Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

# Copyright (C) 2011  Internet Systems Consortium. 

# 

# Permission to use, copy, modify, and distribute this software for any 

# purpose with or without fee is hereby granted, provided that the above 

# copyright notice and this permission notice appear in all copies. 

# 

# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM 

# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL 

# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL 

# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, 

# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING 

# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 

# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 

# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 

 

# Make sure we can load the module, put it into path 

import sys 

import os 

sys.path.extend(os.environ["B10_TEST_PLUGIN_DIR"].split(':')) 

 

import b10logging 

import unittest 

 

class LoggingConfCheckTest(unittest.TestCase): 

    def test_load(self): 

        """ 

        Checks the entry point returns the correct values. 

        """ 

        (spec, check) = b10logging.load() 

        # It returns the checking function 

        self.assertEqual(check, b10logging.check) 

        # The plugin stores it's spec 

        self.assertEqual(spec, b10logging.spec) 

 

    def test_logger_conf(self): 

        self.assertEqual(None, 

                         b10logging.check({'loggers': 

                                          [{'name': '*', 

                                            'severity': 'DEBUG', 

                                            'debuglevel': 50, 

                                            'output_options': 

                                            [{'destination': 'file', 

                                              'output': '/some/file' 

                                            }] 

                                           }, 

                                           {'name': 'b10-resolver', 

                                            'severity': 'WARN', 

                                            'additive': True, 

                                            'output_options': 

                                            [{'destination': 'console', 

                                              'output': 'stderr', 

                                              'flush': True 

                                            }] 

                                           }, 

                                           {'name': 'b10-resolver.resolver', 

                                            'severity': 'ERROR', 

                                            'output_options': [] 

                                           }, 

                                           {'name': '*.cache', 

                                            'severity': 'INFO' 

                                           } 

                                          ]})) 

    def do_bad_name_test(self, name): 

        err_str = "Bad logger name: '" + name + "': * can only be "\ 

                  "used instead of the full first-level name, e.g. "\ 

                  "'*' or '*.subsystem'" 

        self.assertEqual(err_str, 

                         b10logging.check({'loggers': 

                                          [{'name': name, 

                                            'severity': 'DEBUG'}, 

                                          ]})) 

 

    def test_logger_bad_name(self): 

        self.do_bad_name_test("*.") 

        self.do_bad_name_test("*foo") 

        self.do_bad_name_test("*foo.lib") 

        self.do_bad_name_test("foo*") 

        self.do_bad_name_test("foo*.lib") 

 

    def test_logger_bad_severity(self): 

        self.assertEqual('bad severity value for logger *: BADVAL', 

                         b10logging.check({'loggers': 

                                          [{'name': '*', 

                                            'severity': 'BADVAL'}]})) 

 

    def test_logger_bad_destination(self): 

        self.assertEqual('bad destination for logger *: baddest', 

                         b10logging.check({'loggers': 

                                          [{'name': '*', 

                                            'severity': 'INFO', 

                                            'output_options': [ 

                                            { 'destination': 'baddest' } 

                                            ]}]})) 

 

    def test_logger_bad_console_output(self): 

        self.assertEqual('bad output for logger *: bad_output, must be stdout or stderr', 

                         b10logging.check({'loggers': 

                                          [{'name': '*', 

                                            'severity': 'INFO', 

                                            'output_options': [ 

                                            { 'destination': 'console', 

                                              'output': 'bad_output' 

                                            } 

                                            ]}]})) 

 

    def test_logger_bad_file_output(self): 

        self.assertEqual('destination set to file but output not set to any filename for logger *', 

                         b10logging.check({'loggers': 

                                          [{'name': '*', 

                                            'severity': 'INFO', 

                                            'output_options': [ 

                                            { 'destination': 'file' } 

                                            ]}]})) 

 

    def test_logger_bad_syslog_output(self): 

        self.assertEqual('destination set to syslog but output not set to any facility for logger *', 

                         b10logging.check({'loggers': 

                                          [{'name': '*', 

                                            'severity': 'INFO', 

                                            'output_options': [ 

                                            { 'destination': 'syslog' } 

                                            ]}]})) 

 

    def test_logger_bad_type(self): 

        self.assertEqual('123 should be a string', 

                         b10logging.check({'loggers': 

                                          [{'name': 123, 

                                            'severity': 'INFO'}]})) 

        self.assertEqual('123 should be a string', 

                         b10logging.check({'loggers': 

                                          [{'name': 'bind10', 

                                            'severity': 123}]})) 

 

exitif __name__ == '__main__': 

        unittest.main()