pdksync 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +26 -15
- data/.travis.yml +17 -16
- data/CHANGELOG.md +23 -0
- data/CODEOWNERS +2 -0
- data/Gemfile +6 -2
- data/README.md +295 -17
- data/Rakefile +14 -8
- data/lib/pdksync.rb +310 -449
- data/lib/pdksync/conf/puppet_abs_supported_platforms.yaml +41 -0
- data/lib/pdksync/configuration.rb +155 -0
- data/lib/pdksync/githubclient.rb +3 -1
- data/lib/pdksync/gitplatformclient.rb +2 -2
- data/lib/pdksync/jenkinsclient.rb +50 -0
- data/lib/pdksync/logger.rb +116 -0
- data/lib/pdksync/rake_tasks.rb +99 -15
- data/lib/pdksync/utils.rb +1293 -0
- data/managed_modules.yml +21 -26
- data/pdksync.gemspec +18 -15
- data/spec/configuration_spec.rb +56 -0
- data/spec/fixtures/fake_managed_modules.yaml +2 -0
- data/spec/fixtures/pdksync.yml +2 -0
- data/spec/logger_spec.rb +44 -0
- data/spec/pdksync_spec.rb +185 -0
- data/spec/spec_helper.rb +74 -0
- data/spec/utils_spec.rb +131 -0
- metadata +94 -21
- data/lib/pdksync/constants.rb +0 -78
- data/spec/lib/pdksync_spec.rb +0 -58
data/managed_modules.yml
CHANGED
@@ -1,56 +1,51 @@
|
|
1
1
|
---
|
2
|
-
##
|
3
|
-
#-
|
4
|
-
#-
|
5
|
-
#-
|
6
|
-
#- puppetlabs-dsc_lite
|
7
|
-
#- puppetlabs-iis
|
8
|
-
#- puppetlabs-powershell
|
9
|
-
#- puppetlabs-registry
|
10
|
-
#- puppetlabs-reboot
|
11
|
-
#- puppetlabs-scheduled_task
|
12
|
-
#- puppetlabs-sqlserver
|
13
|
-
#- puppetlabs-windows
|
14
|
-
#- puppetlabs-wsus_client
|
15
|
-
## modules team
|
2
|
+
## IA content team
|
3
|
+
#- cisco_ios
|
4
|
+
#- device_manager
|
5
|
+
#- provision
|
16
6
|
#- puppetlabs-accounts
|
7
|
+
#- puppetlabs-acl
|
17
8
|
#- puppetlabs-apache
|
18
9
|
#- puppetlabs-apt
|
19
|
-
#- puppetlabs-
|
10
|
+
#- puppetlabs-chocolatey
|
20
11
|
#- puppetlabs-concat
|
12
|
+
#- puppetlabs-docker
|
13
|
+
#- puppetlabs-dsc
|
14
|
+
#- puppetlabs-dsc_lite
|
21
15
|
#- puppetlabs-exec
|
22
16
|
#- puppetlabs-facter_task
|
23
17
|
#- puppetlabs-firewall
|
24
18
|
#- puppetlabs-haproxy
|
19
|
+
#- puppetlabs-helm
|
25
20
|
#- puppetlabs-ibm_installation_manager
|
21
|
+
#- puppetlabs-iis
|
26
22
|
#- puppetlabs-inifile
|
27
23
|
#- puppetlabs-java
|
28
24
|
#- puppetlabs-java_ks
|
25
|
+
#- puppetlabs-kubernetes
|
29
26
|
#- puppetlabs-motd
|
30
27
|
#- puppetlabs-mysql
|
31
28
|
#- puppetlabs-ntp
|
32
29
|
#- puppetlabs-package
|
30
|
+
#- puppetlabs-panos
|
33
31
|
#- puppetlabs-postgresql
|
32
|
+
#- puppetlabs-powershell
|
34
33
|
#- puppetlabs-puppet_conf
|
35
|
-
#- puppetlabs-
|
34
|
+
#- puppetlabs-reboot
|
35
|
+
#- puppetlabs-registry
|
36
|
+
#- puppetlabs-rook
|
36
37
|
#- puppetlabs-satellite_pe_tools
|
38
|
+
#- puppetlabs-scheduled_task
|
37
39
|
#- puppetlabs-service
|
40
|
+
#- puppetlabs-sqlserver
|
38
41
|
#- puppetlabs-stdlib
|
39
42
|
#- puppetlabs-tagmail
|
40
43
|
#- puppetlabs-tomcat
|
41
|
-
#- puppetlabs-translate
|
42
44
|
#- puppetlabs-vcsrepo
|
45
|
+
#- puppetlabs-vsphere
|
43
46
|
#- puppetlabs-websphere_application_server
|
44
|
-
|
45
|
-
#- cisco_ios
|
46
|
-
#- device_manager
|
47
|
-
#- puppetlabs-panos
|
48
|
-
#- puppetlabs-resource_api
|
47
|
+
#- puppetlabs-wsus_client
|
49
48
|
## testing only
|
50
49
|
#- puppetlabs-testing
|
51
50
|
#- puppetlabs-testing1
|
52
51
|
#- puppetlabs-testing2
|
53
|
-
## cloud and containers team
|
54
|
-
#- puppetlabs-kubernetes
|
55
|
-
#- puppetlabs-helm
|
56
|
-
#- puppetlabs-rook
|
data/pdksync.gemspec
CHANGED
@@ -2,30 +2,33 @@ lib = File.expand_path('../lib', __FILE__)
|
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
|
-
spec.name
|
6
|
-
spec.version
|
7
|
-
spec.authors
|
8
|
-
spec.email
|
9
|
-
spec.summary
|
10
|
-
spec.description
|
11
|
-
spec.homepage
|
12
|
-
spec.license
|
5
|
+
spec.name = 'pdksync'
|
6
|
+
spec.version = '0.6.0'
|
7
|
+
spec.authors = ['Puppet']
|
8
|
+
spec.email = ['']
|
9
|
+
spec.summary = 'Puppet Module PDK Synchronizer'
|
10
|
+
spec.description = 'Utility to synchronize common files across puppet modules using PDK Update.'
|
11
|
+
spec.homepage = 'http://github.com/puppetlabs/pdksync'
|
12
|
+
spec.license = 'Apache-2.0'
|
13
13
|
spec.required_ruby_version = '>= 2.0.0'
|
14
14
|
|
15
|
-
spec.files
|
16
|
-
spec.executables
|
17
|
-
spec.test_files
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ['lib']
|
19
19
|
|
20
|
-
spec.add_development_dependency 'bundler'
|
20
|
+
spec.add_development_dependency 'bundler'
|
21
|
+
spec.add_development_dependency 'codecov'
|
22
|
+
spec.add_development_dependency 'pry'
|
21
23
|
spec.add_development_dependency 'rspec'
|
22
24
|
spec.add_development_dependency 'rubocop', '~> 0.50.0'
|
23
|
-
spec.add_development_dependency '
|
24
|
-
|
25
|
+
spec.add_development_dependency 'simplecov'
|
26
|
+
spec.add_development_dependency 'simplecov-console'
|
27
|
+
spec.add_runtime_dependency 'pdk', '>= 1.14.1'
|
25
28
|
spec.add_runtime_dependency 'git', '~>1.3'
|
26
|
-
spec.add_runtime_dependency 'pdk', '>= 1.4.1'
|
27
29
|
spec.add_runtime_dependency 'rake'
|
28
30
|
spec.add_runtime_dependency 'gitlab'
|
29
31
|
spec.add_runtime_dependency 'octokit'
|
30
32
|
spec.add_runtime_dependency 'colorize'
|
33
|
+
spec.add_runtime_dependency 'jenkins_api_client'
|
31
34
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pdksync/configuration'
|
3
|
+
|
4
|
+
RSpec.describe 'configuration' do
|
5
|
+
before(:each) do
|
6
|
+
allow(ENV).to receive(:[]).with('HOME').and_return('./')
|
7
|
+
allow(ENV).to receive(:[]).with('GITHUB_TOKEN').and_return('blah')
|
8
|
+
allow(ENV).to receive(:[]).with('PDKSYNC_CONFIG_PATH').and_return(nil)
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:instance) do
|
12
|
+
PdkSync::Configuration.new
|
13
|
+
end
|
14
|
+
|
15
|
+
it '#new' do
|
16
|
+
expect(instance).to be_a PdkSync::Configuration
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'passes when token is provided' do
|
20
|
+
expect(instance).to be_a PdkSync::Configuration
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'raises error without token' do
|
24
|
+
allow(ENV).to receive(:[]).with('GITHUB_TOKEN').and_return(nil)
|
25
|
+
expect { instance }.to raise_error(ArgumentError)
|
26
|
+
end
|
27
|
+
|
28
|
+
it '#custom_config' do
|
29
|
+
expect(instance.custom_config).to be_a Hash
|
30
|
+
end
|
31
|
+
|
32
|
+
it '#custom_config does not exist' do
|
33
|
+
expect(instance.custom_config('/tmp/blah')).to be_a Hash
|
34
|
+
end
|
35
|
+
|
36
|
+
it '#custom_config exists' do
|
37
|
+
config = File.join(fixtures_dir, 'pdksync.yml')
|
38
|
+
data = instance.custom_config(config)
|
39
|
+
expect(data).to be_a Hash
|
40
|
+
expect(data[:namespace]).to eq('voxpupuli')
|
41
|
+
end
|
42
|
+
|
43
|
+
it '#locate_config_path' do
|
44
|
+
expect(instance.local_config_path).to be_nil
|
45
|
+
end
|
46
|
+
|
47
|
+
it '#locate_config_path with value' do
|
48
|
+
config = File.join(fixtures_dir, 'pdksync.yml')
|
49
|
+
expect(instance.locate_config_path(config)).to eq(config)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'gets a different config file path when variable is used' do
|
53
|
+
allow(ENV).to receive(:[]).with('PDKSYNC_CONFIG_PATH').and_return(File.join(fixtures_dir, 'pdksync.yml'))
|
54
|
+
expect(instance.locate_config_path(ENV['PDKSYNC_CONFIG_PATH'])).to eq(File.join(fixtures_dir, 'pdksync.yml'))
|
55
|
+
end
|
56
|
+
end
|
data/spec/logger_spec.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pdksync/logger'
|
3
|
+
|
4
|
+
RSpec.describe 'logger' do
|
5
|
+
before(:each) do
|
6
|
+
allow(ENV).to receive(:[]).with('PDKSYNC_LOG_FILENAME').and_return('dev/')
|
7
|
+
allow(ENV).to receive(:[]).with('LOG_LEVEL').and_return(nil)
|
8
|
+
# allow(PdkSync::Logger).to receive(:logger).and_return(PdkSync::Logger.logger($stderr))
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:logger) do
|
12
|
+
PdkSync::Logger.instance_variable_set('@logger', nil)
|
13
|
+
PdkSync::Logger.logger
|
14
|
+
end
|
15
|
+
|
16
|
+
it '#self.logger' do
|
17
|
+
expect(PdkSync::Logger.logger).to be_a Logger
|
18
|
+
end
|
19
|
+
|
20
|
+
it '#self.debug' do
|
21
|
+
allow(ENV).to receive(:[]).with('LOG_LEVEL').and_return('debug')
|
22
|
+
expect(logger.debug('this is a debug')).to be_truthy
|
23
|
+
# wasn't able to capture stdout with rspec, no idea why
|
24
|
+
# expect { logger.debug("this is a debug") }.to output(/DEBUG - PdkSync: this is a debug/).to_stdout
|
25
|
+
end
|
26
|
+
|
27
|
+
it '#self.warn' do
|
28
|
+
allow(ENV).to receive(:[]).with('LOG_LEVEL').and_return('warn')
|
29
|
+
# wasn't able to capture stdout with rspec, no idea why
|
30
|
+
expect(logger.warn('this is a warning')).to be_truthy # output(/WARN - PdkSync: this is a warning/).to_stdout
|
31
|
+
end
|
32
|
+
|
33
|
+
it '#self.info' do
|
34
|
+
allow(ENV).to receive(:[]).with('LOG_LEVEL').and_return('info')
|
35
|
+
# wasn't able to capture stdout with rspec, no idea why
|
36
|
+
expect(logger.info('this is a info')).to be_truthy # output(/INFO - PdkSync: this is a info/).to_stderr
|
37
|
+
end
|
38
|
+
|
39
|
+
it '#self.fatal' do
|
40
|
+
allow(ENV).to receive(:[]).with('LOG_LEVEL').and_return('error')
|
41
|
+
# wasn't able to capture stdout with rspec, no idea why
|
42
|
+
expect(logger.fatal('this is a fatal')).to be_truthy # output(/FATAL - PdkSync: this is a fatal/).to_stderr
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
require 'pdksync'
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'git'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'octokit'
|
6
|
+
|
7
|
+
describe PdkSync do
|
8
|
+
before(:all) do
|
9
|
+
@pdksync_dir = './modules_pdksync'
|
10
|
+
@pdksync_gem_dir = './gems_pdksync'
|
11
|
+
module_name = 'puppetlabs-testing'
|
12
|
+
gem_name = 'puppet-module-gems'
|
13
|
+
@module_names = ['puppetlabs-testing']
|
14
|
+
@output_path_module = "#{@pdksync_dir}/#{module_name}"
|
15
|
+
@output_path_gem = "#{@pdksync_gem_dir}/#{gem_name}"
|
16
|
+
@folder = Dir.pwd
|
17
|
+
# Make changes to modules_managed.yaml file
|
18
|
+
text = File.read('managed_modules.yml')
|
19
|
+
new_contents = text.gsub(%r{#- puppetlabs-testing$}, '- puppetlabs-testing')
|
20
|
+
File.open('managed_modules.yml', 'w') { |file| file.puts new_contents }
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:platform) { Object.new }
|
24
|
+
|
25
|
+
before(:each) do
|
26
|
+
allow(ENV).to receive(:[]).with('HOME').and_return('./')
|
27
|
+
allow(ENV).to receive(:[]).with('GIT_DIR').and_return(nil)
|
28
|
+
allow(ENV).to receive(:[]).with('GIT_WORK_TREE').and_return(nil)
|
29
|
+
allow(ENV).to receive(:[]).with('GIT_INDEX_FILE').and_return(nil)
|
30
|
+
allow(ENV).to receive(:[]).with('PDKSYNC_LOG_FILENAME').and_return(nil)
|
31
|
+
allow(ENV).to receive(:[]).with('LOG_LEVEL').and_return(nil)
|
32
|
+
allow(ENV).to receive(:[]).with('GIT_SSH').and_return(nil)
|
33
|
+
allow(ENV).to receive(:[]).with('GIT_PATH').and_return(nil)
|
34
|
+
allow(ENV).to receive(:[]).with('GITHUB_TOKEN').and_return('blah')
|
35
|
+
allow(ENV).to receive(:[]).with('GEMFURY_TOKEN').and_return('blah')
|
36
|
+
allow(ENV).to receive(:[]).with('PDKSYNC_VERSION_CHECK').and_return(nil)
|
37
|
+
allow(ENV).to receive(:[]).with('http_proxy').and_return(nil)
|
38
|
+
allow(ENV).to receive(:[]).with('HTTP_PROXY').and_return(nil)
|
39
|
+
allow(ENV).to receive(:[]).with('PDKSYNC_CONFIG_PATH').and_return(nil)
|
40
|
+
allow(ENV).to receive(:[]).with('TERM').and_return(nil)
|
41
|
+
allow(ENV).to receive(:[]).with('NO_COLOR').and_return(nil)
|
42
|
+
allow(PdkSync::Utils).to receive(:return_modules).and_return(@module_names)
|
43
|
+
allow(PdkSync::Utils).to receive(:validate_modules_exist).and_return(@module_names)
|
44
|
+
allow(PdkSync::Utils).to receive(:setup_client).and_return(git_client)
|
45
|
+
Dir.chdir(@folder)
|
46
|
+
allow(PdkSync::GitPlatformClient).to receive(:new).and_return(platform)
|
47
|
+
allow(Octokit).to receive(:tags).with('puppetlabs/pdk').and_return([{ name: '1' }])
|
48
|
+
allow(PdkSync::Utils.configuration).to receive(:git_base_uri).and_return('https://github.com')
|
49
|
+
end
|
50
|
+
|
51
|
+
let(:git_client) do
|
52
|
+
double(PdkSync::GitPlatformClient)
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'main method' do
|
56
|
+
it 'runs clone sucessfully' do
|
57
|
+
allow(PdkSync::Utils).to receive(:setup_client).and_return(git_client)
|
58
|
+
FileUtils.rm_rf(@pdksync_dir)
|
59
|
+
PdkSync::Utils.create_filespace
|
60
|
+
PdkSync.main(steps: [:clone])
|
61
|
+
expect(Dir.exist?(@pdksync_dir)).to be(true)
|
62
|
+
expect(Dir.exist?(@output_path_module)).to be(true)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'runs pdk convert, and files have changed' do
|
66
|
+
PdkSync.main(steps: [:pdk_convert])
|
67
|
+
File.exist?("#{@output_path_module}/convert_report.txt")
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'raise when running a command with no argument' do
|
71
|
+
expect { PdkSync.main(steps: [:run_a_command]) }.to raise_error(RuntimeError, %r{"run_a_command" requires an argument to run.})
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'runs a command "touch cat.meow"' do
|
75
|
+
PdkSync.main(steps: [:run_a_command], args: { command: 'touch cat.meow' })
|
76
|
+
expect File.exist?("#{@output_path_module}/cat.meow")
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'raise when create_commit with no arguments' do
|
80
|
+
expect { PdkSync.main(steps: [:create_commit]) }.to raise_error(RuntimeError, %r{Needs a branch_name and commit_message})
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'raise when create_pr with no arguments' do
|
84
|
+
expect { PdkSync.main(steps: [:create_pr]) }.to raise_error(RuntimeError, %r{Needs a pr_title})
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'create_pr with 1 argument' do
|
88
|
+
expect { PdkSync.main(steps: [:create_pr], args: { pr_title: 'some title' }) }.to_not raise_error
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'raise when clean_branches with no arguments' do
|
92
|
+
expect { PdkSync.main(steps: [:clean_branches]) }.to raise_error(RuntimeError, %r{Needs a branch_name, and the branch name contains the string pdksync})
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'raise when gem_file_update with no arguments' do
|
96
|
+
expect { PdkSync.main(steps: [:gem_file_update]) }.to raise_error(NoMethodError)
|
97
|
+
end
|
98
|
+
it 'gem_file_update runs with invalid gem_line given' do
|
99
|
+
expect { PdkSync.main(steps: [:gem_file_update], args: { gem_to_test: 'puppet_litmus', gem_line: "gem 'puppet_litmus'\, git: 'https://github.com/test/puppet_litmus.git'" }) }. to raise_error(Errno::ENOENT) # rubocop:disable Metrics/LineLength
|
100
|
+
end
|
101
|
+
it 'gem_file_update runs with invalid gem_sha_replacer' do
|
102
|
+
expect { PdkSync.main(steps: [:gem_file_update], args: { gem_to_test: 'puppet_litmus', gem_sha_finder: 'jsjsjsjsjsjsjs', gem_sha_replacer: 'abcdefgjhkk' }) }.to raise_error(RuntimeError) # , ("Couldn't find sha: abcdefgjhkk in your repository: puppet_litmus")) # rubocop:disable Metrics/LineLength
|
103
|
+
end
|
104
|
+
it 'gem_file_update runs with invalid gem_version_replacer' do
|
105
|
+
expect { PdkSync.main(steps: [:gem_file_update], args: { gem_to_test: 'puppet_litmus', gem_version_finder: '<= 0.4.9', gem_version_replacer: '<= 1.4.11' }) }.to raise_error(RuntimeError) # , ("Couldn't find version: 1.4.11 in your repository: puppet_litmus")) # rubocop:disable Metrics/LineLength
|
106
|
+
end
|
107
|
+
it 'gem_file_update runs with invalid gem_branch_replacer' do
|
108
|
+
expect { PdkSync.main(steps: [:gem_file_update], args: { gem_to_test: 'puppet_litmus', gem_branch_finder: 'jsjsjsjsjsjsjs', gem_branch_replacer: 'abcdefgjhkk' }) }.to raise_error(RuntimeError) # , "Couldn't find branch: abcdefgjhkk in your repository: puppet_litmus") # rubocop:disable Metrics/LineLength
|
109
|
+
end
|
110
|
+
it 'raise when run_tests with no arguments' do
|
111
|
+
expect { PdkSync.main(steps: [:run_tests_locally]) }.to raise_error(NoMethodError) # , %r{run_tests" requires arguments (module_type) to run.})
|
112
|
+
end
|
113
|
+
it 'raise when run_tests_jenkins with no arguments' do
|
114
|
+
allow(ENV).to receive(:[]).with('JENKINS_USERNAME').and_return('JENKINS_USERNAME')
|
115
|
+
allow(ENV).to receive(:[]).with('JENKINS_PASSWORD').and_return('JENKINS_PASSWORD')
|
116
|
+
expect { PdkSync.main(steps: [:run_tests_jenkins], args: {}) }.to raise_error(RuntimeError) # , "run_tests_jenkins requires arguments (github_repo, github_branch) to run"
|
117
|
+
end
|
118
|
+
it 'raise errors without jenkins credentials' do
|
119
|
+
allow(ENV).to receive(:[]).with('JENKINS_USERNAME').and_return(nil)
|
120
|
+
allow(ENV).to receive(:[]).with('JENKINS_PASSWORD').and_return(nil)
|
121
|
+
expect { PdkSync.main(steps: [:run_tests_jenkins], args: { jenkins_server_url: 'https//jenkins.com', github_repo: 'test', github_branch: 'test' }) }.to raise_error(RuntimeError, %r{Jenkins access token for Jenkins not set})
|
122
|
+
end
|
123
|
+
|
124
|
+
describe 'gem_file_update with valid values' do
|
125
|
+
before(:all) do
|
126
|
+
PdkSync.main(steps: [:gem_file_update], args: {
|
127
|
+
gem_to_test: 'puppet_litmus',
|
128
|
+
gem_line: "gem 'puppet_litmus'\, git: 'https://github.com/puppetlabs/puppet_litmus.git'\, branch: 'main'\, ref: '04da90638f5b5fd7f007123c8c0cc551c8cb3e54'\, '=0.1.0'"
|
129
|
+
})
|
130
|
+
end
|
131
|
+
it 'gem_file_update with valid gem_branch_replacer' do
|
132
|
+
PdkSync.main(steps: [:gem_file_update], args: { gem_to_test: 'puppet_litmus',
|
133
|
+
gem_branch_finder: 'master', gem_branch_replacer: 'main' })
|
134
|
+
expect(File.read('Gemfile')).to match(%r{main})
|
135
|
+
end
|
136
|
+
it 'gem_file_update runs, and contains the gem_sha given' do
|
137
|
+
PdkSync.main(steps: [:gem_file_update], args: { gem_to_test: 'puppet_litmus',
|
138
|
+
gem_sha_finder: '04da90638f5b5fd7f007123c8c0cc551c8cb3e54', gem_sha_replacer: '95ed1c62ffcf89003eb0fe9d66989caa45884538' })
|
139
|
+
expect(File.read('Gemfile')).to match(%r{95ed1c62ffcf89003eb0fe9d66989caa45884538})
|
140
|
+
end
|
141
|
+
it 'gem_file_update runs, and contains the gem_version given' do
|
142
|
+
PdkSync.main(steps: [:gem_file_update], args: { gem_to_test: 'puppet_litmus',
|
143
|
+
gem_version_finder: '=0.1.0', gem_version_replacer: '<=0.3.0' })
|
144
|
+
expect(File.read('Gemfile')).to match(%r{0.3.0})
|
145
|
+
end
|
146
|
+
it 'gem_file_update with valid gem_line' do
|
147
|
+
PdkSync.main(steps: [:gem_file_update], args: { gem_to_test: 'puppet_litmus',
|
148
|
+
gem_line: "gem 'puppet_litmus'\, git: 'https://github.com/puppetlabs/puppet_litmus.git'" })
|
149
|
+
expect(File.read('Gemfile')).to match(%r{gem 'puppet_litmus', git: 'https://github.com/puppetlabs/puppet_litmus.git'})
|
150
|
+
end
|
151
|
+
it 'multigem updated in the module gemfile' do
|
152
|
+
PdkSync.main(steps: [:multi_gemfile_update], args: { gem_name: 'puppet-module', gemfury_username: 'tester' })
|
153
|
+
expect File.exist?("#{@output_path_module}/Gemfile")
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
context 'main method' do
|
158
|
+
let(:platform) { Object.new }
|
159
|
+
|
160
|
+
it 'runs clone gem sucessfully' do
|
161
|
+
allow(PdkSync::Utils).to receive(:setup_client).and_return(git_client)
|
162
|
+
FileUtils.rm_rf(@pdksync_gem_dir)
|
163
|
+
PdkSync::Utils.create_filespace_gem
|
164
|
+
PdkSync.main(steps: [:clone_gem], args: { gem_name: 'puppet-module-gems' })
|
165
|
+
expect(Dir.exist?(@pdksync_dir)).to be(true)
|
166
|
+
expect(Dir.exist?(@pdksync_gem_dir)).to be(true)
|
167
|
+
expect(Dir.exist?(@output_path_gem)).to be(true)
|
168
|
+
end
|
169
|
+
it 'raise when running a command with no argument' do
|
170
|
+
expect { PdkSync.main(steps: [:multi_gem_testing]) }.to raise_error(RuntimeError, %r{"multi_gem_testing" requires arguments to run version_file and build_gem})
|
171
|
+
end
|
172
|
+
it 'runs a command for updating the version and building the gem' do
|
173
|
+
allow(Octokit).to receive(:tags).with('puppetlabs/puppet-module-gems').and_return([{ name: '1' }])
|
174
|
+
PdkSync.main(steps: [:multi_gem_testing], args: { gem_name: 'puppet-module-gems', version_file: 'config/info.yml', build_gem: 'exe/build-gems.rb', gem_path: 'pkg', gem_username: 'tester' })
|
175
|
+
expect File.exist?("#{@output_path_gem}/pkg")
|
176
|
+
end
|
177
|
+
end
|
178
|
+
after(:all) do
|
179
|
+
# Make changes to modules_managed.yaml file
|
180
|
+
Dir.chdir(@folder)
|
181
|
+
text = File.read('managed_modules.yml')
|
182
|
+
new_contents = text.gsub(%r{- puppetlabs-testing$}, '#- puppetlabs-testing')
|
183
|
+
File.open('managed_modules.yml', 'w') { |file| file.puts new_contents }
|
184
|
+
end
|
185
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
if ENV['SIMPLECOV'] == 'yes'
|
4
|
+
begin
|
5
|
+
require 'simplecov'
|
6
|
+
require 'simplecov-console'
|
7
|
+
require 'codecov'
|
8
|
+
|
9
|
+
SimpleCov.formatters = [
|
10
|
+
SimpleCov::Formatter::HTMLFormatter,
|
11
|
+
SimpleCov::Formatter::Console,
|
12
|
+
SimpleCov::Formatter::Codecov
|
13
|
+
]
|
14
|
+
SimpleCov.start do
|
15
|
+
track_files 'lib/**/*.rb'
|
16
|
+
add_filter '/spec'
|
17
|
+
|
18
|
+
# do not track vendored files
|
19
|
+
add_filter '/vendor'
|
20
|
+
add_filter '/.vendor'
|
21
|
+
|
22
|
+
# do not track gitignored files
|
23
|
+
# this adds about 4 seconds to the coverage check
|
24
|
+
# this could definitely be optimized
|
25
|
+
add_filter do |f|
|
26
|
+
# system returns true if exit status is 0, which with git-check-ignore means file is ignored
|
27
|
+
system("git check-ignore --quiet #{f.filename}")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
rescue LoadError
|
31
|
+
raise 'Add the simplecov, simplecov-console, codecov gems to Gemfile to enable this task'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rspec'
|
36
|
+
require 'git'
|
37
|
+
require 'fileutils'
|
38
|
+
|
39
|
+
def pupmods_dir
|
40
|
+
@pupmods_dir ||= begin
|
41
|
+
p = File.join(fixtures_dir, 'puppetlabs')
|
42
|
+
FileUtils.mkdir_p(p) unless File.exist?(p)
|
43
|
+
p
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def remote_testing_repo
|
48
|
+
File.join(pupmods_dir, 'puppetlabs-testing.git')
|
49
|
+
end
|
50
|
+
|
51
|
+
# localizes the remote repo for faster testing, download once and use the local machine as the remote repo
|
52
|
+
def setup_fake_module
|
53
|
+
Git.clone('https://github.com/puppetlabs/puppetlabs-testing.git', remote_testing_repo) unless Dir.exist?(File.join(remote_testing_repo, '.git'))
|
54
|
+
end
|
55
|
+
|
56
|
+
def destroy_fake_modules
|
57
|
+
FileUtils.rm_rf(pupmods_dir)
|
58
|
+
end
|
59
|
+
|
60
|
+
def fixtures_dir
|
61
|
+
@fixtures_dir ||= File.join(__dir__, 'fixtures')
|
62
|
+
end
|
63
|
+
|
64
|
+
RSpec.configure do |config|
|
65
|
+
config.before(:suite) do
|
66
|
+
setup_fake_module
|
67
|
+
# provide a fake github token for the tests
|
68
|
+
ENV['GITHUB_TOKEN'] = 'github-token'
|
69
|
+
end
|
70
|
+
config.before(:each) do
|
71
|
+
allow(PdkSync::Utils.configuration).to receive(:git_base_uri).and_return("file://#{fixtures_dir}")
|
72
|
+
end
|
73
|
+
config.after(:suite) { FileUtils.rm_rf(pupmods_dir) }
|
74
|
+
end
|