def test_check2(self):
     """Test check2:
        -n `first interface`
     """
     try:
         out = StringIO()
         sys.stdout = out
         linux_traffic.main(['-n', self.interfaces[0]])
     except SystemExit, e:
         self.assertEquals(e.code, 0, str(e))
         output = out.getvalue().strip()
         assert output == "Waiting next check to get data..."
 def test_check2(self):
     """Test check2:
        -n `first interface`
     """
     try:
         out = StringIO()
         sys.stdout = out
         linux_traffic.main(['-n', self.interfaces[0]])
     except SystemExit, e:
         self.assertEquals(e.code, 0, str(e))
         output = out.getvalue().strip()
         assert output == "Waiting next check to get data..."
 def test_help(self):
     """Test help output :
        -h
     """
     try:
         out = StringIO()
         sys.stdout = out
         linux_traffic.main(['-h'])
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 3)
         output = out.getvalue().strip()
         assert output.startswith("""check_linux_traffic""")
 def test_bad_arguments1(self):
     """Test bad arguments1:
        -g
     """
     try:
         out = StringIO()
         sys.stdout = out
         linux_traffic.main(['-g'])
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 3)
         output = out.getvalue().strip()
         assert output.startswith("option -g not recognized")
 def test_check3(self):
     """Test check3:
        -f --ignore-lo
     """
     try:
         out = StringIO()
         sys.stdout = out
         linux_traffic.main(['--ignore-lo', '-f'])
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 0)
         output = out.getvalue().strip()
         assert output == "Waiting next check to get data..."
 def test_help(self):
     """Test help output :
        -h
     """
     try:
         out = StringIO()
         sys.stdout = out
         linux_traffic.main(['-h'])
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 3)
         output = out.getvalue().strip()
         assert output.startswith("""check_linux_traffic""")
 def test_check3(self):
     """Test check3:
        -f --ignore-lo
     """
     try:
         out = StringIO()
         sys.stdout = out
         linux_traffic.main(['--ignore-lo', '-f'])
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 0)
         output = out.getvalue().strip()
         assert output == "Waiting next check to get data..."
 def test_bad_arguments3(self):
     """Test bad arguments3:
        -w 80
     """
     try:
         out = StringIO()
         sys.stdout = out
         linux_traffic.main(['-w', 80])
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 3)
         output = out.getvalue().strip()
         assert output.startswith("Critical threshold and warning threshold must be define")
 def test_bad_arguments2(self):
     """Test bad arguments2:
        -w 80 -c 70
     """
     try:
         out = StringIO()
         sys.stdout = out
         linux_traffic.main(['-w', '80', '-c', '70'])
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 3)
         output = out.getvalue().strip()
         assert output.startswith("Critical threshold must be greater than warning threshold")
 def test_bad_arguments1(self):
     """Test bad arguments1:
        -g
     """
     try:
         out = StringIO()
         sys.stdout = out
         linux_traffic.main(['-g'])
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 3)
         output = out.getvalue().strip()
         assert output.startswith("option -g not recognized")
 def test_check4(self):
     """Test check4:
        -f -n `first interface` -l 131072000 
     """
     try:
         out = StringIO()
         sys.stdout = out
         linux_traffic.main(['-f', '-n', self.interfaces[0], '-l', '131072000'])
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 0)
         output = out.getvalue().strip()
         assert output == "Waiting next check to get data..."
 def test_bad_arguments3(self):
     """Test bad arguments3:
        -w 80
     """
     try:
         out = StringIO()
         sys.stdout = out
         linux_traffic.main(['-w', 80])
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 3)
         output = out.getvalue().strip()
         assert output.startswith(
             "Critical threshold and warning threshold must be define")
 def test_bad_arguments2(self):
     """Test bad arguments2:
        -w 80 -c 70
     """
     try:
         out = StringIO()
         sys.stdout = out
         linux_traffic.main(['-w', '80', '-c', '70'])
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 3)
         output = out.getvalue().strip()
         assert output.startswith(
             "Critical threshold must be greater than warning threshold")
 def test_check4(self):
     """Test check4:
        -f -n `first interface` -l 131072000 
     """
     try:
         out = StringIO()
         sys.stdout = out
         linux_traffic.main(
             ['-f', '-n', self.interfaces[0], '-l', '131072000'])
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 0)
         output = out.getvalue().strip()
         assert output == "Waiting next check to get data..."
 def test_version(self):
     """Test version output :
        -V
     """
     try:
         out = StringIO()
         sys.stdout = out
         linux_traffic.main(['--version'])
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 3)
         output = out.getvalue().strip()
         assert output.startswith("check_linux_traffic.py v%s" %
                                  linux_traffic.PLUGIN_VERSION)
 def test_version(self):
     """Test version output :
        -V
     """
     try:
         out = StringIO()
         sys.stdout = out
         linux_traffic.main(['--version'])
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 3)
         output = out.getvalue().strip()
         assert output.startswith("check_linux_traffic.py v%s"
                                  % linux_traffic.PLUGIN_VERSION)
 def test_bad_arguments4(self):
     """Test bad arguments4:
        -w bad_arg
     """
     sys.argv = [sys.argv[0]]
     sys.argv.append('-w')
     sys.argv.append('bad_arg')
     try:
         out = StringIO()
         sys.stdout = out
         linux_traffic.main(['-w', 'bad_arg'])
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 3)
         output = out.getvalue().strip()
         assert output.startswith("Bad argument: ")
 def test_bad_arguments4(self):
     """Test bad arguments4:
        -w bad_arg
     """
     sys.argv = [sys.argv[0]]
     sys.argv.append('-w')
     sys.argv.append('bad_arg')
     try:
         out = StringIO()
         sys.stdout = out
         linux_traffic.main(['-w', 'bad_arg'])
     except SystemExit, e:
         self.assertEquals(type(e), type(SystemExit()))
         self.assertEquals(e.code, 3)
         output = out.getvalue().strip()
         assert output.startswith("Bad argument: ")
           -n `first interface`
        """
        try:
            out = StringIO()
            sys.stdout = out
            linux_traffic.main(['-n', self.interfaces[0]])
        except SystemExit, e:
            self.assertEquals(e.code, 0, str(e))
            output = out.getvalue().strip()
            assert output == "Waiting next check to get data..."

        time.sleep(5)
        try:
            out = StringIO()
            sys.stdout = out
            linux_traffic.main(['-f', '-n', self.interfaces[0]])
        except SystemExit, e:
            self.assertEquals(type(e), type(SystemExit()))
            self.assertEquals(e.code, 0)
            output = out.getvalue().strip()
            assert output.find(self.interfaces[0]) != -1
            if len(self.interfaces) >= 2:
                assert output.find(self.interfaces[1]) == -1

    def test_check3(self):
        """Test check3:
           -f --ignore-lo
        """
        try:
            out = StringIO()
            sys.stdout = out
           -n `first interface`
        """
        try:
            out = StringIO()
            sys.stdout = out
            linux_traffic.main(['-n', self.interfaces[0]])
        except SystemExit, e:
            self.assertEquals(e.code, 0, str(e))
            output = out.getvalue().strip()
            assert output == "Waiting next check to get data..."

        time.sleep(5)
        try:
            out = StringIO()
            sys.stdout = out
            linux_traffic.main(['-f', '-n', self.interfaces[0]])
        except SystemExit, e:
            self.assertEquals(type(e), type(SystemExit()))
            self.assertEquals(e.code, 0)
            output = out.getvalue().strip()
            assert output.find(self.interfaces[0]) != -1
            if len(self.interfaces) >= 2:
                assert output.find(self.interfaces[1]) == -1

    def test_check3(self):
        """Test check3:
           -f --ignore-lo
        """
        try:
            out = StringIO()
            sys.stdout = out