Skip to content

Commit

Permalink
Added new force param
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan Ratcliffe committed Mar 6, 2018
1 parent e11d5c2 commit 21076c4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 17 deletions.
45 changes: 30 additions & 15 deletions features/run.feature
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@run
Feature: Run rspec and acceptance test suits
Onceover should allow to run rspec and acceptance test for all profvile and role classes
or for any part of them. Use should set if he wants to see only summary of tests or full
Expand All @@ -6,23 +7,37 @@ Feature: Run rspec and acceptance test suits
Background:
Given onceover executable

Scenario: Run correct spec tests
Given initialized control repo "basic"
When I run onceover command "run spec"
Then I should not see any errors
# Scenario: Run correct spec tests
# Given initialized control repo "basic"
# When I run onceover command "run spec"
# Then I should not see any errors
#
# Scenario: Run spec tests with misspelled module in Puppetfile
# Given initialized control repo "basic"
# And in Puppetfile is misspelled module's name
# When I run onceover command "run spec"
# Then I should see error with message pattern "The module acme-not_exists does not exist"
#
# Scenario: Run advanced spec tests
# Given control repo "puppet_controlrepo"
# When I run onceover command "run spec"
# Then I should not see any errors
#
# Scenario: Check that control_branch functionality works
# Given initialized control repo "control_branch"
# When I run onceover command "run spec"
# Then the temporary Puppetfile should contain the git branch

Scenario: Run spec tests with misspelled module in Puppetfile
Scenario: Run with local modifications
Given initialized control repo "basic"
And in Puppetfile is misspelled module's name
When I run onceover command "run spec"
Then I should see error with message pattern "The module acme-not_exists does not exist"
And I make local modifications
And I run onceover command "run spec"
Then I should see message pattern "local modifications"

Scenario: Run advanced spec tests
Given control repo "puppet_controlrepo"
When I run onceover command "run spec"
Then I should not see any errors

Scenario: Check that control_branch functionality works
Given initialized control repo "control_branch"
Scenario: Force overwrite local modifications
Given initialized control repo "basic"
When I run onceover command "run spec"
Then the temporary Puppetfile should contain the git branch
And I make local modifications
And I run onceover command "run spec --force"
Then I should see message pattern "Overwriting local modifications"
2 changes: 1 addition & 1 deletion features/step_definitions/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

Then(/^I should see message pattern "([^"]*)"$/) do |err_msg_regexp|
expect(@cmd.success?).to be true
puts @cmd.output unless @cmd.success?
puts @cmd.output unless @cmd.output =~ Regexp.new(err_msg_regexp)
expect(@cmd.output).to match(err_msg_regexp)
puts @cmd.output.match(err_msg_regexp).to_s
end
4 changes: 4 additions & 0 deletions features/step_definitions/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
git_branch = `git rev-parse --abbrev-ref HEAD`.chomp
step %Q(the temporary Puppetfile should contain /#{git_branch}/)
end

When(/^I make local modifications$/) do
FileUtils.rm_rf("#{@repo.onceover_temp_root_folder}/modules/apache/manifests")
end
1 change: 1 addition & 0 deletions lib/onceover/cli/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def self.command
optional :c, :classes, 'A list of classes. Only tests with these classes will be run'
optional :n, :nodes, 'A list of nodes. Only tests with these nodes will be run'
optional :s, :skip_r10k, 'Skip the r10k step'
optional :f, :force, 'Passes --force to r10k, overwriting modules'
optional :sv, :strict_variables, 'Run with strict_variables set to yes'

run do |opts, args, cmd|
Expand Down
7 changes: 6 additions & 1 deletion lib/onceover/testconfig.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class TestConfig
attr_accessor :before_conditions
attr_accessor :after_conditions
attr_accessor :skip_r10k
attr_accessor :force
attr_accessor :strict_variables

def initialize(file, opts = {})
Expand Down Expand Up @@ -68,6 +69,7 @@ def initialize(file, opts = {})
@filter_classes = opts[:classes] ? [opts[:classes].split(',')].flatten.map {|x| Onceover::Class.find(x)} : nil
@filter_nodes = opts[:nodes] ? [opts[:nodes].split(',')].flatten.map {|x| Onceover::Node.find(x)} : nil
@skip_r10k = opts[:skip_r10k] ? true : false
@force = opts[:force] || false

# Loop over all of the items in the test matrix and add those as test
# objects to the list of tests
Expand Down Expand Up @@ -265,7 +267,10 @@ def deploy_local(repo = Onceover::Controlrepo.new, opts = {})
# R10K::Action::Deploy::Environment
prod_dir = "#{repo.tempdir}/#{repo.environmentpath}/production"
Dir.chdir(prod_dir) do
install_cmd = "r10k puppetfile install --verbose --color --puppetfile #{repo.puppetfile}"
install_cmd = []
install_cmd << "r10k puppetfile install --verbose --color --puppetfile #{repo.puppetfile}"
install_cmd << "--force" if @force
install_cmd = install_cmd.join(' ')
logger.debug "Running #{install_cmd} from #{prod_dir}"
system(install_cmd)
raise 'r10k could not install all required modules' unless $?.success?
Expand Down

0 comments on commit 21076c4

Please sign in to comment.