-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6adf0e7
commit 132eb46
Showing
5 changed files
with
225 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# coding=utf-8 | ||
# ----------------------------------------------------------------------------- | ||
# The CodeChecker Infrastructure | ||
# This file is distributed under the University of Illinois Open Source | ||
# License. See LICENSE.TXT for details. | ||
# ----------------------------------------------------------------------------- | ||
|
||
""" Setup for the config test for the web commands. """ | ||
|
||
|
||
import os | ||
import shutil | ||
|
||
from libtest import env | ||
|
||
|
||
# Test workspace should be initialized in this module. | ||
TEST_WORKSPACE = None | ||
|
||
|
||
def setup_package(): | ||
"""Setup the environment for the tests.""" | ||
|
||
global TEST_WORKSPACE | ||
TEST_WORKSPACE = env.get_workspace('config') | ||
|
||
# Set the TEST_WORKSPACE used by the tests. | ||
os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE | ||
|
||
# Create a basic CodeChecker config for the tests, this should | ||
# be imported by the tests and they should only depend on these | ||
# configuration options. | ||
codechecker_cfg = { | ||
'workspace': TEST_WORKSPACE, | ||
'check_env': env.test_env(TEST_WORKSPACE), | ||
'viewer_host': 'localhost', | ||
'viewer_product': 'db_cleanup' | ||
} | ||
|
||
env.export_test_cfg(TEST_WORKSPACE, {'codechecker_cfg': codechecker_cfg}) | ||
|
||
|
||
def teardown_package(): | ||
""" Delete the workspace associated with this test. """ | ||
|
||
# TODO: If environment variable is set keep the workspace | ||
# and print out the path. | ||
global TEST_WORKSPACE | ||
|
||
print("Removing: " + TEST_WORKSPACE) | ||
shutil.rmtree(TEST_WORKSPACE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# | ||
# ----------------------------------------------------------------------------- | ||
# The CodeChecker Infrastructure | ||
# This file is distributed under the University of Illinois Open Source | ||
# License. See LICENSE.TXT for details. | ||
# ----------------------------------------------------------------------------- | ||
|
||
""" | ||
Test server configuration file. | ||
""" | ||
|
||
|
||
import json | ||
import multiprocessing | ||
import os | ||
import unittest | ||
|
||
from libtest import codechecker | ||
from libtest import env | ||
|
||
|
||
class TestServerConfig(unittest.TestCase): | ||
_ccClient = None | ||
|
||
def setUp(self): | ||
|
||
# TEST_WORKSPACE is automatically set by test package __init__.py . | ||
self.test_workspace = os.environ['TEST_WORKSPACE'] | ||
self.codechecker_cfg = env.import_codechecker_cfg(self.test_workspace) | ||
|
||
test_class = self.__class__.__name__ | ||
print('Running ' + test_class + ' tests in ' + self.test_workspace) | ||
|
||
# Get the CodeChecker cmd if needed for the tests. | ||
self._codechecker_cmd = env.codechecker_cmd() | ||
|
||
self.config_file = os.path.join(self.test_workspace, | ||
"codechecker.json") | ||
|
||
def test_valid_config(self): | ||
""" Start server with a valid configuration file. """ | ||
with open(self.config_file, 'w+', | ||
encoding="utf-8", errors="ignore") as config_f: | ||
json.dump({ | ||
'server': ['--skip-db-cleanup']}, config_f) | ||
|
||
event = multiprocessing.Event() | ||
event.clear() | ||
|
||
self.codechecker_cfg['viewer_port'] = env.get_free_port() | ||
|
||
server_access = \ | ||
codechecker.start_server(self.codechecker_cfg, event, | ||
['--config', self.config_file]) | ||
event.set() | ||
event.clear() | ||
with open(server_access['server_output_file'], 'r', | ||
encoding='utf-8', errors='ignore') as out: | ||
content = out.read() | ||
self.assertFalse('usage: CodeChecker' in content) | ||
|
||
def test_invalid_config(self): | ||
""" Start server with an invalid configuration file. """ | ||
with open(self.config_file, 'w+', | ||
encoding="utf-8", errors="ignore") as config_f: | ||
json.dump({ | ||
'server': ['--dummy-option']}, config_f) | ||
|
||
event = multiprocessing.Event() | ||
event.clear() | ||
|
||
self.codechecker_cfg['viewer_port'] = env.get_free_port() | ||
|
||
server_access = \ | ||
codechecker.start_server(self.codechecker_cfg, event, | ||
['--config', self.config_file]) | ||
event.set() | ||
event.clear() | ||
with open(server_access['server_output_file'], 'r', | ||
encoding='utf-8', errors='ignore') as out: | ||
content = out.read() | ||
self.assertTrue('usage: CodeChecker' in content) | ||
|
||
def test_empty_config(self): | ||
""" Start server with an empty configuration file. """ | ||
with open(self.config_file, 'w+', | ||
encoding="utf-8", errors="ignore") as config_f: | ||
config_f.write("") | ||
|
||
event = multiprocessing.Event() | ||
event.clear() | ||
|
||
self.codechecker_cfg['viewer_port'] = env.get_free_port() | ||
|
||
server_access = \ | ||
codechecker.start_server(self.codechecker_cfg, event, | ||
['--config', self.config_file]) | ||
event.set() | ||
event.clear() | ||
with open(server_access['server_output_file'], 'r', | ||
encoding='utf-8', errors='ignore') as out: | ||
content = out.read() | ||
self.assertFalse('usage: CodeChecker' in content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters