mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-08 02:18:53 +00:00
41ab6f3161
Move /osquery/python_tests/* to /tools/tests Move test_extensions process controls to test_base module Use test_base.Testing to implement each module's main() - This applies a default argparse with --build - test_base.ARGS is the argparse-parsed namespace - Use test_base.ARGS.build for the platform-specific dir Move WatchdogTests to /tools/tests/test_watchdog.py
47 lines
1.5 KiB
Python
Executable File
47 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
# Copyright (c) 2014, Facebook, Inc.
|
|
# All rights reserved.
|
|
#
|
|
# This source code is licensed under the BSD-style license found in the
|
|
# LICENSE file in the root directory of this source tree. An additional grant
|
|
# of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
from __future__ import absolute_import
|
|
from __future__ import division
|
|
from __future__ import print_function
|
|
# pyexpect.replwrap will not work with unicode_literals
|
|
#from __future__ import unicode_literals
|
|
|
|
import os
|
|
import unittest
|
|
|
|
# osquery-specific testing utils
|
|
import test_base
|
|
|
|
class OsqueryiTest(unittest.TestCase):
|
|
def setUp(self):
|
|
binary = os.path.join(test_base.ARGS.build, "osquery", "osqueryi")
|
|
self.osqueryi = test_base.OsqueryWrapper(binary)
|
|
|
|
def test_error(self):
|
|
'''Test that we throw an error on bad query'''
|
|
self.osqueryi.run_command(' ')
|
|
self.assertRaises(test_base.OsqueryException,
|
|
self.osqueryi.run_query, 'foo')
|
|
|
|
def test_time(self):
|
|
'''Demonstrating basic usage of OsqueryWrapper with the time table'''
|
|
self.osqueryi.run_command(' ') # flush error output
|
|
result = self.osqueryi.run_query(
|
|
'SELECT hour, minutes, seconds FROM time;')
|
|
self.assertEqual(len(result), 1)
|
|
row = result[0]
|
|
self.assertTrue(0 <= int(row['hour']) <= 24)
|
|
self.assertTrue(0 <= int(row['minutes']) <= 60)
|
|
self.assertTrue(0 <= int(row['seconds']) <= 60)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
test_base.Tester().run()
|