Skip to content

Commit

Permalink
Cleaned up some unused test code
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsNielsen committed Jun 21, 2019
1 parent 87f9284 commit a0b5726
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 81 deletions.
62 changes: 29 additions & 33 deletions lib/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Core extend self
def cli_text(file)
cli = <<DOCOPT
Usage:
#{file} from <oldest-ref> [--to=<newest-ref>] [options] [-v...] [-q...] [-c (<user> <password> <target>)]...
#{file} from <oldest-ref> [--to=<newest-ref>] [options] [-v...] [-q...] [-c (<user> <password> <target>)]...
#{file} from-latest-tag <approximation> [--to=<newest-ref>] [options] [-v...] [-q...] [-c <user> <password> <target>]...
#{file} -h|--help
Expand All @@ -19,47 +19,47 @@ def cli_text(file)
--from <oldest-ref> Specify where to stop searching for commit. For git this takes anything that rev-parse accepts. Such as HEAD~3 / Git sha or tag name.
--from-latest-tag Looks for the newest commit that the tag with <approximation> points to.
--settings=<path> Path to the settings file used. If nothing is specified default_settings.yml is used
--from-latest-tag Looks for the newest commit that the tag with <approximation> points to.
--properties=<properties>
--settings=<path> Path to the settings file used. If nothing is specified default_settings.yml is used
Allows you to pass in additional variables to the Liquid templates. Must be in JSON format. Namespaced under properties.* in
--properties=<properties>
Allows you to pass in additional variables to the Liquid templates. Must be in JSON format. Namespaced under properties.* in
your Liquid templates. Referenced like so '{{properties.[your-variable]}}' in your templates.
JSON keys and values should be wrapped in quotation marks '"' like so: --properties='{ "title":"PAC Changelog" }'
JSON keys and values should be wrapped in quotation marks '"' like so: --properties='{ "title":"PAC Changelog" }'
-v More verbose output. Can be repeated to increase output verbosity or to cancel out -q
-q Less verbose output. Can be repeated for more silence or to cancel out -v
-c Override username and password. Example: `-c my_user my_password jira`. This will set username and password for task system jira.
DOCOPT
cli
cli
end

def settings
if defined?(@@settings).nil?
{}
else
@@settings
end
end
end

def settings=(val)
@@settings = val
end

#Reads the command line options. And based on this it will return the
#Reads the command line options. And based on this it will return the
#path of the settings file to use.
def read_settings_file(input)
settings_file = File.join(Dir.pwd, 'settings/default_settings.yml')
unless input['--settings'].nil?
settings_file = input['--settings']
end

unless File.exists?(settings_file)
unless File.exists?(settings_file)
raise "Settings file '#{settings_file}' does not exist"
end

Expand All @@ -79,10 +79,6 @@ def generate_settings(cmdline, configuration)
loaded[:properties] = {}
end

unless cmdline['--pattern'].nil?
loaded[:vcs][:release_regex] = input['--pattern']
end

#User name override
if cmdline['-c']
(0..cmdline['-c']-1).each do |it|
Expand All @@ -97,31 +93,31 @@ def generate_settings(cmdline, configuration)
end
end
end
unless cmdline['--properties'].nil?

unless cmdline['--properties'].nil?
json_value = JSON.parse(cmdline['--properties'])
loaded[:properties] = loaded[:properties].merge(json_value)
end
loaded[:verbosity] = Logging.calc_verbosity(cmdline)
loaded
loaded
end

#Requires a configuration section for the task system to be applied
def apply_task_system(task_system, tasks)
val = true
Logging.verboseprint(1, "[PAC] Applying task system #{task_system[:name]}")
if task_system[:name] == 'trac'
if task_system[:name] == 'trac'
val = Task::TracTaskSystem.new(task_system).apply(tasks)
end
if task_system[:name] == 'jira'
val = Task::JiraTaskSystem.new(task_system).apply(tasks)
end
end
if task_system[:name] == 'fogbugz'
val = Task::FogBugzTaskSystem.new(task_system).apply(tasks)
end
val
end

def vcs
if @@settings[:vcs][:type] == 'git'
Vcs::GitVcs.new(settings[:vcs])
Expand All @@ -133,7 +129,7 @@ def vcs
end

#This is now core functionality. The task of generating a collection of tasks based on the commits found
#This takes in a PACCommitCollection and returns a PACTaskCollection
#This takes in a PACCommitCollection and returns a PACTaskCollection
def task_id_list(commits)
regex_arr = []

Expand All @@ -145,31 +141,31 @@ def task_id_list(commits)
#Regex ~ Eacb regex in the task system
settings[:task_systems].each do |ts|
#Loop over each task system. Parse commits for matches
if ts.has_key? :delimiter
split_pattern = eval(ts[:delimiter])
if ts.has_key? :delimiter
split_pattern = eval(ts[:delimiter])
end

if ts.has_key? :regex
if ts.has_key? :regex
tasks_for_commit = c_pac.matchtask(ts[:regex], split_pattern)
tasks_for_commit.each do |t|
tasks_for_commit.each do |t|
t.applies_to = ts[:name]
end
end
#If a task was found
unless tasks_for_commit.empty?
referenced = true
tasks.add(tasks_for_commit)
end
referenced = true
tasks.add(tasks_for_commit)
end
end
end

if !referenced
task = Model::PACTask.new
task.add_commit(c_pac)
tasks.add(task)
end
end

end

tasks
tasks
end
end
12 changes: 1 addition & 11 deletions settings/default_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,8 @@
:usr: "user"
:pw: "password"
:regex:
- { pattern: '/(PRJ-\d+)/i', label: jira }
-
:name: trac
:trac_url: "https://my.trac.site"
:trac_usr: "user"
:trac_pwd: "pass"
:regex:
- { pattern: '/Ticket-(\d+)/i', label: trac }
- { pattern: '/(PRJ-\d+)/i', label: jira }

:vcs:
:type: git
:usr:
:pwd:
:repo_location: '.'
:release_regex: 'tags'
2 changes: 0 additions & 2 deletions spec/pactask_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
end
end



describe "applies_to" do
let(:pt) { Model::PACTask.new() }

Expand Down
3 changes: 1 addition & 2 deletions test/resources/GetCommitMessagesTestRepository_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@
:type: git
:usr:
:pwd:
:repo_location: 'test/resources/GetCommitMessagesTestRepository'
:release_regex: 'tags'
:repo_location: 'test/resources/GetCommitMessagesTestRepository'
5 changes: 1 addition & 4 deletions test/resources/IncludesSinceTestRepository_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,4 @@

:vcs:
:type: git
:usr:
:pwd:
:repo_location: 'test/resources/IncludesSinceTestRepository'
:release_regex: 'tags'
:repo_location: 'test/resources/IncludesSinceTestRepository'
5 changes: 1 addition & 4 deletions test/resources/idReportTestRepository_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,4 @@

:vcs:
:type: git
:usr:
:pwd:
:repo_location: 'test/resources/idReportTestRepository'
:release_regex: 'tags'
:repo_location: 'test/resources/idReportTestRepository'
5 changes: 1 addition & 4 deletions test/resources/pac-test-repo_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,4 @@

:vcs:
:type: git
:usr:
:pwd:
:repo_location: 'test/resources/pac-test-repo'
:release_regex: 'tags'
:repo_location: 'test/resources/pac-test-repo'
3 changes: 0 additions & 3 deletions test/resources/repo_with_tags_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,4 @@

:vcs:
:type: git
:usr:
:pwd:
:repo_location: 'test/resources/repo_with_tags'
:release_regex: 'tags'
33 changes: 15 additions & 18 deletions test/unit/configurationtest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def test_configuration_parsing
settings_file = File.join(File.dirname(__FILE__), '../../settings/default_settings.yml')
loaded = YAML::load(File.open(settings_file))
assert_true(loaded.has_key?(:general))
assert_equal(3, loaded[:task_systems].length)
assert_equal(3, loaded[:templates].length)
assert_equal(2, loaded[:task_systems].length)
assert_equal(3, loaded[:templates].length)
end

#The everything ok scenario
Expand All @@ -21,7 +21,7 @@ def test_properties_parsing_ok
arguments = { '--settings' => "#{settings_file}", '--properties' => '{"title" : "PAC Changelog Name Override" }' }
file_parsed = Core.read_settings_file(arguments)
settings_parsed = Core.generate_settings(arguments, file_parsed)
assert_equal('PAC Changelog Name Override', settings_parsed[:properties]['title'])
assert_equal('PAC Changelog Name Override', settings_parsed[:properties]['title'])
defined = Report::Generator.new.to_liquid_properties(settings_parsed)
assert_equal('PAC Changelog Name Override', defined['properties']['title'] )
assert_equal('PAC Changelog Name Override', settings_parsed[:properties]['title'])
Expand All @@ -31,39 +31,36 @@ def test_properties_parsing_ok
def test_properties_incorrect_json
settings_file = File.join(File.dirname(__FILE__), '../../settings/default_settings.yml')
arguments = { '--settings' => "#{settings_file}", '--properties' => "{ title'PAC Chang} " }
file_parsed = Core.read_settings_file(arguments)
file_parsed = Core.read_settings_file(arguments)
assert_raise do |err|
settings_parsed = Core.generate_settings(arguments, file_parsed)
end
end

#Credentials test (test the -c option. for username and password overrides)
def test_configure_credentials
settings_file = File.join(File.dirname(__FILE__), '../../settings/default_settings.yml')
#Notice the wierd way docopt handles it. The -c flag is a repeat flag, each option is then grouped positionally. So for each 'c' specified
#Notice the wierd way docopt handles it. The -c flag is a repeat flag, each option is then grouped positionally. So for each 'c' specified
#c is incremented, and the index of the then the value specified.
arguments = { '--settings' => "#{settings_file}", '--properties' => '{"title" : "PAC Changelog Name Override" }', '-c' => 2,
'<user>' => ["newuser", "tracuser"],
'<password>' => ["newpassword", "tracpassword"],
'<target>' => ["jira", "trac"] }
arguments = { '--settings' => "#{settings_file}", '--properties' => '{"title" : "PAC Changelog Name Override" }', '-c' => 2,
'<user>' => ["newuser", "tracuser"],
'<password>' => ["newpassword", "tracpassword"],
'<target>' => ["jira", "trac"] }

file_parsed = Core.read_settings_file(arguments)
settings_parsed = Core.generate_settings(arguments, file_parsed)
settings_parsed = Core.generate_settings(arguments, file_parsed)
assert_equal('newuser', settings_parsed[:task_systems][1][:usr])
assert_equal('newpassword', settings_parsed[:task_systems][1][:pw])

assert_equal('tracuser', settings_parsed[:task_systems][2][:usr])
assert_equal('tracpassword', settings_parsed[:task_systems][2][:pw])
end

def test_raise_exception_on_missing_settings_file
def test_raise_exception_on_missing_settings_file
config = { '--settings' => 'not-there.yml' }
assert_raise RuntimeError do
assert_raise RuntimeError do
Core.read_settings_file(config)
end
#Assert the inverse as well
config['--settings'] = 'pac_settings.yml'
Core.read_settings_file(config)
end
end

end
end

0 comments on commit a0b5726

Please sign in to comment.