Skip to content

Commit

Permalink
Merge pull request #202 from opus-codium/improve-tests
Browse files Browse the repository at this point in the history
Improve tests capabilities by using local/fake remote repositories
  • Loading branch information
bastelfreak authored Jan 15, 2021
2 parents 979c9e3 + 563deb3 commit 53c9a25
Show file tree
Hide file tree
Showing 9 changed files with 373 additions and 388 deletions.
1 change: 1 addition & 0 deletions .config/cucumber.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default: --publish-quiet
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Layout/IndentHeredoc:
# sane line length
Metrics/LineLength:
Max: 120
Exclude:
- 'features/**/*'

Style/FrozenStringLiteralComment:
Enabled: false
11 changes: 6 additions & 5 deletions features/cli.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ 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 "fakenamespace"
And a file named "managed_modules.yml" with:
"""
---
- puppet-test
"""
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 fakenamespace`
Then the exit status should be 0
And the output should not match /git@github.com:/
And the output should match /Syncing fakenamespace/
8 changes: 3 additions & 5 deletions features/hook.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
"""
99 changes: 63 additions & 36 deletions features/step_definitions/git_steps.rb
Original file line number Diff line number Diff line change
@@ -1,48 +1,75 @@
Given 'a mocked git configuration' do
steps %(
Given a mocked home directory
And I run `git config --global user.name Test`
And I run `git config --global user.email test@example.com`
)
end
require_relative '../../spec/helpers/faker/puppet_module_remote_repo'

Given 'a remote module repository' do
Given 'a basic setup with a puppet module {string} from {string}' do |name, namespace|
steps %(
Given a directory named "sources"
And I run `git clone https://github.com/maestrodev/puppet-test sources/puppet-test`
Given a mocked git configuration
And a puppet module "#{name}" from "#{namespace}"
And a file named "managed_modules.yml" with:
"""
---
- puppet-test
- #{name}
"""
And a file named "modulesync.yml" with:
"""
---
namespace: #{namespace}
"""
And a git_base option appended to "modulesync.yml" for local tests
)
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|
Given 'a mocked git configuration' do
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
"""
Given a mocked home directory
And I run `git config --global user.name Aruba`
And I run `git config --global user.email aruba@example.com`
)
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

Given 'a puppet module {string} from {string}' do |name, namespace|
pmrr = ModuleSync::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: #{ModuleSync::Faker::PuppetModuleRemoteRepo.git_base}", mode: 'a'
end

Given 'the puppet module {string} from {string} is read-only' do |name, namespace|
pmrr = ModuleSync::Faker::PuppetModuleRemoteRepo.new(name, namespace)
pmrr.read_only = true
end

Then 'the puppet module {string} from {string} should have no commits between {string} and {string}' do |name, namespace, commit1, commit2|
pmrr = ModuleSync::Faker::PuppetModuleRemoteRepo.new(name, namespace)
expect(pmrr.commit_count_between(commit1, commit2)).to eq 0
end

Then 'the puppet module {string} from {string} should have( only) {int} commit(s) made by {string}' do |name, namespace, commit_count, author|
pmrr = ModuleSync::Faker::PuppetModuleRemoteRepo.new(name, namespace)
expect(pmrr.commit_count_by(author)).to eq commit_count
end

Then 'the puppet module {string} from {string} should have( only) {int} commit(s) made by {string} in branch {string}' do |name, namespace, commit_count, author, branch|
pmrr = ModuleSync::Faker::PuppetModuleRemoteRepo.new(name, namespace)
expect(pmrr.commit_count_by(author, branch)).to eq commit_count
end

Then 'the puppet module {string} from {string} should have no commits made by {string}' do |name, namespace, author|
step "the puppet module \"#{name}\" from \"#{namespace}\" should have 0 commits made by \"#{author}\""
end

Given 'the puppet module {string} from {string} has a file named {string} with:' do |name, namespace, filename, content|
pmrr = ModuleSync::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 = ModuleSync::Faker::PuppetModuleRemoteRepo.new(name, namespace)
expect(pmrr.read_file(filename, branch)).to include(content)
end

Given 'the puppet module {string} from {string} has the default branch named {string}' do |name, namespace, default_branch|
pmrr = ModuleSync::Faker::PuppetModuleRemoteRepo.new(name, namespace)
pmrr.default_branch = default_branch
end
4 changes: 4 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
require 'aruba/cucumber'

require_relative '../../spec/helpers/faker'

ModuleSync::Faker.working_directory = File.expand_path('faker', Aruba.config.working_directory)

Before do
@aruba_timeout_seconds = 5
end
Loading

0 comments on commit 53c9a25

Please sign in to comment.