Allow test
command to use conf files
It should be possible to run the `test` command with a custom config. This allows examination of the XML outputted where config settings can change the outputted XML. Otherwise any non-default config values will only be used when running the `update` comand. Add a simple test to confirm that the custom url that is unlikely to ever be a valid default value is returned when the command is set to `test` and a custom config is specified. Change-Id: I193e83314a35943406bff5b182f20693edd640ba
This commit is contained in:
parent
1df929c58a
commit
1eb343616f
@ -118,12 +118,12 @@ def setup_config_settings(options):
|
||||
config = ConfigParser.ConfigParser()
|
||||
## Load default config always
|
||||
config.readfp(cStringIO.StringIO(DEFAULT_CONF))
|
||||
if options.command == 'test':
|
||||
logger.debug("Not reading config for test output generation")
|
||||
elif os.path.isfile(conf):
|
||||
if os.path.isfile(conf):
|
||||
logger.debug("Reading config from {0}".format(conf))
|
||||
conffp = open(conf, 'r')
|
||||
config.readfp(conffp)
|
||||
elif options.command == 'test':
|
||||
logger.debug("Not requiring config for test output generation")
|
||||
else:
|
||||
raise JenkinsJobsException(
|
||||
"A valid configuration file is required when not run as a test"
|
||||
|
2
tests/cmd/fixtures/cmd-001.conf
Normal file
2
tests/cmd/fixtures/cmd-001.conf
Normal file
@ -0,0 +1,2 @@
|
||||
[jenkins]
|
||||
url=http://test-jenkins.with.non.default.url:8080/
|
@ -83,3 +83,18 @@ class CmdTests(testtools.TestCase):
|
||||
'r',
|
||||
'utf-8').read()
|
||||
self.assertEqual(console_out.getvalue(), xml_content)
|
||||
|
||||
def test_config_with_test(self):
|
||||
"""
|
||||
Run test mode and pass a config file
|
||||
"""
|
||||
args = self.parser.parse_args(['--conf',
|
||||
os.path.join(self.fixtures_path,
|
||||
'cmd-001.conf'),
|
||||
'test',
|
||||
os.path.join(self.fixtures_path,
|
||||
'cmd-001.yaml'),
|
||||
'foo-job'])
|
||||
config = cmd.setup_config_settings(args)
|
||||
self.assertEqual(config.get('jenkins', 'url'),
|
||||
"http://test-jenkins.with.non.default.url:8080/")
|
||||
|
Loading…
Reference in New Issue
Block a user