From ca4d19045cd59401220f6846bcdea3b791551efe Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Sun, 20 Dec 2020 13:30:43 +0100 Subject: [PATCH 01/29] Remove monkey-patch related to UTF-8 issues on Git::Diff class According to https://github.com/ruby-git/ruby-git/pull/405, it seems to close the issue reported at https://github.com/ruby-git/ruby-git/issues/326. This have been merged then released in 1.7.0. It finally removes the deprecation warning: lib/monkey_patches.rb:13: warning: Using the last argument as keyword parameters is deprecated --- lib/monkey_patches.rb | 39 --------------------------------------- modulesync.gemspec | 2 +- 2 files changed, 1 insertion(+), 40 deletions(-) diff --git a/lib/monkey_patches.rb b/lib/monkey_patches.rb index f4818232..46878dd5 100644 --- a/lib/monkey_patches.rb +++ b/lib/monkey_patches.rb @@ -1,43 +1,4 @@ module Git - class Diff - # Monkey patch process_full_diff until https://github.com/schacon/ruby-git/issues/326 is resolved - def process_full_diff - defaults = { - :mode => '', - :src => '', - :dst => '', - :type => 'modified' - } - final = {} - current_file = nil - full_diff_utf8_encoded = @full_diff.encode("UTF-8", "binary", { - :invalid => :replace, - :undef => :replace - }) - full_diff_utf8_encoded.split("\n").each do |line| - if m = /^diff --git a\/(.*?) b\/(.*?)/.match(line) - current_file = m[1] - final[current_file] = defaults.merge({:patch => line, :path => current_file}) - elsif !current_file.nil? - if m = /^index (.......)\.\.(.......)( ......)*/.match(line) - final[current_file][:src] = m[1] - final[current_file][:dst] = m[2] - final[current_file][:mode] = m[3].strip if m[3] - end - if m = /^([[:alpha:]]*?) file mode (......)/.match(line) - final[current_file][:type] = m[1] - final[current_file][:mode] = m[2] - end - if m = /^Binary files /.match(line) - final[current_file][:binary] = true - end - final[current_file][:patch] << "\n" + line - end - end - final.map { |e| [e[0], DiffFile.new(@base, e[1])] } - end - end - module LibMonkeyPatch # Monkey patch set_custom_git_env_variables due to our ::Git::GitExecuteError handling. # diff --git a/modulesync.gemspec b/modulesync.gemspec index c06ee84e..338a36eb 100644 --- a/modulesync.gemspec +++ b/modulesync.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rspec' spec.add_development_dependency 'rubocop', '~> 0.50.0' - spec.add_runtime_dependency 'git', '~>1.3' + spec.add_runtime_dependency 'git', '~>1.7' spec.add_runtime_dependency 'gitlab', '~>4.0' spec.add_runtime_dependency 'octokit', '~>4.0' spec.add_runtime_dependency 'puppet-blacksmith', '>= 3.0', '< 7' From 731b3fd3c317497811e9474dac7ccfb2b8647bb9 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Sun, 20 Dec 2020 13:52:08 +0100 Subject: [PATCH 02/29] Remove monkey-patch related to ls-files This is now fixed upstream since 2018: https://github.com/ruby-git/ruby-git/pull/350 --- lib/monkey_patches.rb | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/lib/monkey_patches.rb b/lib/monkey_patches.rb index 46878dd5..ca4fb440 100644 --- a/lib/monkey_patches.rb +++ b/lib/monkey_patches.rb @@ -12,18 +12,5 @@ def set_custom_git_env_variables class Lib prepend LibMonkeyPatch - - # Monkey patch ls_files until https://github.com/ruby-git/ruby-git/pull/320 is resolved - def ls_files(location=nil) - location ||= '.' - hsh = {} - command_lines('ls-files', ['--stage', location]).each do |line| - (info, file) = line.split("\t") - (mode, sha, stage) = info.split - file = eval(file) if file =~ /^\".*\"$/ # This takes care of quoted strings returned from git - hsh[file] = {:path => file, :mode_index => mode, :sha_index => sha, :stage => stage} - end - hsh - end end end From 47e1ae4f9559aa0e0f53bff6dbb4b9c2552195b2 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Sun, 20 Dec 2020 00:33:41 +0100 Subject: [PATCH 03/29] Tests: Implement a Puppet module remote repository faker This commit provides a new helper class Faker::PuppetModuleRemoteRepo to ease the write of tests when tested operations should (or not) operate on the git repository of a puppet module. This class provides following features: - Fake a remote repository by creating a bare initialization usable using a local remote url (ie. file://) - Create basic operations behind the scene using a temporary repo (e.g. write, add and push a file; read a file from a specified branch) - Populate the fake remote repo using a basic metadata.json - Simulate a read-only repo - Change the default branch - Count commits between two commit refs - Count commits made by an author on all the repo, or a specified branch Note: All operations are made using "Faker " as author and committer. This commit comes with a tiny Faker module to hold the config (ie. the working directory) --- spec/helpers/faker.rb | 12 ++ .../faker/puppet_module_remote_repo.rb | 130 ++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 spec/helpers/faker.rb create mode 100644 spec/helpers/faker/puppet_module_remote_repo.rb diff --git a/spec/helpers/faker.rb b/spec/helpers/faker.rb new file mode 100644 index 00000000..4f628c57 --- /dev/null +++ b/spec/helpers/faker.rb @@ -0,0 +1,12 @@ +# Faker is a top-level module to keep global faker config +module Faker + def self.working_directory=(path) + @working_directory = path + end + + def self.working_directory + raise 'Working directory must be set' if @working_directory.nil? + FileUtils.mkdir_p @working_directory + @working_directory + end +end diff --git a/spec/helpers/faker/puppet_module_remote_repo.rb b/spec/helpers/faker/puppet_module_remote_repo.rb new file mode 100644 index 00000000..7cb8e092 --- /dev/null +++ b/spec/helpers/faker/puppet_module_remote_repo.rb @@ -0,0 +1,130 @@ +require 'open3' + +require_relative '../faker' + +# Fake a remote git repository that hold a puppet module +# +# This module allow to fake a remote repositiory using: +# - a bare repo +# - a temporary cloned repo to operate on the remote before exposition to modulesync +# +# Note: This module need to have working_directory sets before using it +module Faker + class PuppetModuleRemoteRepo + attr_reader :name + attr_reader :namespace + + def initialize(name, namespace) + @name = name + @namespace = namespace + end + + def populate + FileUtils.chdir(Faker.working_directory) do + run "git init --bare '#{bare_repo_dir}'" + run "git clone '#{bare_repo_dir}' '#{tmp_repo_dir}'" + + module_short_name = name.sub(/^puppet-/, '') + + FileUtils.chdir(tmp_repo_dir) do + metadata = { + name: "modulesync-#{module_short_name}", + version: '0.4.2', + author: 'ModuleSync team', + }.to_json + + File.write 'metadata.json', metadata + run 'git add metadata.json' + run "git commit -m'Initial commit'" + run 'git push' + end + end + end + + def read_only=(value) + mode = value ? '0444' : '0644' + FileUtils.chdir(bare_repo_dir) do + run "git config core.sharedRepository #{mode}" + end + end + + def default_branch=(value) + FileUtils.chdir(bare_repo_dir) do + run "git branch -M master #{value}" + run "git symbolic-ref HEAD refs/heads/#{value}" + end + end + + def read_file(filename, branch = nil) + FileUtils.chdir(tmp_repo_dir) do + run "git fetch" + run "git checkout #{branch}" unless branch.nil? + run "git merge --ff-only" + return unless File.exists?(filename) + + return File.read filename + end + end + + def add_file(filename, content, branch = nil) + FileUtils.chdir(tmp_repo_dir) do + run "git checkout #{branch}" unless branch.nil? + File.write filename, content + run "git add #{filename}" + run "git commit -m'Add file: \"#{filename}\"'" + run 'git push' + end + end + + def commit_count_between(commit1, commit2) + FileUtils.chdir(bare_repo_dir) do + stdout = run "git rev-list --count #{commit1}..#{commit2}" + return Integer(stdout) + end + end + + def commit_count_by(author, commit = nil) + FileUtils.chdir(bare_repo_dir) do + commit ||= '--all' + stdout = run "git rev-list #{commit} --author='#{author}' --count" + return Integer(stdout) + end + end + + def remote_url + "file://#{bare_repo_dir}" + end + + def self.git_base + "file://#{Faker.working_directory}/bare/" + end + + private + def tmp_repo_dir + "#{Faker.working_directory}/tmp/#{namespace}/#{name}" + end + + def bare_repo_dir + "#{Faker.working_directory}/bare/#{namespace}/#{name}.git" + end + + GIT_ENV = { + 'GIT_AUTHOR_NAME' => 'Faker', + 'GIT_AUTHOR_EMAIL' => 'faker@example.com', + 'GIT_COMMITTER_NAME' => 'Faker', + 'GIT_COMMITTER_EMAIL' => 'faker@example.com', + } + + def run(command) + stdout, stderr, status = Open3.capture3(GIT_ENV, command) + return stdout if status.success? + + $stderr.puts "Command '#{command}' failed: #{status}" + $stderr.puts ' STDOUT:' + $stderr.puts stdout + $stderr.puts ' STDERR:' + $stderr.puts stderr + raise + end + end +end From b428d1ffdd6ffc3a09ce4f78f3e3e5c0d972e05c Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Sun, 20 Dec 2020 00:34:39 +0100 Subject: [PATCH 04/29] Cucumber: Setup the use of the Faker module --- features/support/env.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/features/support/env.rb b/features/support/env.rb index f3f544d6..f391dde2 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,5 +1,9 @@ require 'aruba/cucumber' +require_relative '../../spec/helpers/faker' + +Faker.working_directory = File.expand_path("#{Aruba.config.working_directory}/faker") + Before do @aruba_timeout_seconds = 5 end From 7edefbb44aaaf5e18294823857dcabec16a78355 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Sun, 20 Dec 2020 00:36:57 +0100 Subject: [PATCH 05/29] Tests: Provide new steps to use PuppetModuleRemoteRepo faker --- .rubocop.yml | 2 ++ features/step_definitions/git_steps.rb | 50 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 84fb5455..8c30206a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -25,6 +25,8 @@ Layout/IndentHeredoc: # sane line length Metrics/LineLength: Max: 120 + Exclude: + - 'features/**/*' Style/FrozenStringLiteralComment: Enabled: false diff --git a/features/step_definitions/git_steps.rb b/features/step_definitions/git_steps.rb index 36c1e903..61d02476 100644 --- a/features/step_definitions/git_steps.rb +++ b/features/step_definitions/git_steps.rb @@ -1,3 +1,5 @@ +require_relative '../../spec/helpers/faker/puppet_module_remote_repo' + Given 'a mocked git configuration' do steps %( Given a mocked home directory @@ -6,6 +8,54 @@ ) end +Given 'a puppet module {string} from {string}' do |name, namespace| + pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace) + pmrr.populate +end + +Given 'a git_base option appended to "modulesync.yml" for local tests' do + File.write "#{Aruba.config.working_directory}/modulesync.yml", "\ngit_base: #{Faker::PuppetModuleRemoteRepo.git_base}", mode: 'a' +end + +Given 'the puppet module {string} from {string} is read-only' do |name, namespace| + pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace) + pmrr.read_only = true +end + +Then 'the puppet module {string} from {string} have no commit between {string} and {string}' do |name, namespace, commit1, commit2| + pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace) + expect(pmrr.commit_count_between(commit1, commit2)).to eq 0 +end + +Then 'the puppet module {string} from {string} have( only) {int} commit(s) made by {string}' do |name, namespace, commit_count, author| + pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace) + expect(pmrr.commit_count_by(author)).to eq commit_count +end + +Then 'the puppet module {string} from {string} have( only) {int} commit(s) made by {string} in branch {string}' do |name, namespace, commit_count, author, branch| + pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace) + expect(pmrr.commit_count_by(author, branch)).to eq commit_count +end + +Then 'the puppet module {string} from {string} have no commit made by {string}' do |name, namespace, author| + step "the puppet module \"#{name}\" from \"#{namespace}\" have 0 commit made by \"#{author}\"" +end + +Given 'the puppet module {string} from {string} have a file named {string} with:' do |name, namespace, filename, content| + pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace) + pmrr.add_file(filename, content) +end + +Then 'the puppet module {string} from {string} should have a branch {string} with a file named {string} which contains:' do |name, namespace, branch, filename, content| + pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace) + expect(pmrr.read_file(filename, branch)).to include(content) +end + +Given 'the puppet module {string} from {string} have the default branch named {string}' do |name, namespace, default_branch| + pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace) + pmrr.default_branch = default_branch +end + Given 'a remote module repository' do steps %( Given a directory named "sources" From fee8ee75722b353d5d12d311134d7c764be18cde Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Sun, 20 Dec 2020 00:39:16 +0100 Subject: [PATCH 06/29] Tests: Set git identity to "Aruba Date: Sun, 20 Dec 2020 00:44:47 +0100 Subject: [PATCH 07/29] Tests: Improve behavior tests scenarios by using PuppetModuleRemoteRepo faker This commit replaces the use of dummy remote repo hosted on GitHub (ie. puppet-test from maestrodev) by fake repos provided by Faker::PuppetModuleRemoteRepo. Additonally, this commit adds expectations to ensure the remote is, or not depending the test, altered by the running test. --- features/cli.feature | 11 +- features/update.feature | 406 +++++++++++++++++++++++++++------------- 2 files changed, 282 insertions(+), 135 deletions(-) diff --git a/features/cli.feature b/features/cli.feature index 509ba47c..afa08699 100644 --- a/features/cli.feature +++ b/features/cli.feature @@ -18,7 +18,8 @@ Feature: CLI And the output should match /Commands:/ Scenario: When overriding a setting from the config file on the command line - Given a file named "managed_modules.yml" with: + Given a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: """ --- - puppet-test @@ -26,10 +27,10 @@ Feature: CLI And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: 'git@github.com:' + namespace: default """ + And a git_base option appended to "modulesync.yml" for local tests And a directory named "moduleroot" - When I run `msync update --noop --git-base https://github.com/` + When I run `msync update --noop --namespace maestrodev` Then the exit status should be 0 - And the output should not match /git@github.com:/ + And the output should match /Syncing maestrodev/ diff --git a/features/update.feature b/features/update.feature index 5dedf977..34718f1b 100644 --- a/features/update.feature +++ b/features/update.feature @@ -2,7 +2,9 @@ Feature: update ModuleSync needs to update module boilerplate Scenario: Adding a new file - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: """ --- - puppet-test @@ -10,9 +12,9 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: https://github.com/ + namespace: maestrodev """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -35,7 +37,10 @@ Feature: update Then the output should contain "aruba" Scenario: Using skip_broken option and adding a new file to repo without write access - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "faker" + And the puppet module "puppet-test" from "faker" is read-only + And a file named "managed_modules.yml" with: """ --- - puppet-test @@ -43,9 +48,9 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: 'git@github.com:' + namespace: faker """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -59,9 +64,13 @@ Feature: update """ When I run `msync update -s -m "Add test"` Then the exit status should be 0 + And the puppet module "puppet-test" from "faker" have no commit made by "Aruba" Scenario: Adding a new file to repo without write access - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And the puppet module "puppet-test" from "maestrodev" is read-only + And a file named "managed_modules.yml" with: """ --- - puppet-test @@ -69,9 +78,9 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: 'git@github.com:' + namespace: maestrodev """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -85,9 +94,12 @@ Feature: update """ When I run `msync update -m "Add test" -r` Then the exit status should be 1 + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: Adding a new file, without the .erb suffix - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: """ --- - puppet-test @@ -95,9 +107,9 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: https://github.com/ + namespace: maestrodev """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -122,9 +134,12 @@ Feature: update """ Given I run `cat modules/maestrodev/puppet-test/test` Then the output should contain "aruba" + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: Adding a new file using global values - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: """ --- - puppet-test @@ -132,9 +147,9 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: https://github.com/ + namespace: maestrodev """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -155,9 +170,12 @@ Feature: update """ Given I run `cat modules/maestrodev/puppet-test/test` Then the output should contain "aruba" + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: Adding a new file overriding global values - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: """ --- - puppet-test @@ -165,9 +183,9 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: https://github.com/ + namespace: maestrodev """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -191,9 +209,12 @@ Feature: update """ Given I run `cat modules/maestrodev/puppet-test/test` Then the output should contain "aruba" + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: Adding a new file ignoring global values - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: """ --- - puppet-test @@ -201,9 +222,9 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: https://github.com/ + namespace: maestrodev """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -227,9 +248,12 @@ Feature: update """ Given I run `cat modules/maestrodev/puppet-test/test` Then the output should contain "aruba" + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: Adding a file that ERB can't parse - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: """ --- - puppet-test @@ -237,9 +261,9 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: https://github.com/ + namespace: maestrodev """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -255,9 +279,12 @@ Feature: update """ When I run `msync update --noop` Then the exit status should be 1 + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: Using skip_broken option with invalid files - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: """ --- - puppet-test @@ -265,9 +292,9 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: https://github.com/ + namespace: maestrodev """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -283,9 +310,12 @@ Feature: update """ When I run `msync update --noop -s` Then the exit status should be 0 + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: Using skip_broken and fail_on_warnings options with invalid files - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: """ --- - puppet-test @@ -293,9 +323,9 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: https://github.com/ + namespace: maestrodev """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -311,9 +341,16 @@ Feature: update """ When I run `msync update --noop --skip_broken --fail_on_warnings` Then the exit status should be 1 + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: Modifying an existing file - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And the puppet module "puppet-test" from "maestrodev" have a file named "Gemfile" with: + """ + source 'https://example.com' + """ + And a file named "managed_modules.yml" with: """ --- - puppet-test @@ -321,9 +358,9 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: https://github.com/ + namespace: maestrodev """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -347,10 +384,26 @@ Feature: update """ source 'https://somehost.com' """ + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: Modifying an existing file and committing the change Given a mocked git configuration - And a remote module repository + And a puppet module "puppet-test" from "maestrodev" + And the puppet module "puppet-test" from "maestrodev" have a file named "Gemfile" with: + """ + source 'https://example.com' + """ + And a file named "managed_modules.yml" with: + """ + --- + - puppet-test + """ + And a file named "modulesync.yml" with: + """ + --- + namespace: maestrodev + """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -364,15 +417,21 @@ Feature: update """ When I run `msync update -m "Update Gemfile" -r test` Then the exit status should be 0 - Given I cd to "sources/puppet-test" - And I run `git checkout test` - Then the file "Gemfile" should contain: + And the puppet module "puppet-test" from "maestrodev" have only 1 commit made by "Aruba" + And the puppet module "puppet-test" from "maestrodev" have 1 commit made by "Aruba" in branch "test" + And the puppet module "puppet-test" from "maestrodev" should have a branch "test" with a file named "Gemfile" which contains: """ source 'https://somehost.com' """ Scenario: Setting an existing file to unmanaged - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And the puppet module "puppet-test" from "maestrodev" have a file named "Gemfile" with: + """ + source 'https://rubygems.org' + """ + And a file named "managed_modules.yml" with: """ --- - puppet-test @@ -380,14 +439,15 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: https://github.com/ + namespace: maestrodev """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- Gemfile: unmanaged: true + gem_source: https://somehost.com """ And a directory named "moduleroot" And a file named "moduleroot/Gemfile.erb" with: @@ -410,9 +470,12 @@ Feature: update """ source 'https://rubygems.org' """ + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: Setting an existing file to deleted - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: """ --- - puppet-test @@ -420,9 +483,9 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: https://github.com/ + namespace: maestrodev """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -434,6 +497,10 @@ Feature: update """ source '<%= @configs['gem_source'] %>' """ + And the puppet module "puppet-test" from "fakenamespace" have a file named "Gemfile" with: + """ + source 'https://rubygems.org' + """ When I run `msync update --noop` Then the output should match: """ @@ -442,9 +509,12 @@ Feature: update deleted file mode 100644 """ And the exit status should be 0 + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: Setting a non-existent file to deleted - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: """ --- - puppet-test @@ -452,9 +522,9 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: https://github.com/ + namespace: maestrodev """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -464,19 +534,22 @@ Feature: update And a directory named "moduleroot" When I run `msync update -m 'deletes a file that doesnt exist!' -f puppet-test` And the exit status should be 0 + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: Setting a directory to unmanaged - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-apache" from "puppetlabs" + And a file named "managed_modules.yml" with: """ --- - - puppetlabs-apache + - puppet-apache """ And a file named "modulesync.yml" with: """ --- - namespace: puppetlabs - git_base: https://github.com/ + namespace: puppetlabs """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -488,26 +561,29 @@ Feature: update """ some spec_helper fud """ - And a directory named "modules/puppetlabs/puppetlabs-apache/spec" - And a file named "modules/puppetlabs/puppetlabs-apache/spec/spec_helper.rb" with: + And a directory named "modules/puppetlabs/puppet-apache/spec" + And a file named "modules/puppetlabs/puppet-apache/spec/spec_helper.rb" with: """ This is a fake spec_helper! """ When I run `msync update --offline` Then the output should contain: """ - Not managing spec/spec_helper.rb in puppetlabs-apache + Not managing spec/spec_helper.rb in puppet-apache """ And the exit status should be 0 - Given I run `cat modules/puppetlabs/puppetlabs-apache/spec/spec_helper.rb` + Given I run `cat modules/puppetlabs/puppet-apache/spec/spec_helper.rb` Then the output should contain: """ This is a fake spec_helper! """ And the exit status should be 0 + And the puppet module "puppet-apache" from "puppetlabs" have no commit made by "Aruba" Scenario: Adding a new file in a new subdirectory - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: """ --- - puppet-test @@ -515,9 +591,9 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: https://github.com/ + namespace: maestrodev """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -543,9 +619,12 @@ Feature: update """ require 'puppetlabs_spec_helper/module_helper' """ + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: Updating offline - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: """ --- - puppet-test @@ -553,9 +632,9 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: https://github.com/ + namespace: maestrodev """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -572,9 +651,12 @@ Feature: update When I run `msync update --offline` Then the exit status should be 0 And the output should not match /Files (changed|added|deleted):/ + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: Pulling a module that already exists in the modules directory - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: """ --- - maestrodev/puppet-test @@ -582,9 +664,13 @@ Feature: update And a file named "modulesync.yml" with: """ --- - git_base: https://github.com/ + namespace: maestrodev """ - And a file named "config_defaults.yml" with: + And a git_base option appended to "modulesync.yml" for local tests + When I run `msync update` + Then the exit status should be 0 + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + Given a file named "config_defaults.yml" with: """ --- spec/spec_helper.rb: @@ -597,20 +683,6 @@ Feature: update require '<%= required %>' <% end %> """ - Given I run `git init modules/maestrodev/puppet-test` - Given a file named "modules/maestrodev/puppet-test/.git/config" with: - """ - [core] - repositoryformatversion = 0 - filemode = true - bare = false - logallrefupdates = true - ignorecase = true - precomposeunicode = true - [remote "origin"] - url = https://github.com/maestrodev/puppet-test.git - fetch = +refs/heads/*:refs/remotes/origin/* - """ When I run `msync update --noop` Then the exit status should be 0 And the output should match: @@ -618,9 +690,12 @@ Feature: update Files added: spec/spec_helper.rb """ + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: When running update with no changes - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: """ --- - puppet-test @@ -628,16 +703,18 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: https://github.com/ + namespace: maestrodev """ + And a git_base option appended to "modulesync.yml" for local tests And a directory named "moduleroot" - When I run `msync update --noop` + When I run `msync update` Then the exit status should be 0 - And the output should not match /diff/ + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: When specifying configurations in managed_modules.yml - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: """ --- puppet-test: @@ -646,9 +723,9 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: https://github.com/ + namespace: maestrodev """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -669,9 +746,13 @@ Feature: update """ Given I run `cat modules/maestrodev/puppet-test/test` Then the output should contain "aruba" + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: When specifying configurations in managed_modules.yml and using a filter - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-blacksmith" from "maestrodev" + And a file named "managed_modules.yml" with: """ --- puppet-blacksmith: @@ -681,9 +762,9 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: https://github.com/ + namespace: maestrodev """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -705,9 +786,13 @@ Feature: update Given I run `cat modules/maestrodev/puppet-test/test` Then the output should contain "aruba" And a directory named "modules/maestrodev/puppet-blacksmith" should not exist + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: When specifying configurations in managed_modules.yml and using a negative filter - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-blacksmith" from "maestrodev" + And a file named "managed_modules.yml" with: """ --- puppet-blacksmith: @@ -717,9 +802,9 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: https://github.com/ + namespace: maestrodev """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -741,9 +826,12 @@ Feature: update Given I run `cat modules/maestrodev/puppet-test/test` Then the output should contain "aruba" And a directory named "modules/maestrodev/puppet-blacksmith" should not exist + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: Updating a module with a .sync.yml file - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: """ --- - maestrodev/puppet-test @@ -751,8 +839,9 @@ Feature: update And a file named "modulesync.yml" with: """ --- - git_base: https://github.com/ + namespace: maestrodev """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -775,21 +864,7 @@ Feature: update <%= @configs['global-to-overwrite'] %> <%= @configs['module-default'] %> """ - Given I run `git init modules/maestrodev/puppet-test` - Given a file named "modules/maestrodev/puppet-test/.git/config" with: - """ - [core] - repositoryformatversion = 0 - filemode = true - bare = false - logallrefupdates = true - ignorecase = true - precomposeunicode = true - [remote "origin"] - url = https://github.com/maestrodev/puppet-test.git - fetch = +refs/heads/*:refs/remotes/origin/* - """ - Given a file named "modules/maestrodev/puppet-test/.sync.yml" with: + And the puppet module "puppet-test" from "maestrodev" have a file named ".sync.yml" with: """ --- :global: @@ -811,9 +886,13 @@ Feature: update it-is-overwritten some-value """ + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: Module with custom namespace - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-lib-file_concat" from "electrical" + And a file named "managed_modules.yml" with: """ --- - puppet-test @@ -822,9 +901,9 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: https://github.com/ + namespace: maestrodev """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -844,12 +923,16 @@ Feature: update test """ Given I run `cat modules/maestrodev/puppet-test/.git/config` - Then the output should contain "url = https://github.com/maestrodev/puppet-test.git" + Then the output should match /^\s+url = .*maestrodev.puppet-test$/ Given I run `cat modules/electrical/puppet-lib-file_concat/.git/config` - Then the output should contain "url = https://github.com/electrical/puppet-lib-file_concat.git" + Then the output should match /^\s+url = .*electrical.puppet-lib-file_concat$/ + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-lib-file_concat" from "electrical" have no commit made by "Aruba" Scenario: Modifying an existing file with values exposed by the module - Given a file named "managed_modules.yml" with: + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: """ --- - puppet-test @@ -857,9 +940,9 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev - git_base: https://github.com/ + namespace: maestrodev """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -868,7 +951,12 @@ Feature: update And a directory named "moduleroot" And a file named "moduleroot/README.md.erb" with: """ - echo '<%= @configs[:git_base] + @configs[:namespace] %>' + module: <%= @configs[:puppet_module] %> + namespace: <%= @configs[:namespace] %> + """ + And the puppet module "puppet-test" from "maestrodev" have a file named "README.md" with: + """ + Hello world! """ When I run `msync update --noop` Then the exit status should be 0 @@ -880,12 +968,25 @@ Feature: update Given I run `cat modules/maestrodev/puppet-test/README.md` Then the output should contain: """ - echo 'https://github.com/maestrodev' + module: puppet-test + namespace: maestrodev """ + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: Running the same update twice and pushing to a remote branch Given a mocked git configuration - And a remote module repository + And a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: + """ + --- + - puppet-test + """ + And a file named "modulesync.yml" with: + """ + --- + namespace: maestrodev + """ + And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -899,15 +1000,30 @@ Feature: update """ When I run `msync update -m "Update Gemfile" -r test` Then the exit status should be 0 + And the puppet module "puppet-test" from "maestrodev" have only 1 commit made by "Aruba" + And the puppet module "puppet-test" from "maestrodev" have 1 commit made by "Aruba" in branch "test" Given I remove the directory "modules" When I run `msync update -m "Update Gemfile" -r test` Then the exit status should be 0 Then the output should not contain "error" Then the output should not contain "rejected" + And the puppet module "puppet-test" from "maestrodev" have only 1 commit made by "Aruba" + And the puppet module "puppet-test" from "maestrodev" have 1 commit made by "Aruba" in branch "test" Scenario: Creating a GitHub PR with an update Given a mocked git configuration - And a remote module repository + And a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: + """ + --- + - puppet-test + """ + And a file named "modulesync.yml" with: + """ + --- + namespace: maestrodev + """ + And a git_base option appended to "modulesync.yml" for local tests And a directory named "moduleroot" And I set the environment variables to: | variable | value | @@ -915,10 +1031,22 @@ Feature: update When I run `msync update --noop --branch managed_update --pr` Then the output should contain "Would submit PR " And the exit status should be 0 + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: Creating a GitLab MR with an update Given a mocked git configuration - And a remote module repository + And a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: + """ + --- + - puppet-test + """ + And a file named "modulesync.yml" with: + """ + --- + namespace: maestrodev + """ + And a git_base option appended to "modulesync.yml" for local tests And a directory named "moduleroot" And I set the environment variables to: | variable | value | @@ -926,10 +1054,23 @@ Feature: update When I run `msync update --noop --branch managed_update --pr` Then the output should contain "Would submit MR " And the exit status should be 0 + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" Scenario: Repository with a default branch other than master Given a mocked git configuration - And a remote module repository with "develop" as the default branch + And a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: + """ + --- + - puppet-test + """ + And a file named "modulesync.yml" with: + """ + --- + namespace: maestrodev + """ + And a git_base option appended to "modulesync.yml" for local tests + And the puppet module "puppet-test" from "maestrodev" have the default branch named "develop" And a file named "config_defaults.yml" with: """ --- @@ -943,23 +1084,27 @@ Feature: update """ When I run `msync update -m "Update Gemfile"` Then the exit status should be 0 - Then the output should contain "Using repository's default branch: develop" + And the output should contain "Using repository's default branch: develop" + And the puppet module "puppet-test" from "maestrodev" have only 1 commit made by "Aruba" + And the puppet module "puppet-test" from "maestrodev" have 1 commit made by "Aruba" in branch "develop" - Scenario: Adding a new file from a template using meta data - And a file named "config_defaults.yml" with: + Scenario: Adding a new file from a template using metadata + Given a mocked git configuration + And a puppet module "puppet-test" from "maestrodev" + And a file named "managed_modules.yml" with: """ --- + - puppet-test """ - Given a file named "managed_modules.yml" with: + And a file named "modulesync.yml" with: """ --- - - puppet-test + namespace: maestrodev """ - And a file named "modulesync.yml" with: + And a git_base option appended to "modulesync.yml" for local tests + And a file named "config_defaults.yml" with: """ --- - namespace: maestrodev - git_base: https://github.com/ """ And a directory named "moduleroot" And a file named "moduleroot/test.erb" with: @@ -977,3 +1122,4 @@ Feature: update target: modules/maestrodev/puppet-test/test workdir: modules/maestrodev/puppet-test """ + And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" From 8d814d288cddfe89e1da5423ee0b8a2c3641a055 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Sun, 20 Dec 2020 00:39:54 +0100 Subject: [PATCH 08/29] Tests: Remove unused steps --- features/step_definitions/git_steps.rb | 41 -------------------------- 1 file changed, 41 deletions(-) diff --git a/features/step_definitions/git_steps.rb b/features/step_definitions/git_steps.rb index 3484593f..f65a3280 100644 --- a/features/step_definitions/git_steps.rb +++ b/features/step_definitions/git_steps.rb @@ -55,44 +55,3 @@ pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace) pmrr.default_branch = default_branch end - -Given 'a remote module repository' do - steps %( - Given a directory named "sources" - And I run `git clone https://github.com/maestrodev/puppet-test sources/puppet-test` - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - ) - write_file('modulesync.yml', <<~CONFIG) - --- - namespace: sources - git_base: file://#{expand_path('.')}/ - CONFIG -end - -Given Regexp.new(/a remote module repository with "(.+?)" as the default branch/) do |branch| - steps %( - Given a directory named "sources" - And I run `git clone --mirror https://github.com/maestrodev/puppet-test sources/puppet-test` - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - ) - write_file('modulesync.yml', <<~CONFIG) - --- - namespace: sources - git_base: file://#{expand_path('.')}/ - CONFIG - - cd('sources/puppet-test') do - steps %( - And I run `git branch -M master #{branch}` - And I run `git symbolic-ref HEAD refs/heads/#{branch}` - ) - end -end From b481c944ceed502e01ad33de54ee0f63a90d91b0 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Sat, 19 Dec 2020 22:40:51 +0100 Subject: [PATCH 09/29] Tests: Rename maestrodev namespace to fakenamespace As msync as a default git_base set to GitHub, we need to be sure that there is no online repo usage anymore. To do so, we choose an invalid namespace/repo couple that ensure we operate on local (fake) repos. --- features/cli.feature | 6 +- features/update.feature | 258 ++++++++++++++++++++-------------------- 2 files changed, 132 insertions(+), 132 deletions(-) diff --git a/features/cli.feature b/features/cli.feature index afa08699..f4ad61ed 100644 --- a/features/cli.feature +++ b/features/cli.feature @@ -18,7 +18,7 @@ Feature: CLI And the output should match /Commands:/ Scenario: When overriding a setting from the config file on the command line - Given a puppet module "puppet-test" from "maestrodev" + Given a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -31,6 +31,6 @@ Feature: CLI """ And a git_base option appended to "modulesync.yml" for local tests And a directory named "moduleroot" - When I run `msync update --noop --namespace maestrodev` + When I run `msync update --noop --namespace fakenamespace` Then the exit status should be 0 - And the output should match /Syncing maestrodev/ + And the output should match /Syncing fakenamespace/ diff --git a/features/update.feature b/features/update.feature index 34718f1b..a611252c 100644 --- a/features/update.feature +++ b/features/update.feature @@ -3,7 +3,7 @@ Feature: update Scenario: Adding a new file Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -12,7 +12,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -33,13 +33,13 @@ Feature: update Files added: test """ - Given I run `cat modules/maestrodev/puppet-test/test` + Given I run `cat modules/fakenamespace/puppet-test/test` Then the output should contain "aruba" Scenario: Using skip_broken option and adding a new file to repo without write access Given a mocked git configuration - And a puppet module "puppet-test" from "faker" - And the puppet module "puppet-test" from "faker" is read-only + And a puppet module "puppet-test" from "fakenamespace" + And the puppet module "puppet-test" from "fakenamespace" is read-only And a file named "managed_modules.yml" with: """ --- @@ -48,7 +48,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: faker + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -64,12 +64,12 @@ Feature: update """ When I run `msync update -s -m "Add test"` Then the exit status should be 0 - And the puppet module "puppet-test" from "faker" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Adding a new file to repo without write access Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" - And the puppet module "puppet-test" from "maestrodev" is read-only + And a puppet module "puppet-test" from "fakenamespace" + And the puppet module "puppet-test" from "fakenamespace" is read-only And a file named "managed_modules.yml" with: """ --- @@ -78,7 +78,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -94,11 +94,11 @@ Feature: update """ When I run `msync update -m "Add test" -r` Then the exit status should be 1 - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Adding a new file, without the .erb suffix Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -107,7 +107,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -132,13 +132,13 @@ Feature: update Files added: test """ - Given I run `cat modules/maestrodev/puppet-test/test` + Given I run `cat modules/fakenamespace/puppet-test/test` Then the output should contain "aruba" - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Adding a new file using global values Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -147,7 +147,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -168,13 +168,13 @@ Feature: update Files added: test """ - Given I run `cat modules/maestrodev/puppet-test/test` + Given I run `cat modules/fakenamespace/puppet-test/test` Then the output should contain "aruba" - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Adding a new file overriding global values Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -183,7 +183,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -207,13 +207,13 @@ Feature: update Files added: test """ - Given I run `cat modules/maestrodev/puppet-test/test` + Given I run `cat modules/fakenamespace/puppet-test/test` Then the output should contain "aruba" - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Adding a new file ignoring global values Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -222,7 +222,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -246,13 +246,13 @@ Feature: update Files added: test """ - Given I run `cat modules/maestrodev/puppet-test/test` + Given I run `cat modules/fakenamespace/puppet-test/test` Then the output should contain "aruba" - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Adding a file that ERB can't parse Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -261,7 +261,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -279,11 +279,11 @@ Feature: update """ When I run `msync update --noop` Then the exit status should be 1 - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Using skip_broken option with invalid files Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -292,7 +292,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -310,11 +310,11 @@ Feature: update """ When I run `msync update --noop -s` Then the exit status should be 0 - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Using skip_broken and fail_on_warnings options with invalid files Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -323,7 +323,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -341,12 +341,12 @@ Feature: update """ When I run `msync update --noop --skip_broken --fail_on_warnings` Then the exit status should be 1 - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Modifying an existing file Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" - And the puppet module "puppet-test" from "maestrodev" have a file named "Gemfile" with: + And a puppet module "puppet-test" from "fakenamespace" + And the puppet module "puppet-test" from "fakenamespace" have a file named "Gemfile" with: """ source 'https://example.com' """ @@ -358,7 +358,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -379,17 +379,17 @@ Feature: update Files changed: +diff --git a/Gemfile b/Gemfile """ - Given I run `cat modules/maestrodev/puppet-test/Gemfile` + Given I run `cat modules/fakenamespace/puppet-test/Gemfile` Then the output should contain: """ source 'https://somehost.com' """ - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Modifying an existing file and committing the change Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" - And the puppet module "puppet-test" from "maestrodev" have a file named "Gemfile" with: + And a puppet module "puppet-test" from "fakenamespace" + And the puppet module "puppet-test" from "fakenamespace" have a file named "Gemfile" with: """ source 'https://example.com' """ @@ -401,7 +401,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -417,17 +417,17 @@ Feature: update """ When I run `msync update -m "Update Gemfile" -r test` Then the exit status should be 0 - And the puppet module "puppet-test" from "maestrodev" have only 1 commit made by "Aruba" - And the puppet module "puppet-test" from "maestrodev" have 1 commit made by "Aruba" in branch "test" - And the puppet module "puppet-test" from "maestrodev" should have a branch "test" with a file named "Gemfile" which contains: + And the puppet module "puppet-test" from "fakenamespace" have only 1 commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have 1 commit made by "Aruba" in branch "test" + And the puppet module "puppet-test" from "fakenamespace" should have a branch "test" with a file named "Gemfile" which contains: """ source 'https://somehost.com' """ Scenario: Setting an existing file to unmanaged Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" - And the puppet module "puppet-test" from "maestrodev" have a file named "Gemfile" with: + And a puppet module "puppet-test" from "fakenamespace" + And the puppet module "puppet-test" from "fakenamespace" have a file named "Gemfile" with: """ source 'https://rubygems.org' """ @@ -439,7 +439,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -465,16 +465,16 @@ Feature: update Not managing Gemfile in puppet-test """ And the exit status should be 0 - Given I run `cat modules/maestrodev/puppet-test/Gemfile` + Given I run `cat modules/fakenamespace/puppet-test/Gemfile` Then the output should contain: """ source 'https://rubygems.org' """ - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Setting an existing file to deleted Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -483,7 +483,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -509,11 +509,11 @@ Feature: update deleted file mode 100644 """ And the exit status should be 0 - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Setting a non-existent file to deleted Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -522,7 +522,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -534,7 +534,7 @@ Feature: update And a directory named "moduleroot" When I run `msync update -m 'deletes a file that doesnt exist!' -f puppet-test` And the exit status should be 0 - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Setting a directory to unmanaged Given a mocked git configuration @@ -582,7 +582,7 @@ Feature: update Scenario: Adding a new file in a new subdirectory Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -591,7 +591,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -614,16 +614,16 @@ Feature: update Files added: spec/spec_helper.rb """ - Given I run `cat modules/maestrodev/puppet-test/spec/spec_helper.rb` + Given I run `cat modules/fakenamespace/puppet-test/spec/spec_helper.rb` Then the output should contain: """ require 'puppetlabs_spec_helper/module_helper' """ - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Updating offline Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -632,7 +632,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -651,25 +651,25 @@ Feature: update When I run `msync update --offline` Then the exit status should be 0 And the output should not match /Files (changed|added|deleted):/ - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Pulling a module that already exists in the modules directory Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- - - maestrodev/puppet-test + - fakenamespace/puppet-test """ And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests When I run `msync update` Then the exit status should be 0 - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Given a file named "config_defaults.yml" with: """ --- @@ -690,11 +690,11 @@ Feature: update Files added: spec/spec_helper.rb """ - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: When running update with no changes Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -703,17 +703,17 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a directory named "moduleroot" When I run `msync update` Then the exit status should be 0 - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: When specifying configurations in managed_modules.yml Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -723,7 +723,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -744,14 +744,14 @@ Feature: update Files added: test """ - Given I run `cat modules/maestrodev/puppet-test/test` + Given I run `cat modules/fakenamespace/puppet-test/test` Then the output should contain "aruba" - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: When specifying configurations in managed_modules.yml and using a filter Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" - And a puppet module "puppet-blacksmith" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" + And a puppet module "puppet-blacksmith" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -762,7 +762,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -783,15 +783,15 @@ Feature: update Files added: test """ - Given I run `cat modules/maestrodev/puppet-test/test` + Given I run `cat modules/fakenamespace/puppet-test/test` Then the output should contain "aruba" - And a directory named "modules/maestrodev/puppet-blacksmith" should not exist - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And a directory named "modules/fakenamespace/puppet-blacksmith" should not exist + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: When specifying configurations in managed_modules.yml and using a negative filter Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" - And a puppet module "puppet-blacksmith" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" + And a puppet module "puppet-blacksmith" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -802,7 +802,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -823,23 +823,23 @@ Feature: update Files added: test """ - Given I run `cat modules/maestrodev/puppet-test/test` + Given I run `cat modules/fakenamespace/puppet-test/test` Then the output should contain "aruba" - And a directory named "modules/maestrodev/puppet-blacksmith" should not exist - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And a directory named "modules/fakenamespace/puppet-blacksmith" should not exist + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Updating a module with a .sync.yml file Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- - - maestrodev/puppet-test + - fakenamespace/puppet-test """ And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -864,7 +864,7 @@ Feature: update <%= @configs['global-to-overwrite'] %> <%= @configs['module-default'] %> """ - And the puppet module "puppet-test" from "maestrodev" have a file named ".sync.yml" with: + And the puppet module "puppet-test" from "fakenamespace" have a file named ".sync.yml" with: """ --- :global: @@ -879,18 +879,18 @@ Feature: update """ Not managing spec/spec_helper.rb in puppet-test """ - Given I run `cat modules/maestrodev/puppet-test/global-test.md` + Given I run `cat modules/fakenamespace/puppet-test/global-test.md` Then the output should match: """ some-default it-is-overwritten some-value """ - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Module with custom namespace Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a puppet module "puppet-lib-file_concat" from "electrical" And a file named "managed_modules.yml" with: """ @@ -901,7 +901,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -922,16 +922,16 @@ Feature: update Files added: test """ - Given I run `cat modules/maestrodev/puppet-test/.git/config` - Then the output should match /^\s+url = .*maestrodev.puppet-test$/ + Given I run `cat modules/fakenamespace/puppet-test/.git/config` + Then the output should match /^\s+url = .*fakenamespace.puppet-test$/ Given I run `cat modules/electrical/puppet-lib-file_concat/.git/config` Then the output should match /^\s+url = .*electrical.puppet-lib-file_concat$/ - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" And the puppet module "puppet-lib-file_concat" from "electrical" have no commit made by "Aruba" Scenario: Modifying an existing file with values exposed by the module Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -940,7 +940,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -954,7 +954,7 @@ Feature: update module: <%= @configs[:puppet_module] %> namespace: <%= @configs[:namespace] %> """ - And the puppet module "puppet-test" from "maestrodev" have a file named "README.md" with: + And the puppet module "puppet-test" from "fakenamespace" have a file named "README.md" with: """ Hello world! """ @@ -965,17 +965,17 @@ Feature: update Files changed: +diff --git a/README.md b/README.md """ - Given I run `cat modules/maestrodev/puppet-test/README.md` + Given I run `cat modules/fakenamespace/puppet-test/README.md` Then the output should contain: """ module: puppet-test - namespace: maestrodev + namespace: fakenamespace """ - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Running the same update twice and pushing to a remote branch Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -984,7 +984,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -1000,19 +1000,19 @@ Feature: update """ When I run `msync update -m "Update Gemfile" -r test` Then the exit status should be 0 - And the puppet module "puppet-test" from "maestrodev" have only 1 commit made by "Aruba" - And the puppet module "puppet-test" from "maestrodev" have 1 commit made by "Aruba" in branch "test" + And the puppet module "puppet-test" from "fakenamespace" have only 1 commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have 1 commit made by "Aruba" in branch "test" Given I remove the directory "modules" When I run `msync update -m "Update Gemfile" -r test` Then the exit status should be 0 Then the output should not contain "error" Then the output should not contain "rejected" - And the puppet module "puppet-test" from "maestrodev" have only 1 commit made by "Aruba" - And the puppet module "puppet-test" from "maestrodev" have 1 commit made by "Aruba" in branch "test" + And the puppet module "puppet-test" from "fakenamespace" have only 1 commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have 1 commit made by "Aruba" in branch "test" Scenario: Creating a GitHub PR with an update Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -1021,7 +1021,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a directory named "moduleroot" @@ -1031,11 +1031,11 @@ Feature: update When I run `msync update --noop --branch managed_update --pr` Then the output should contain "Would submit PR " And the exit status should be 0 - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Creating a GitLab MR with an update Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -1044,7 +1044,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a directory named "moduleroot" @@ -1054,11 +1054,11 @@ Feature: update When I run `msync update --noop --branch managed_update --pr` Then the output should contain "Would submit MR " And the exit status should be 0 - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Repository with a default branch other than master Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -1067,10 +1067,10 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests - And the puppet module "puppet-test" from "maestrodev" have the default branch named "develop" + And the puppet module "puppet-test" from "fakenamespace" have the default branch named "develop" And a file named "config_defaults.yml" with: """ --- @@ -1085,12 +1085,12 @@ Feature: update When I run `msync update -m "Update Gemfile"` Then the exit status should be 0 And the output should contain "Using repository's default branch: develop" - And the puppet module "puppet-test" from "maestrodev" have only 1 commit made by "Aruba" - And the puppet module "puppet-test" from "maestrodev" have 1 commit made by "Aruba" in branch "develop" + And the puppet module "puppet-test" from "fakenamespace" have only 1 commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have 1 commit made by "Aruba" in branch "develop" Scenario: Adding a new file from a template using metadata Given a mocked git configuration - And a puppet module "puppet-test" from "maestrodev" + And a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- @@ -1099,7 +1099,7 @@ Feature: update And a file named "modulesync.yml" with: """ --- - namespace: maestrodev + namespace: fakenamespace """ And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: @@ -1115,11 +1115,11 @@ Feature: update """ When I run `msync update --noop` Then the exit status should be 0 - Given I run `cat modules/maestrodev/puppet-test/test` + Given I run `cat modules/fakenamespace/puppet-test/test` Then the output should contain: """ module: puppet-test - target: modules/maestrodev/puppet-test/test - workdir: modules/maestrodev/puppet-test + target: modules/fakenamespace/puppet-test/test + workdir: modules/fakenamespace/puppet-test """ - And the puppet module "puppet-test" from "maestrodev" have no commit made by "Aruba" + And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" From 1d4399452d145e87183f85860c3e7f7b23013f17 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Sat, 19 Dec 2020 23:36:01 +0100 Subject: [PATCH 10/29] Tests: Replace cat usage by aruba file matcher --- features/hook.feature | 8 +++---- features/update.feature | 51 ++++++++++++++--------------------------- 2 files changed, 20 insertions(+), 39 deletions(-) diff --git a/features/hook.feature b/features/hook.feature index 10e97909..cae008e9 100644 --- a/features/hook.feature +++ b/features/hook.feature @@ -5,8 +5,7 @@ Feature: hook Given a directory named ".git/hooks" When I run `msync hook activate` Then the exit status should be 0 - Given I run `cat .git/hooks/pre-push` - Then the output should contain "bash" + And the file named ".git/hooks/pre-push" should contain "bash" Scenario: Deactivating a hook Given a file named ".git/hooks/pre-push" with: @@ -21,8 +20,7 @@ Feature: hook Given a directory named ".git/hooks" When I run `msync hook activate -a '--foo bar --baz quux' -b master` Then the exit status should be 0 - Given I run `cat .git/hooks/pre-push` - Then the output should match: + And the file named ".git/hooks/pre-push" should contain: """ - "\$message" -n puppetlabs -b master --foo bar --baz quux + "$message" -n puppetlabs -b master --foo bar --baz quux """ diff --git a/features/update.feature b/features/update.feature index a611252c..fb440f75 100644 --- a/features/update.feature +++ b/features/update.feature @@ -33,8 +33,7 @@ Feature: update Files added: test """ - Given I run `cat modules/fakenamespace/puppet-test/test` - Then the output should contain "aruba" + And the file named "modules/fakenamespace/puppet-test/test" should contain "aruba" Scenario: Using skip_broken option and adding a new file to repo without write access Given a mocked git configuration @@ -132,8 +131,7 @@ Feature: update Files added: test """ - Given I run `cat modules/fakenamespace/puppet-test/test` - Then the output should contain "aruba" + And the file named "modules/fakenamespace/puppet-test/test" should contain "aruba" And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Adding a new file using global values @@ -168,8 +166,7 @@ Feature: update Files added: test """ - Given I run `cat modules/fakenamespace/puppet-test/test` - Then the output should contain "aruba" + And the file named "modules/fakenamespace/puppet-test/test" should contain "aruba" And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Adding a new file overriding global values @@ -207,8 +204,7 @@ Feature: update Files added: test """ - Given I run `cat modules/fakenamespace/puppet-test/test` - Then the output should contain "aruba" + And the file named "modules/fakenamespace/puppet-test/test" should contain "aruba" And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Adding a new file ignoring global values @@ -246,8 +242,7 @@ Feature: update Files added: test """ - Given I run `cat modules/fakenamespace/puppet-test/test` - Then the output should contain "aruba" + And the file named "modules/fakenamespace/puppet-test/test" should contain "aruba" And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Adding a file that ERB can't parse @@ -379,8 +374,7 @@ Feature: update Files changed: +diff --git a/Gemfile b/Gemfile """ - Given I run `cat modules/fakenamespace/puppet-test/Gemfile` - Then the output should contain: + And the file named "modules/fakenamespace/puppet-test/Gemfile" should contain: """ source 'https://somehost.com' """ @@ -465,8 +459,7 @@ Feature: update Not managing Gemfile in puppet-test """ And the exit status should be 0 - Given I run `cat modules/fakenamespace/puppet-test/Gemfile` - Then the output should contain: + And the file named "modules/fakenamespace/puppet-test/Gemfile" should contain: """ source 'https://rubygems.org' """ @@ -572,8 +565,7 @@ Feature: update Not managing spec/spec_helper.rb in puppet-apache """ And the exit status should be 0 - Given I run `cat modules/puppetlabs/puppet-apache/spec/spec_helper.rb` - Then the output should contain: + And the file named "modules/puppetlabs/puppet-apache/spec/spec_helper.rb" should contain: """ This is a fake spec_helper! """ @@ -614,8 +606,7 @@ Feature: update Files added: spec/spec_helper.rb """ - Given I run `cat modules/fakenamespace/puppet-test/spec/spec_helper.rb` - Then the output should contain: + And the file named "modules/fakenamespace/puppet-test/spec/spec_helper.rb" should contain: """ require 'puppetlabs_spec_helper/module_helper' """ @@ -744,8 +735,7 @@ Feature: update Files added: test """ - Given I run `cat modules/fakenamespace/puppet-test/test` - Then the output should contain "aruba" + And the file named "modules/fakenamespace/puppet-test/test" should contain "aruba" And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: When specifying configurations in managed_modules.yml and using a filter @@ -783,8 +773,7 @@ Feature: update Files added: test """ - Given I run `cat modules/fakenamespace/puppet-test/test` - Then the output should contain "aruba" + And the file named "modules/fakenamespace/puppet-test/test" should contain "aruba" And a directory named "modules/fakenamespace/puppet-blacksmith" should not exist And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" @@ -823,8 +812,7 @@ Feature: update Files added: test """ - Given I run `cat modules/fakenamespace/puppet-test/test` - Then the output should contain "aruba" + And the file named "modules/fakenamespace/puppet-test/test" should contain "aruba" And a directory named "modules/fakenamespace/puppet-blacksmith" should not exist And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" @@ -879,8 +867,7 @@ Feature: update """ Not managing spec/spec_helper.rb in puppet-test """ - Given I run `cat modules/fakenamespace/puppet-test/global-test.md` - Then the output should match: + And the file named "modules/fakenamespace/puppet-test/global-test.md" should contain: """ some-default it-is-overwritten @@ -922,10 +909,8 @@ Feature: update Files added: test """ - Given I run `cat modules/fakenamespace/puppet-test/.git/config` - Then the output should match /^\s+url = .*fakenamespace.puppet-test$/ - Given I run `cat modules/electrical/puppet-lib-file_concat/.git/config` - Then the output should match /^\s+url = .*electrical.puppet-lib-file_concat$/ + And the file named "modules/fakenamespace/puppet-test/.git/config" should match /^\s+url = .*fakenamespace.puppet-test$/ + And the file named "modules/electrical/puppet-lib-file_concat/.git/config" should match /^\s+url = .*electrical.puppet-lib-file_concat$/ And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" And the puppet module "puppet-lib-file_concat" from "electrical" have no commit made by "Aruba" @@ -965,8 +950,7 @@ Feature: update Files changed: +diff --git a/README.md b/README.md """ - Given I run `cat modules/fakenamespace/puppet-test/README.md` - Then the output should contain: + And the file named "modules/fakenamespace/puppet-test/README.md" should contain: """ module: puppet-test namespace: fakenamespace @@ -1115,8 +1099,7 @@ Feature: update """ When I run `msync update --noop` Then the exit status should be 0 - Given I run `cat modules/fakenamespace/puppet-test/test` - Then the output should contain: + And the file named "modules/fakenamespace/puppet-test/test" should contain: """ module: puppet-test target: modules/fakenamespace/puppet-test/test From 02bd978d3c23867f0e80397b07b8059f105ce393 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Sun, 20 Dec 2020 00:06:58 +0100 Subject: [PATCH 11/29] Tests: Provide a step to setup a msync with one puppet module This commit adds a "basic setup" step in order to reduce scenario verbosity and help to focus on important steps --- features/cli.feature | 13 +- features/step_definitions/git_steps.rb | 18 ++ features/update.feature | 387 ++----------------------- 3 files changed, 47 insertions(+), 371 deletions(-) diff --git a/features/cli.feature b/features/cli.feature index f4ad61ed..75630c02 100644 --- a/features/cli.feature +++ b/features/cli.feature @@ -18,18 +18,7 @@ Feature: CLI And the output should match /Commands:/ Scenario: When overriding a setting from the config file on the command line - Given a puppet module "puppet-test" from "fakenamespace" - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: default - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And a directory named "moduleroot" When I run `msync update --noop --namespace fakenamespace` Then the exit status should be 0 diff --git a/features/step_definitions/git_steps.rb b/features/step_definitions/git_steps.rb index f65a3280..68cd614c 100644 --- a/features/step_definitions/git_steps.rb +++ b/features/step_definitions/git_steps.rb @@ -1,5 +1,23 @@ require_relative '../../spec/helpers/faker/puppet_module_remote_repo' +Given 'a basic setup with a puppet module {string} from {string}' do |name, namespace| + steps %( + Given a mocked git configuration + And a puppet module "#{name}" from "#{namespace}" + And a file named "managed_modules.yml" with: + """ + --- + - #{name} + """ + And a file named "modulesync.yml" with: + """ + --- + namespace: #{namespace} + """ + And a git_base option appended to "modulesync.yml" for local tests + ) +end + Given 'a mocked git configuration' do steps %( Given a mocked home directory diff --git a/features/update.feature b/features/update.feature index fb440f75..8078a04f 100644 --- a/features/update.feature +++ b/features/update.feature @@ -2,19 +2,7 @@ Feature: update ModuleSync needs to update module boilerplate Scenario: Adding a new file - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And a file named "config_defaults.yml" with: """ --- @@ -36,20 +24,8 @@ Feature: update And the file named "modules/fakenamespace/puppet-test/test" should contain "aruba" Scenario: Using skip_broken option and adding a new file to repo without write access - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And the puppet module "puppet-test" from "fakenamespace" is read-only - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -66,20 +42,8 @@ Feature: update And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Adding a new file to repo without write access - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And the puppet module "puppet-test" from "fakenamespace" is read-only - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -96,19 +60,7 @@ Feature: update And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Adding a new file, without the .erb suffix - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And a file named "config_defaults.yml" with: """ --- @@ -135,19 +87,7 @@ Feature: update And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Adding a new file using global values - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And a file named "config_defaults.yml" with: """ --- @@ -170,19 +110,7 @@ Feature: update And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Adding a new file overriding global values - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And a file named "config_defaults.yml" with: """ --- @@ -208,19 +136,7 @@ Feature: update And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Adding a new file ignoring global values - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And a file named "config_defaults.yml" with: """ --- @@ -246,19 +162,7 @@ Feature: update And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Adding a file that ERB can't parse - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And a file named "config_defaults.yml" with: """ --- @@ -277,19 +181,7 @@ Feature: update And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Using skip_broken option with invalid files - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And a file named "config_defaults.yml" with: """ --- @@ -308,19 +200,7 @@ Feature: update And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Using skip_broken and fail_on_warnings options with invalid files - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And a file named "config_defaults.yml" with: """ --- @@ -339,23 +219,11 @@ Feature: update And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Modifying an existing file - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And the puppet module "puppet-test" from "fakenamespace" have a file named "Gemfile" with: """ source 'https://example.com' """ - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -381,23 +249,11 @@ Feature: update And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Modifying an existing file and committing the change - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And the puppet module "puppet-test" from "fakenamespace" have a file named "Gemfile" with: """ source 'https://example.com' """ - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -419,23 +275,11 @@ Feature: update """ Scenario: Setting an existing file to unmanaged - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And the puppet module "puppet-test" from "fakenamespace" have a file named "Gemfile" with: """ source 'https://rubygems.org' """ - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -466,19 +310,7 @@ Feature: update And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Setting an existing file to deleted - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And a file named "config_defaults.yml" with: """ --- @@ -505,19 +337,7 @@ Feature: update And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Setting a non-existent file to deleted - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And a file named "config_defaults.yml" with: """ --- @@ -530,19 +350,7 @@ Feature: update And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Setting a directory to unmanaged - Given a mocked git configuration - And a puppet module "puppet-apache" from "puppetlabs" - And a file named "managed_modules.yml" with: - """ - --- - - puppet-apache - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: puppetlabs - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-apache" from "puppetlabs" And a file named "config_defaults.yml" with: """ --- @@ -573,19 +381,7 @@ Feature: update And the puppet module "puppet-apache" from "puppetlabs" have no commit made by "Aruba" Scenario: Adding a new file in a new subdirectory - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And a file named "config_defaults.yml" with: """ --- @@ -613,19 +409,7 @@ Feature: update And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Updating offline - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And a file named "config_defaults.yml" with: """ --- @@ -645,19 +429,7 @@ Feature: update And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Pulling a module that already exists in the modules directory - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" - And a file named "managed_modules.yml" with: - """ - --- - - fakenamespace/puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" When I run `msync update` Then the exit status should be 0 And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" @@ -684,39 +456,20 @@ Feature: update And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: When running update with no changes - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And a directory named "moduleroot" When I run `msync update` Then the exit status should be 0 And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: When specifying configurations in managed_modules.yml - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And a file named "managed_modules.yml" with: """ --- puppet-test: module_name: test """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests And a file named "config_defaults.yml" with: """ --- @@ -817,19 +570,7 @@ Feature: update And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Updating a module with a .sync.yml file - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" - And a file named "managed_modules.yml" with: - """ - --- - - fakenamespace/puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And a file named "config_defaults.yml" with: """ --- @@ -915,19 +656,7 @@ Feature: update And the puppet module "puppet-lib-file_concat" from "electrical" have no commit made by "Aruba" Scenario: Modifying an existing file with values exposed by the module - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And a file named "config_defaults.yml" with: """ --- @@ -958,19 +687,7 @@ Feature: update And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Running the same update twice and pushing to a remote branch - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And a file named "config_defaults.yml" with: """ --- @@ -995,19 +712,7 @@ Feature: update And the puppet module "puppet-test" from "fakenamespace" have 1 commit made by "Aruba" in branch "test" Scenario: Creating a GitHub PR with an update - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And a directory named "moduleroot" And I set the environment variables to: | variable | value | @@ -1018,19 +723,7 @@ Feature: update And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Creating a GitLab MR with an update - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And a directory named "moduleroot" And I set the environment variables to: | variable | value | @@ -1041,19 +734,7 @@ Feature: update And the puppet module "puppet-test" from "fakenamespace" have no commit made by "Aruba" Scenario: Repository with a default branch other than master - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And the puppet module "puppet-test" from "fakenamespace" have the default branch named "develop" And a file named "config_defaults.yml" with: """ @@ -1073,19 +754,7 @@ Feature: update And the puppet module "puppet-test" from "fakenamespace" have 1 commit made by "Aruba" in branch "develop" Scenario: Adding a new file from a template using metadata - Given a mocked git configuration - And a puppet module "puppet-test" from "fakenamespace" - And a file named "managed_modules.yml" with: - """ - --- - - puppet-test - """ - And a file named "modulesync.yml" with: - """ - --- - namespace: fakenamespace - """ - And a git_base option appended to "modulesync.yml" for local tests + Given a basic setup with a puppet module "puppet-test" from "fakenamespace" And a file named "config_defaults.yml" with: """ --- From 79c0759af697e0e581ef889e99bc397f7b58df95 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Sun, 20 Dec 2020 00:11:36 +0100 Subject: [PATCH 12/29] Cucumber: Silent message about publishing results --- .config/cucumber.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .config/cucumber.yml diff --git a/.config/cucumber.yml b/.config/cucumber.yml new file mode 100644 index 00000000..fea5edc1 --- /dev/null +++ b/.config/cucumber.yml @@ -0,0 +1 @@ +default: --publish-quiet From 60847657b574a36f4aa429942c85766904ba9dc4 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Sun, 20 Dec 2020 12:47:21 +0100 Subject: [PATCH 13/29] Refactor ModuleSync#update in order to reuse code base --- lib/modulesync.rb | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/modulesync.rb b/lib/modulesync.rb index 101d4197..3c7c6fa5 100644 --- a/lib/modulesync.rb +++ b/lib/modulesync.rb @@ -148,7 +148,22 @@ def config_path(file, options) self.class.config_path(file, options) end - def self.update(options) + def self.update(cli_options) + prepare = lambda { |options| + local_template_dir = config_path(MODULE_FILES_DIR, options) + local_files = find_template_files(local_template_dir) + module_files = relative_names(local_files, local_template_dir) + return options.merge(_module_files: module_files) + } + + job = lambda { |puppet_module, module_options, defaults, options| + manage_module(puppet_module, options[:_module_files], module_options, defaults, options) + } + + run(cli_options, job, prepare) + end + + def self.run(options, job, prepare = nil) options = config_defaults.merge(options) defaults = Util.parse_config(config_path(CONF_FILE, options)) if options[:pr] @@ -160,9 +175,7 @@ def self.update(options) @pr = create_pr_manager if options[:pr] end - local_template_dir = config_path(MODULE_FILES_DIR, options) - local_files = find_template_files(local_template_dir) - module_files = relative_names(local_files, local_template_dir) + options = prepare.call(options) unless prepare.nil? managed_modules = self.managed_modules(config_path(options[:managed_modules_conf], options), options[:filter], @@ -172,13 +185,13 @@ def self.update(options) # managed_modules is either an array or a hash managed_modules.each do |puppet_module, module_options| begin - mod_options = module_options.nil? ? nil : Util.symbolize_keys(module_options) - manage_module(puppet_module, module_files, mod_options, defaults, options) + mod_options = module_options.nil? ? {} : Util.symbolize_keys(module_options) + job.call(puppet_module, mod_options, defaults, options) rescue # rubocop:disable Lint/RescueWithoutErrorClass - $stderr.puts "Error while updating #{puppet_module}" + $stderr.puts "Error during '#{options[:command]}' command on #{puppet_module}" raise unless options[:skip_broken] errors = true - $stdout.puts "Skipping #{puppet_module} as update process failed" + $stdout.puts "Skipping #{puppet_module} as '#{options[:command]}' process failed" end end exit 1 if errors && options[:fail_on_warnings] From ffffc5309ac0aa64b12b54cb905560024dab0456 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Sun, 20 Dec 2020 12:50:09 +0100 Subject: [PATCH 14/29] Reuse exception message if available --- lib/modulesync.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/modulesync.rb b/lib/modulesync.rb index 3c7c6fa5..3277ae71 100644 --- a/lib/modulesync.rb +++ b/lib/modulesync.rb @@ -187,8 +187,10 @@ def self.run(options, job, prepare = nil) begin mod_options = module_options.nil? ? {} : Util.symbolize_keys(module_options) job.call(puppet_module, mod_options, defaults, options) - rescue # rubocop:disable Lint/RescueWithoutErrorClass - $stderr.puts "Error during '#{options[:command]}' command on #{puppet_module}" + rescue StandardError => e + message = e.message || "Error during '#{options[:command]}'" + message = "#{puppet_module}: #{message}" + $stderr.puts message raise unless options[:skip_broken] errors = true $stdout.puts "Skipping #{puppet_module} as '#{options[:command]}' process failed" From 61c8445f8b0f1af2b9ea39b8f5a0cdabd1a6ca55 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Sun, 20 Dec 2020 12:29:54 +0100 Subject: [PATCH 15/29] FIXUP Refactor --- lib/modulesync.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/modulesync.rb b/lib/modulesync.rb index 3277ae71..f1e8c3a0 100644 --- a/lib/modulesync.rb +++ b/lib/modulesync.rb @@ -184,9 +184,10 @@ def self.run(options, job, prepare = nil) errors = false # managed_modules is either an array or a hash managed_modules.each do |puppet_module, module_options| + module_options ||= {} + module_options = Util.symbolize_keys(module_options) begin - mod_options = module_options.nil? ? {} : Util.symbolize_keys(module_options) - job.call(puppet_module, mod_options, defaults, options) + job.call(puppet_module, module_options, defaults, options) rescue StandardError => e message = e.message || "Error during '#{options[:command]}'" message = "#{puppet_module}: #{message}" From c1ae58d0c89caa1f6b9b6fd457dcf28492515999 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Tue, 15 Dec 2020 22:57:58 +0100 Subject: [PATCH 16/29] Set default value of remote-branch to branch according to help --- lib/modulesync.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/modulesync.rb b/lib/modulesync.rb index f1e8c3a0..d2a1cf1a 100644 --- a/lib/modulesync.rb +++ b/lib/modulesync.rb @@ -165,6 +165,7 @@ def self.update(cli_options) def self.run(options, job, prepare = nil) options = config_defaults.merge(options) + options[:remote_branch] ||= options[:branch] defaults = Util.parse_config(config_path(CONF_FILE, options)) if options[:pr] unless options[:branch] From aae9d882e5589cc9fee8654a79f597e01683dea8 Mon Sep 17 00:00:00 2001 From: Manuel Tancoigne Date: Tue, 15 Dec 2020 18:12:22 +0100 Subject: [PATCH 17/29] CLI: Add new command to push a specified branch for each managed module --- features/push.feature | 15 +++++++++++++ lib/modulesync.rb | 21 ++++++++++++++++++ lib/modulesync/cli.rb | 51 ++++++++++++++++++++++++++++++++++++++++++- lib/modulesync/git.rb | 10 +++++++++ 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 features/push.feature diff --git a/features/push.feature b/features/push.feature new file mode 100644 index 00000000..625b0ac2 --- /dev/null +++ b/features/push.feature @@ -0,0 +1,15 @@ +Feature: push + Use ModuleSync to push a specified branch from each repos and optionaly submit a PR/MR + + Scenario: When 'branch' option is missing + When I run `msync push` + Then the output should match /^No value provided for required options '--branch'$/ + + Scenario: Report the need to clone repositories if puppet module have not been fetch before + Given a basic setup with a puppet module "puppet-test" from "awesome" + When I run `msync push --branch hello` + Then the exit status should be 1 + And the stderr should contain: + """ + Repository must be locally available before trying to push + """ diff --git a/lib/modulesync.rb b/lib/modulesync.rb index d2a1cf1a..acda840e 100644 --- a/lib/modulesync.rb +++ b/lib/modulesync.rb @@ -10,6 +10,8 @@ require 'monkey_patches' module ModuleSync # rubocop:disable Metrics/ModuleLength + class Error < StandardError; end + include Constants def self.config_defaults @@ -163,6 +165,25 @@ def self.update(cli_options) run(cli_options, job, prepare) end + def self.push(cli_options) + job = lambda { |puppet_module, module_options, _defaults, options| + default_namespace = module_options[:namespace] || options[:namespace] + namespace, module_name = module_name(puppet_module, default_namespace) + repo_dir = File.join(options[:project_root], namespace, module_name) + + begin + repo = ::Git.open repo_dir + rescue ArgumentError => e + raise unless e.message == 'path does not exist' + raise ModuleSync::Error, 'Repository must be locally available before trying to push' + end + Git.push(repo, options) + options[:pr] && pr(module_options).manage(namespace, module_name, options) + } + + run(cli_options, job) + end + def self.run(options, job, prepare = nil) options = config_defaults.merge(options) options[:remote_branch] ||= options[:branch] diff --git a/lib/modulesync/cli.rb b/lib/modulesync/cli.rb index 72602219..cfc66c26 100644 --- a/lib/modulesync/cli.rb +++ b/lib/modulesync/cli.rb @@ -33,7 +33,7 @@ def deactivate end end - class Base < Thor + class Base < Thor # rubocop:disable Metrics/ClassLength class_option :project_root, :aliases => '-c', :desc => 'Path used by git to clone modules into.', @@ -141,6 +141,55 @@ def update ModuleSync.update(config) end + desc 'push', 'Push specified branch for each modules and submit PR if requested' + option :configs, + :aliases => '-c', + :desc => 'The local directory or remote repository to define the list of managed modules,' \ + ' the file templates, and the default values for template variables.' + option :managed_modules_conf, + :desc => 'The file name to define the list of managed modules' + option :skip_broken, + :type => :boolean, + :aliases => '-s', + :desc => 'Process remaining modules if an error is found', + :default => false + option :fail_on_warnings, + :type => :boolean, + :aliases => '-F', + :desc => 'Produce a failure exit code when there are warnings' \ + ' (only has effect when --skip_broken is enabled)', + :default => false + option :branch, + :aliases => '-b', + :desc => 'Branch name to push', + :required => true + option :remote_branch, + :aliases => '-r', + :desc => 'Remote branch name to push. Defaults to the branch name.' + option :force, + :type => :boolean, + :desc => 'Force push', + :default => false + option :pr, + :type => :boolean, + :desc => 'Submit pull/merge request', + :default => false + option :pr_title, + :desc => 'Title of pull/merge request' + option :pr_labels, + :type => :array, + :desc => 'Labels to add to the pull/merge request', + :default => CLI.defaults[:pr_labels] || [] + option :pr_target_branch, + :desc => 'Target branch for the pull/merge request', + :default => CLI.defaults[:pr_target_branch] || 'master' + def push + config = { :command => 'push' }.merge(options) + config = Util.symbolize_keys(config) + raise Thor::Error, 'No value provided for required option "--pr-title"' if config[:pr] && !config[:pr_title] + ModuleSync.push(config) + end + desc 'hook', 'Activate or deactivate a git hook.' subcommand 'hook', ModuleSync::CLI::Hook end diff --git a/lib/modulesync/git.rb b/lib/modulesync/git.rb index e6f70b69..cfada03a 100644 --- a/lib/modulesync/git.rb +++ b/lib/modulesync/git.rb @@ -71,6 +71,16 @@ def self.pull(git_base, name, branch, project_root, opts) end end + def self.push(repo, options) + git_options = {} + git_options = { :force => true } if options[:force] + + remote = 'origin' + remote_url = repo.remote('origin').url + $stdout.puts "Push branch '#{options[:branch]}' to '#{remote_url}' (#{remote}/#{options[:remote_branch]})" + repo.push(remote, "#{options[:branch]}:#{options[:remote_branch]}", git_options) + end + def self.update_changelog(repo, version, message, module_root) changelog = "#{module_root}/CHANGELOG.md" if File.exist?(changelog) From ed80a459fb91de0027484c3db4dc332f484bf560 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 16 Dec 2020 00:22:48 +0100 Subject: [PATCH 18/29] README: Add section for "push" command --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 83dc61db..7fc4957d 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Table of Contents 4. [Installing](#installing) 5. [Workflow](#workflow) 6. [The Templates](#the-templates) +7. [Additional features](#additional-features) Usage TLDR ---------- @@ -436,3 +437,20 @@ The Templates See [Puppet's modulesync\_configs](https://github.com/puppetlabs/modulesync_configs) and [Vox Pupuli's modulesync\_config](https://github.com/voxpupuli/modulesync_config) repositories for different templates currently in use. + +Additional features +------------------- + +## Push manually a branch for each module + +After a regular `msync update` without push, you may want to add some commits manually then push. + +```shell +msync push --branch my-specific-branch +``` + +Like `update` command, you can submit a PR/MR using the same options: + +```shell +msync push --branch my-specific-feature-branch --pr --pr-title "Add a new super feature" +``` From 58986c26ea6ed1aed8afea98f746c7ceb4eec890 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 16 Dec 2020 23:36:50 +0100 Subject: [PATCH 19/29] Refactor Git#pull for reusability and readability --- features/cli.feature | 5 ++++- lib/modulesync.rb | 6 +++++- lib/modulesync/git.rb | 39 ++++++++++++++++++++++++++------------- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/features/cli.feature b/features/cli.feature index 75630c02..e920521a 100644 --- a/features/cli.feature +++ b/features/cli.feature @@ -22,4 +22,7 @@ Feature: CLI And a directory named "moduleroot" When I run `msync update --noop --namespace fakenamespace` Then the exit status should be 0 - And the output should match /Syncing fakenamespace/ + And the stdout should contain: + """ + Syncing 'fakenamespace/puppet-test' + """ diff --git a/lib/modulesync.rb b/lib/modulesync.rb index acda840e..87637a29 100644 --- a/lib/modulesync.rb +++ b/lib/modulesync.rb @@ -114,7 +114,11 @@ def self.manage_module(puppet_module, module_files, module_options, defaults, op namespace, module_name = module_name(puppet_module, default_namespace) git_repo = File.join(namespace, module_name) unless options[:offline] - Git.pull(options[:git_base], git_repo, options[:branch], options[:project_root], module_options || {}) + git_options = { + override_changes: true, + remote: module_options[:remote], + } + Git.pull(options[:git_base], git_repo, options[:branch], options[:project_root], git_options) end module_configs = Util.parse_config(module_file(options[:project_root], namespace, module_name, MODULE_CONF_FILE)) diff --git a/lib/modulesync/git.rb b/lib/modulesync/git.rb index cfada03a..49c7cf13 100644 --- a/lib/modulesync/git.rb +++ b/lib/modulesync/git.rb @@ -45,30 +45,43 @@ def self.switch_branch(repo, branch) end end - def self.pull(git_base, name, branch, project_root, opts) - puts "Syncing #{name}" - Dir.mkdir(project_root) unless Dir.exist?(project_root) + def self.pull(git_base, name, branch, project_root, options) + puts "Syncing '#{name}'" + repo_dir = "#{project_root}/#{name}" # Repo needs to be cloned in the cwd - if !Dir.exist?("#{project_root}/#{name}") || !Dir.exist?("#{project_root}/#{name}/.git") - puts 'Cloning repository fresh' - remote = opts[:remote] || (git_base.start_with?('file://') ? "#{git_base}#{name}" : "#{git_base}#{name}.git") - local = "#{project_root}/#{name}" - puts "Cloning from #{remote}" - repo = ::Git.clone(remote, local) + if !Dir.exist?("#{repo_dir}/.git") + remote = options[:remote] || (git_base.start_with?('file://') ? "#{git_base}#{name}" : "#{git_base}#{name}.git") + puts "Cloning '#{remote}' to '#{repo_dir}'" + repo = ::Git.clone(remote, repo_dir) switch_branch(repo, branch) # Repo already cloned, check out master and override local changes else # Some versions of git can't properly handle managing a repo from outside the repo directory - Dir.chdir("#{project_root}/#{name}") do - puts "Overriding any local changes to repositories in #{project_root}" + Dir.chdir(repo_dir) do repo = ::Git.open('.') repo.fetch - repo.reset_hard + if options[:override_changes] + puts "Overriding any local changes in '#{repo_dir}'" + repo.reset_hard + end + switch_branch(repo, branch) - repo.pull('origin', branch) if remote_branch_exists?(repo, branch) + + if options[:reset_hard] + repo.reset_hard(options[:reset_hard]) + elsif options[:override_changes] + if remote_branch_exists?(repo, branch) + # FIXME: It does not honor --remote-branch option, should it? + puts "Pulling changes from 'origin/#{branch}' in '#{repo_dir}'" + # NOTE: It seems to be more efficient to hard-reset here + repo.pull('origin', branch) + end + end end end + + repo end def self.push(repo, options) From 1e29b9d00d4b013fa1ac98589419d661536758c8 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Tue, 15 Dec 2020 23:37:46 +0100 Subject: [PATCH 20/29] CLI: Add new command to execute a script on each managed module --- lib/modulesync.rb | 27 +++++++++++++++++ lib/modulesync/cli.rb | 68 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/lib/modulesync.rb b/lib/modulesync.rb index 87637a29..29e6809b 100644 --- a/lib/modulesync.rb +++ b/lib/modulesync.rb @@ -1,5 +1,6 @@ require 'fileutils' require 'pathname' +require 'English' require 'modulesync/cli' require 'modulesync/constants' require 'modulesync/git' @@ -188,6 +189,32 @@ def self.push(cli_options) run(cli_options, job) end + def self.execute(cli_options) + job = lambda { |puppet_module, module_options, _defaults, options| + default_namespace = module_options[:namespace] || options[:namespace] + namespace, module_name = module_name(puppet_module, default_namespace) + + module_fullname = File.join(namespace, module_name) + repo_dir = File.join(options[:project_root], module_fullname) + + git_options = { + remote: module_options[:remote], + reset_hard: options[:reset_hard], + } + repo = Git.pull(options[:git_base], module_fullname, options[:branch], options[:project_root], git_options) + + FileUtils.chdir(repo_dir) do + result = system(options[:script]) + raise "Error during script execution (#{$CHILD_STATUS})" unless result + + options[:push] && Git.push(repo, options) + options[:push] && options[:pr] && pr(module_options).manage(namespace, module_name, options) + end + } + + run(cli_options, job) + end + def self.run(options, job, prepare = nil) options = config_defaults.merge(options) options[:remote_branch] ||= options[:branch] diff --git a/lib/modulesync/cli.rb b/lib/modulesync/cli.rb index cfc66c26..f6532759 100644 --- a/lib/modulesync/cli.rb +++ b/lib/modulesync/cli.rb @@ -190,6 +190,74 @@ def push ModuleSync.push(config) end + desc 'execute SCRIPT', 'Execute a script on each managed modules then push/PR if requested' + option :configs, + :aliases => '-c', + :desc => 'The local directory or remote repository to define the list of managed modules,' \ + ' the file templates, and the default values for template variables.' + option :managed_modules_conf, + :desc => 'The file name to define the list of managed modules' + option :skip_broken, + :type => :boolean, + :aliases => '-s', + :desc => 'Process remaining modules if an error is found', + :default => false + option :fail_on_warnings, + :type => :boolean, + :aliases => '-F', + :desc => 'Produce a failure exit code when there are warnings' \ + ' (only has effect when --skip_broken is enabled)', + :default => false + option :branch, + :aliases => '-b', + :desc => 'Branch name to make the changes in.', + :required => true + option :reset_hard, + :desc => 'Hard-reset on specified branch (e.g. origin/master) between fetch and script execution' + option :push, + :desc => 'Push the changes. Please note that it is up to the script to carry out commits.', + :type => :boolean, + :default => false + option :remote_branch, + :aliases => '-r', + :desc => 'Remote branch name to push the changes to. Defaults to the branch name.' + option :force, + :type => :boolean, + :desc => 'Force push commit', + :default => false + option :pr, + :type => :boolean, + :desc => 'Submit pull/merge request', + :default => false + option :pr_title, + :desc => 'Title of pull/merge request' + option :pr_labels, + :type => :array, + :desc => 'Labels to add to the pull/merge request', + :default => CLI.defaults[:pr_labels] || [] + option :pr_target_branch, + :desc => 'Target branch for the pull/merge request', + :default => CLI.defaults[:pr_target_branch] || 'master' + def execute(script) + script = File.expand_path(script) + + unless File.executable? script + $stderr.puts 'Script does not exist nor executable' + raise + end + + config = { + :command => 'execute', + :script => script, + }.merge(options) + config = Util.symbolize_keys(config) + + raise Thor::Error, 'Option "--pr" requires "--push"' if config[:pr] && !config[:push] + raise Thor::Error, 'No value provided for required option "--pr-title"' if config[:pr] && !config[:pr_title] + + ModuleSync.execute(config) + end + desc 'hook', 'Activate or deactivate a git hook.' subcommand 'hook', ModuleSync::CLI::Hook end From f44757ad438e947e9ad96ea96019cebf11495f6a Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 16 Dec 2020 00:25:27 +0100 Subject: [PATCH 21/29] README: Add section for "execute" command --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 7fc4957d..fd9624fa 100644 --- a/README.md +++ b/README.md @@ -441,6 +441,24 @@ repositories for different templates currently in use. Additional features ------------------- +## Execute a custom script on each module + +During puppet modules maintenance, you may want to run a custom script to modify, add or deleted files then commit modifications. + +As example, if you want to generate REFERENCES.md, CHANGELOG.md or update your module to be PDK compliant, this command could be useful. + +```shell +msync exec /path/to/script --branch my-new-feature +``` + +**Important**: Please note that it is up to your script to modify correctly the repository (e.g. `git mv old-path new-path`, `git add my-file`) and performs the commits (ie. `git commit -m'Set a smart commit message here'`). + +Like `update` command, you can push and submit a PR/MR using the same options: + +```shell +msync exec /path/to/script --branch my-new-feature --push --pr --pr-title "Add a new super feature" +``` + ## Push manually a branch for each module After a regular `msync update` without push, you may want to add some commits manually then push. From 5942b00593191d005a5f2f947b195761a212a2fe Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 16 Dec 2020 12:48:06 +0100 Subject: [PATCH 22/29] CLI: Add reset-hard option to "update" command --- lib/modulesync.rb | 1 + lib/modulesync/cli.rb | 2 ++ 2 files changed, 3 insertions(+) diff --git a/lib/modulesync.rb b/lib/modulesync.rb index 29e6809b..1746925e 100644 --- a/lib/modulesync.rb +++ b/lib/modulesync.rb @@ -118,6 +118,7 @@ def self.manage_module(puppet_module, module_files, module_options, defaults, op git_options = { override_changes: true, remote: module_options[:remote], + reset_hard: options[:reset_hard], } Git.pull(options[:git_base], git_repo, options[:branch], options[:project_root], git_options) end diff --git a/lib/modulesync/cli.rb b/lib/modulesync/cli.rb index f6532759..64a50895 100644 --- a/lib/modulesync/cli.rb +++ b/lib/modulesync/cli.rb @@ -85,6 +85,8 @@ class Base < Thor # rubocop:disable Metrics/ClassLength :type => :boolean, :desc => 'Force push amended commit', :default => false + option :reset_hard, + :desc => 'Hard-reset on specified branch (e.g. origin/master) before updating modules' option :noop, :type => :boolean, :desc => 'No-op mode', From 647d9bda80ab83f3a07a6952606a0a12b9ce99ad Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 17 Dec 2020 21:40:08 +0100 Subject: [PATCH 23/29] Tests: Add minimal behaviour tests for "execute" command --- features/execute.feature | 25 +++++++++++++++++++ features/step_definitions/git_steps.rb | 10 ++++++++ .../faker/puppet_module_remote_repo.rb | 18 ++++++++++++- 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 features/execute.feature diff --git a/features/execute.feature b/features/execute.feature new file mode 100644 index 00000000..51cb7738 --- /dev/null +++ b/features/execute.feature @@ -0,0 +1,25 @@ +Feature: execute + Use ModuleSync to execute a custom script on a specified branch for each repos and optionaly push and submit a PR/MR + + Scenario: Running command without required 'branch' option + When I run `msync exec` + Then the output should match /^No value provided for required options '--branch'$/ + + Scenario: Cloning modules before running command when modules/ dir is empty + Given a basic setup with a puppet module "puppet-test" from "awesome" + Then the file "modules/awesome/puppet-test/metadata.json" should not exist + When I run `msync exec -b master /bin/true` + Then the exit status should be 0 + And the file "modules/awesome/puppet-test/metadata.json" should exist + + @no-clobber + Scenario: Hard-reset on specified branch before running command when modules have already been cloned + Given the file "modules/awesome/puppet-test/metadata.json" should exist + And the file "modules/awesome/puppet-test/hello" should not exist + And the puppet module "puppet-test" from "awesome" have a branch "execute" + And the puppet module "puppet-test" from "awesome" have a file named "hello" on branch "execute" with: + """ + Hello + """ + When I run `msync exec -b master --reset-hard origin/execute /bin/true` + And the file "modules/awesome/puppet-test/hello" should exist diff --git a/features/step_definitions/git_steps.rb b/features/step_definitions/git_steps.rb index 68cd614c..c860eff5 100644 --- a/features/step_definitions/git_steps.rb +++ b/features/step_definitions/git_steps.rb @@ -64,6 +64,11 @@ pmrr.add_file(filename, content) end +Given 'the puppet module {string} from {string} have a file named {string} on branch {string} with:' do |name, namespace, filename, branch, content| + pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace) + pmrr.add_file(filename, content, branch) +end + Then 'the puppet module {string} from {string} should have a branch {string} with a file named {string} which contains:' do |name, namespace, branch, filename, content| pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace) expect(pmrr.read_file(filename, branch)).to include(content) @@ -73,3 +78,8 @@ pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace) pmrr.default_branch = default_branch end + +Given 'the puppet module {string} from {string} have a branch {string}' do |name, namespace, branch| + pmrr = Faker::PuppetModuleRemoteRepo.new(name, namespace) + pmrr.create_branch(branch) +end diff --git a/spec/helpers/faker/puppet_module_remote_repo.rb b/spec/helpers/faker/puppet_module_remote_repo.rb index 7cb8e092..d8e58b2f 100644 --- a/spec/helpers/faker/puppet_module_remote_repo.rb +++ b/spec/helpers/faker/puppet_module_remote_repo.rb @@ -55,10 +55,18 @@ def default_branch=(value) end end + def default_branch + FileUtils.chdir(bare_repo_dir) do + stdout = run "git symbolic-ref --short HEAD" + return stdout.chomp + end + end + def read_file(filename, branch = nil) + branch ||= default_branch FileUtils.chdir(tmp_repo_dir) do run "git fetch" - run "git checkout #{branch}" unless branch.nil? + run "git checkout #{branch}" run "git merge --ff-only" return unless File.exists?(filename) @@ -66,6 +74,14 @@ def read_file(filename, branch = nil) end end + def create_branch(branch, from = nil) + from ||= default_branch + FileUtils.chdir(tmp_repo_dir) do + run "git checkout -B #{branch} #{from}" + run "git push --set-upstream origin #{branch}" + end + end + def add_file(filename, content, branch = nil) FileUtils.chdir(tmp_repo_dir) do run "git checkout #{branch}" unless branch.nil? From e5f7d6f1ed1af6698b3adc628f4ffca440cc7644 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Sun, 20 Dec 2020 15:23:57 +0100 Subject: [PATCH 24/29] RENAME to compute_module_naming_attributes BEFORE execute --- lib/modulesync.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/modulesync.rb b/lib/modulesync.rb index 1746925e..28797797 100644 --- a/lib/modulesync.rb +++ b/lib/modulesync.rb @@ -65,7 +65,7 @@ def self.managed_modules(config_file, filter, negative_filter) managed_modules end - def self.module_name(module_name, default_namespace) + def self.compute_module_naming_attributes(module_name, default_namespace) return [default_namespace, module_name] unless module_name.include?('/') ns, mod = module_name.split('/') end @@ -112,7 +112,7 @@ def self.manage_module(puppet_module, module_files, module_options, defaults, op if module_options.is_a?(Hash) && module_options.key?(:namespace) default_namespace = module_options[:namespace] end - namespace, module_name = module_name(puppet_module, default_namespace) + namespace, module_name = compute_module_naming_attributes(puppet_module, default_namespace) git_repo = File.join(namespace, module_name) unless options[:offline] git_options = { From f0bdbdb533b90d3d050d64ec90bf700ad4ccb827 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Sun, 20 Dec 2020 15:24:33 +0100 Subject: [PATCH 25/29] RENAME to compute_module_naming_attributes for PUSH --- lib/modulesync.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modulesync.rb b/lib/modulesync.rb index 28797797..a06b3cee 100644 --- a/lib/modulesync.rb +++ b/lib/modulesync.rb @@ -174,7 +174,7 @@ def self.update(cli_options) def self.push(cli_options) job = lambda { |puppet_module, module_options, _defaults, options| default_namespace = module_options[:namespace] || options[:namespace] - namespace, module_name = module_name(puppet_module, default_namespace) + namespace, module_name = compute_module_naming_attributes(puppet_module, default_namespace) repo_dir = File.join(options[:project_root], namespace, module_name) begin From bf891b5b2ec0cfd3dad3a6a489e9f6d0415e3836 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Sun, 20 Dec 2020 15:24:41 +0100 Subject: [PATCH 26/29] RENAME to compute_module_naming_attributes for EXECUTE --- lib/modulesync.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modulesync.rb b/lib/modulesync.rb index a06b3cee..1475e1a1 100644 --- a/lib/modulesync.rb +++ b/lib/modulesync.rb @@ -193,7 +193,7 @@ def self.push(cli_options) def self.execute(cli_options) job = lambda { |puppet_module, module_options, _defaults, options| default_namespace = module_options[:namespace] || options[:namespace] - namespace, module_name = module_name(puppet_module, default_namespace) + namespace, module_name = compute_module_naming_attributes(puppet_module, default_namespace) module_fullname = File.join(namespace, module_name) repo_dir = File.join(options[:project_root], module_fullname) From 19fa8bf2aef72b0e37dae10dcdda928663579a7d Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Sun, 20 Dec 2020 16:01:24 +0100 Subject: [PATCH 27/29] REWORK compute_naming_attrs --- lib/modulesync.rb | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/lib/modulesync.rb b/lib/modulesync.rb index 1475e1a1..717e6369 100644 --- a/lib/modulesync.rb +++ b/lib/modulesync.rb @@ -65,9 +65,17 @@ def self.managed_modules(config_file, filter, negative_filter) managed_modules end - def self.compute_module_naming_attributes(module_name, default_namespace) - return [default_namespace, module_name] unless module_name.include?('/') - ns, mod = module_name.split('/') + def self.compute_module_naming_attributes(module_name, options, module_options) + namespace = module_options[:namespace] || options[:namespace] + name = module_name + namespace, name = module_name.split('/') if module_name.include?('/') + fullname = "#{namespace}/#{name}" + + { + name: name, + namespace: namespace, + fullname: fullname, + } end def self.hook(options) @@ -108,12 +116,8 @@ def self.manage_file(filename, settings, options) end def self.manage_module(puppet_module, module_files, module_options, defaults, options) - default_namespace = options[:namespace] - if module_options.is_a?(Hash) && module_options.key?(:namespace) - default_namespace = module_options[:namespace] - end - namespace, module_name = compute_module_naming_attributes(puppet_module, default_namespace) - git_repo = File.join(namespace, module_name) + git_repo = module_options[:fullname] + unless options[:offline] git_options = { override_changes: true, @@ -123,16 +127,17 @@ def self.manage_module(puppet_module, module_files, module_options, defaults, op Git.pull(options[:git_base], git_repo, options[:branch], options[:project_root], git_options) end - module_configs = Util.parse_config(module_file(options[:project_root], namespace, module_name, MODULE_CONF_FILE)) + module_configs = Util.parse_config(module_file(options[:project_root], module_options[:namespace], module_options[:name], MODULE_CONF_FILE)) settings = Settings.new(defaults[GLOBAL_DEFAULTS_KEY] || {}, defaults, module_configs[GLOBAL_DEFAULTS_KEY] || {}, module_configs, - :puppet_module => module_name, + :puppet_module => module_options[:name], :git_base => options[:git_base], - :namespace => namespace) + :namespace => module_options[:namespace]) + settings.unmanaged_files(module_files).each do |filename| - $stdout.puts "Not managing #{filename} in #{module_name}" + $stdout.puts "Not managing #{filename} in #{module_options[:name]}" end files_to_manage = settings.managed_files(module_files) @@ -140,10 +145,10 @@ def self.manage_module(puppet_module, module_files, module_options, defaults, op if options[:noop] Git.update_noop(git_repo, options) - options[:pr] && pr(module_options).manage(namespace, module_name, options) + options[:pr] && pr(module_options).manage(module_options[:namespace], module_options[:name], options) elsif !options[:offline] pushed = Git.update(git_repo, files_to_manage, options) - pushed && options[:pr] && pr(module_options).manage(namespace, module_name, options) + pushed && options[:pr] && pr(module_options).manage(module_options[:namespace], module_options[:name], options) end end @@ -240,6 +245,8 @@ def self.run(options, job, prepare = nil) managed_modules.each do |puppet_module, module_options| module_options ||= {} module_options = Util.symbolize_keys(module_options) + module_options.merge! compute_module_naming_attributes(puppet_module, options, module_options) + begin job.call(puppet_module, module_options, defaults, options) rescue StandardError => e From c81b340189a76f68c7991465546f586ca4d475b9 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Sun, 20 Dec 2020 16:02:59 +0100 Subject: [PATCH 28/29] compute_naming_attrs for push --- lib/modulesync.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/modulesync.rb b/lib/modulesync.rb index 717e6369..6d31d9c2 100644 --- a/lib/modulesync.rb +++ b/lib/modulesync.rb @@ -178,9 +178,7 @@ def self.update(cli_options) def self.push(cli_options) job = lambda { |puppet_module, module_options, _defaults, options| - default_namespace = module_options[:namespace] || options[:namespace] - namespace, module_name = compute_module_naming_attributes(puppet_module, default_namespace) - repo_dir = File.join(options[:project_root], namespace, module_name) + repo_dir = File.join(options[:project_root], module_options[:fullname]) begin repo = ::Git.open repo_dir @@ -189,7 +187,7 @@ def self.push(cli_options) raise ModuleSync::Error, 'Repository must be locally available before trying to push' end Git.push(repo, options) - options[:pr] && pr(module_options).manage(namespace, module_name, options) + options[:pr] && pr(module_options).manage(module_options[:namespace], module_options[:name], options) } run(cli_options, job) From e3714a9a47377f61ca2cd3b518de4621c26dfe35 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Sun, 20 Dec 2020 16:03:06 +0100 Subject: [PATCH 29/29] compute_naming_attrs for execute --- lib/modulesync.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/modulesync.rb b/lib/modulesync.rb index 6d31d9c2..e1e10a21 100644 --- a/lib/modulesync.rb +++ b/lib/modulesync.rb @@ -195,24 +195,20 @@ def self.push(cli_options) def self.execute(cli_options) job = lambda { |puppet_module, module_options, _defaults, options| - default_namespace = module_options[:namespace] || options[:namespace] - namespace, module_name = compute_module_naming_attributes(puppet_module, default_namespace) - - module_fullname = File.join(namespace, module_name) - repo_dir = File.join(options[:project_root], module_fullname) + repo_dir = File.join(options[:project_root], module_options[:fullname]) git_options = { remote: module_options[:remote], reset_hard: options[:reset_hard], } - repo = Git.pull(options[:git_base], module_fullname, options[:branch], options[:project_root], git_options) + repo = Git.pull(options[:git_base], module_options[:fullname], options[:branch], options[:project_root], git_options) FileUtils.chdir(repo_dir) do result = system(options[:script]) raise "Error during script execution (#{$CHILD_STATUS})" unless result options[:push] && Git.push(repo, options) - options[:push] && options[:pr] && pr(module_options).manage(namespace, module_name, options) + options[:push] && options[:pr] && pr(module_options).manage(module_options[:namespace], module_options[:name], options) end }