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/spec/utils_spec.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pdksync/utils'
|
3
|
+
require 'tempfile'
|
4
|
+
describe 'PdkSync::Utils' do
|
5
|
+
before(:all) do
|
6
|
+
@tmp_dir = Dir.mktmpdir('testing')
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:cloned_module) do
|
10
|
+
begin
|
11
|
+
Git.open(@tmp_dir)
|
12
|
+
rescue ArgumentError
|
13
|
+
PdkSync::Utils.clone_directory('puppetlabs',
|
14
|
+
'puppetlabs-testing', @tmp_dir)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:metadata_file) do
|
19
|
+
File.join(@tmp_dir, 'metadata.json')
|
20
|
+
end
|
21
|
+
|
22
|
+
before(:each) do
|
23
|
+
cloned_module
|
24
|
+
end
|
25
|
+
|
26
|
+
after(:all) do
|
27
|
+
FileUtils.remove_entry @tmp_dir
|
28
|
+
end
|
29
|
+
|
30
|
+
it '#self.clone_directory' do
|
31
|
+
Dir.mktmpdir do |dir|
|
32
|
+
PdkSync::Utils.clone_directory('puppetlabs',
|
33
|
+
'puppetlabs-testing', dir)
|
34
|
+
expect(cloned_module).to be_a Git::Base
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it '#self.create_commit' do
|
39
|
+
File.write(File.join(@tmp_dir, 'README.md'), rand(32_332))
|
40
|
+
expect(PdkSync::Utils.create_commit(cloned_module, 'main', 'boom')).to match(%r{README})
|
41
|
+
end
|
42
|
+
|
43
|
+
it '#self.run_command' do
|
44
|
+
expect(PdkSync::Utils.run_command('./', 'pwd', nil)).to eq(0)
|
45
|
+
end
|
46
|
+
|
47
|
+
it '#self.pdk_update' do
|
48
|
+
expect(PdkSync::Utils.pdk_update(@tmp_dir)).to eq(0)
|
49
|
+
end
|
50
|
+
|
51
|
+
it '#self.return_template_ref' do
|
52
|
+
expect(PdkSync::Utils.return_template_ref(metadata_file)).to match(%r{^heads\/main\S+$})
|
53
|
+
end
|
54
|
+
|
55
|
+
it '#self.module_templates_url' do
|
56
|
+
allow(Octokit).to receive(:tags).with('puppetlabs/pdk').and_return([{ name: 'v1.14.1' }])
|
57
|
+
url, version = PdkSync::Utils.module_templates_url(metadata_file).split('#')
|
58
|
+
expect(url).to eq('https://github.com/puppetlabs/pdk-templates')
|
59
|
+
expect(version).to match(%r{main})
|
60
|
+
end
|
61
|
+
|
62
|
+
it '#self.change_module_template_url' do
|
63
|
+
url = 'https://github.com/nwops/pdk-templates'
|
64
|
+
ref = 'special'
|
65
|
+
expect(PdkSync::Utils.change_module_template_url(url, ref, metadata_file)).to eq('https://github.com/nwops/pdk-templates#special')
|
66
|
+
end
|
67
|
+
|
68
|
+
it '#self.checkout_branch' do
|
69
|
+
PdkSync::Utils.checkout_branch(cloned_module, 'sync1234')
|
70
|
+
branch = cloned_module.branches.find { |b| b.name.eql?('pdksync_sync1234') }
|
71
|
+
expect(branch).to be_a Git::Branch
|
72
|
+
end
|
73
|
+
|
74
|
+
it '#self.check_pdk_version is false' do
|
75
|
+
process = double
|
76
|
+
allow(process).to receive(:exitstatus).and_return(true)
|
77
|
+
allow(Octokit).to receive(:tags).with('puppetlabs/pdk').and_return([{ name: 'v1.14.1' }])
|
78
|
+
allow(PdkSync::Utils).to receive(:return_pdk_path).and_return('/opt/puppetlabs/pdk/bin/pdk')
|
79
|
+
allow(Open3).to receive(:capture3).with('/opt/puppetlabs/pdk/bin/pdk --version').and_return(['1.14.0', nil, process])
|
80
|
+
expect(PdkSync::Utils.check_pdk_version).to be false
|
81
|
+
end
|
82
|
+
|
83
|
+
it '#self.check_pdk_version is true' do
|
84
|
+
process = double
|
85
|
+
allow(process).to receive(:exitstatus).and_return(true)
|
86
|
+
allow(PdkSync::Utils).to receive(:return_pdk_path).and_return('/opt/puppetlabs/pdk/bin/pdk')
|
87
|
+
allow(Open3).to receive(:capture3).with('/opt/puppetlabs/pdk/bin/pdk --version').and_return(['1.14.0', nil, process])
|
88
|
+
allow(Octokit).to receive(:tags).with('puppetlabs/pdk').and_return([{ name: 'v1.14.0' }])
|
89
|
+
expect(PdkSync::Utils.check_pdk_version).to be true
|
90
|
+
end
|
91
|
+
|
92
|
+
it '#self.check_gem_latest_version' do
|
93
|
+
process = double
|
94
|
+
allow(process).to receive(:exitstatus).and_return(true)
|
95
|
+
allow(Octokit).to receive(:tags).with('puppetlabs/puppet_module_gems').and_return([{ name: '0.4.0' }])
|
96
|
+
expect(PdkSync::Utils.check_gem_latest_version('puppet_module_gems')).to eq '0.4.0'
|
97
|
+
end
|
98
|
+
|
99
|
+
it '#self.update_gem_latest_version_by_one' do
|
100
|
+
expect(PdkSync::Utils.update_gem_latest_version_by_one('0.4.0')).to eq Gem::Version.new('0.5')
|
101
|
+
end
|
102
|
+
|
103
|
+
it '#self.create_filespace' do
|
104
|
+
expect(PdkSync::Utils.create_filespace).to eq('modules_pdksync')
|
105
|
+
end
|
106
|
+
|
107
|
+
it '#self.setup_client' do
|
108
|
+
g = double(PdkSync::GitPlatformClient)
|
109
|
+
expect(PdkSync::GitPlatformClient).to receive(:new).with(:github,
|
110
|
+
access_token: 'github-token',
|
111
|
+
api_endpoint: nil,
|
112
|
+
gitlab_api_endpoint: 'https://gitlab.com/api/v4').and_return(g)
|
113
|
+
expect(PdkSync::Utils.setup_client).to eq(g)
|
114
|
+
end
|
115
|
+
|
116
|
+
it '#self.return_modules' do
|
117
|
+
allow_any_instance_of(PdkSync::Configuration).to receive(:managed_modules).and_return(File.join(fixtures_dir, 'fake_managed_modules.yaml'))
|
118
|
+
expect(PdkSync::Utils.return_modules).to eq(['puppetlabs/puppetlabs-testing'])
|
119
|
+
end
|
120
|
+
|
121
|
+
it '#self.validate_modules_exist' do
|
122
|
+
client = double
|
123
|
+
allow_any_instance_of(PdkSync::Configuration).to receive(:managed_modules).and_return(File.join(fixtures_dir, 'fake_managed_modules.yaml'))
|
124
|
+
allow(client).to receive(:repository?).with('puppetlabs/puppetlabs-testing').and_return(true)
|
125
|
+
expect(PdkSync::Utils.validate_modules_exist(client, ['puppetlabs-testing'])).to be true
|
126
|
+
end
|
127
|
+
|
128
|
+
it '#self.create_filespace_gem' do
|
129
|
+
expect(PdkSync::Utils.create_filespace_gem).to eq('gems_pdksync')
|
130
|
+
end
|
131
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdksync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: codecov
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: rspec
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,7 +81,21 @@ dependencies:
|
|
53
81
|
- !ruby/object:Gem::Version
|
54
82
|
version: 0.50.0
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov-console
|
57
99
|
requirement: !ruby/object:Gem::Requirement
|
58
100
|
requirements:
|
59
101
|
- - ">="
|
@@ -66,6 +108,20 @@ dependencies:
|
|
66
108
|
- - ">="
|
67
109
|
- !ruby/object:Gem::Version
|
68
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pdk
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.14.1
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.14.1
|
69
125
|
- !ruby/object:Gem::Dependency
|
70
126
|
name: git
|
71
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,21 +137,21 @@ dependencies:
|
|
81
137
|
- !ruby/object:Gem::Version
|
82
138
|
version: '1.3'
|
83
139
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
140
|
+
name: rake
|
85
141
|
requirement: !ruby/object:Gem::Requirement
|
86
142
|
requirements:
|
87
143
|
- - ">="
|
88
144
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
145
|
+
version: '0'
|
90
146
|
type: :runtime
|
91
147
|
prerelease: false
|
92
148
|
version_requirements: !ruby/object:Gem::Requirement
|
93
149
|
requirements:
|
94
150
|
- - ">="
|
95
151
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
152
|
+
version: '0'
|
97
153
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
154
|
+
name: gitlab
|
99
155
|
requirement: !ruby/object:Gem::Requirement
|
100
156
|
requirements:
|
101
157
|
- - ">="
|
@@ -109,7 +165,7 @@ dependencies:
|
|
109
165
|
- !ruby/object:Gem::Version
|
110
166
|
version: '0'
|
111
167
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
168
|
+
name: octokit
|
113
169
|
requirement: !ruby/object:Gem::Requirement
|
114
170
|
requirements:
|
115
171
|
- - ">="
|
@@ -123,7 +179,7 @@ dependencies:
|
|
123
179
|
- !ruby/object:Gem::Version
|
124
180
|
version: '0'
|
125
181
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
182
|
+
name: colorize
|
127
183
|
requirement: !ruby/object:Gem::Requirement
|
128
184
|
requirements:
|
129
185
|
- - ">="
|
@@ -137,7 +193,7 @@ dependencies:
|
|
137
193
|
- !ruby/object:Gem::Version
|
138
194
|
version: '0'
|
139
195
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
196
|
+
name: jenkins_api_client
|
141
197
|
requirement: !ruby/object:Gem::Requirement
|
142
198
|
requirements:
|
143
199
|
- - ">="
|
@@ -163,25 +219,36 @@ files:
|
|
163
219
|
- ".rubocop_todo.yml"
|
164
220
|
- ".travis.yml"
|
165
221
|
- CHANGELOG.md
|
222
|
+
- CODEOWNERS
|
166
223
|
- Gemfile
|
167
224
|
- LICENSE
|
168
225
|
- README.md
|
169
226
|
- Rakefile
|
170
227
|
- lib/pdksync.rb
|
171
|
-
- lib/pdksync/
|
228
|
+
- lib/pdksync/conf/puppet_abs_supported_platforms.yaml
|
229
|
+
- lib/pdksync/configuration.rb
|
172
230
|
- lib/pdksync/githubclient.rb
|
173
231
|
- lib/pdksync/gitlabclient.rb
|
174
232
|
- lib/pdksync/gitplatformclient.rb
|
233
|
+
- lib/pdksync/jenkinsclient.rb
|
234
|
+
- lib/pdksync/logger.rb
|
175
235
|
- lib/pdksync/pullrequest.rb
|
176
236
|
- lib/pdksync/rake_tasks.rb
|
237
|
+
- lib/pdksync/utils.rb
|
177
238
|
- managed_modules.yml
|
178
239
|
- pdksync.gemspec
|
179
|
-
- spec/
|
240
|
+
- spec/configuration_spec.rb
|
241
|
+
- spec/fixtures/fake_managed_modules.yaml
|
242
|
+
- spec/fixtures/pdksync.yml
|
243
|
+
- spec/logger_spec.rb
|
244
|
+
- spec/pdksync_spec.rb
|
245
|
+
- spec/spec_helper.rb
|
246
|
+
- spec/utils_spec.rb
|
180
247
|
homepage: http://github.com/puppetlabs/pdksync
|
181
248
|
licenses:
|
182
249
|
- Apache-2.0
|
183
250
|
metadata: {}
|
184
|
-
post_install_message:
|
251
|
+
post_install_message:
|
185
252
|
rdoc_options: []
|
186
253
|
require_paths:
|
187
254
|
- lib
|
@@ -196,9 +263,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
263
|
- !ruby/object:Gem::Version
|
197
264
|
version: '0'
|
198
265
|
requirements: []
|
199
|
-
rubygems_version: 3.
|
200
|
-
signing_key:
|
266
|
+
rubygems_version: 3.1.6
|
267
|
+
signing_key:
|
201
268
|
specification_version: 4
|
202
269
|
summary: Puppet Module PDK Synchronizer
|
203
270
|
test_files:
|
204
|
-
- spec/
|
271
|
+
- spec/configuration_spec.rb
|
272
|
+
- spec/fixtures/fake_managed_modules.yaml
|
273
|
+
- spec/fixtures/pdksync.yml
|
274
|
+
- spec/logger_spec.rb
|
275
|
+
- spec/pdksync_spec.rb
|
276
|
+
- spec/spec_helper.rb
|
277
|
+
- spec/utils_spec.rb
|
data/lib/pdksync/constants.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
# @summary
|
4
|
-
# A module used to contain a set of variables that are expected to remain constant across all iterations of the main pdksync module.
|
5
|
-
# @note
|
6
|
-
# Configuration is loaded from `$HOME/.pdksync.yml`. If $HOME is not set, the config_path will use the current directory.
|
7
|
-
# Set PDKSYNC_LABEL to '' to disable adding a label during pdksync runs.
|
8
|
-
module PdkSync # rubocop:disable Style/ClassAndModuleChildren
|
9
|
-
# Constants contains the configuration for pdksync to use
|
10
|
-
module Constants
|
11
|
-
default_config = {
|
12
|
-
namespace: 'puppetlabs',
|
13
|
-
pdksync_dir: 'modules_pdksync',
|
14
|
-
push_file_destination: 'origin',
|
15
|
-
create_pr_against: 'master',
|
16
|
-
managed_modules: 'managed_modules.yml',
|
17
|
-
pdksync_label: 'maintenance',
|
18
|
-
git_platform: :github,
|
19
|
-
git_base_uri: 'https://github.com',
|
20
|
-
gitlab_api_endpoint: 'https://gitlab.com/api/v4'
|
21
|
-
}
|
22
|
-
|
23
|
-
supported_git_platforms = [:github, :gitlab]
|
24
|
-
|
25
|
-
config = {}
|
26
|
-
|
27
|
-
config_path = File.exist?('pdksync.yml') ? 'pdksync.yml' : "#{ENV['HOME']}/.pdksync.yml"
|
28
|
-
|
29
|
-
# pdksync config file must exist, not be empty and not be an empty YAML file
|
30
|
-
if File.exist?(config_path) && YAML.load_file(config_path) && !YAML.load_file(config_path).nil?
|
31
|
-
custom_config = YAML.load_file(config_path)
|
32
|
-
config[:namespace] = custom_config['namespace'] ||= default_config[:namespace]
|
33
|
-
config[:pdksync_dir] = custom_config['pdksync_dir'] ||= default_config[:pdksync_dir]
|
34
|
-
config[:push_file_destination] = custom_config['push_file_destination'] ||= default_config[:push_file_destination]
|
35
|
-
config[:create_pr_against] = custom_config['create_pr_against'] ||= default_config[:create_pr_against]
|
36
|
-
config[:managed_modules] = custom_config['managed_modules'] ||= default_config[:managed_modules]
|
37
|
-
config[:pdksync_label] = custom_config['pdksync_label'] ||= default_config[:pdksync_label]
|
38
|
-
config[:git_platform] = custom_config['git_platform'] ||= default_config[:git_platform]
|
39
|
-
config[:git_base_uri] = custom_config['git_base_uri'] ||= case config[:git_platform]
|
40
|
-
when :gitlab
|
41
|
-
'https://gitlab.com'
|
42
|
-
else
|
43
|
-
default_config[:git_base_uri]
|
44
|
-
end
|
45
|
-
config[:gitlab_api_endpoint] = custom_config['gitlab_api_endpoint'] ||= default_config[:gitlab_api_endpoint]
|
46
|
-
else
|
47
|
-
config = default_config
|
48
|
-
end
|
49
|
-
|
50
|
-
NAMESPACE = config[:namespace].freeze
|
51
|
-
PDKSYNC_DIR = config[:pdksync_dir].freeze
|
52
|
-
PUSH_FILE_DESTINATION = config[:push_file_destination].freeze
|
53
|
-
CREATE_PR_AGAINST = config[:create_pr_against].freeze
|
54
|
-
MANAGED_MODULES = config[:managed_modules].freeze
|
55
|
-
PDKSYNC_LABEL = config[:pdksync_label].freeze
|
56
|
-
GIT_PLATFORM = config[:git_platform].downcase.to_sym.freeze
|
57
|
-
GIT_BASE_URI = config[:git_base_uri].freeze
|
58
|
-
GITLAB_API_ENDPOINT = config[:gitlab_api_endpoint].freeze
|
59
|
-
ACCESS_TOKEN = case GIT_PLATFORM
|
60
|
-
when :github
|
61
|
-
ENV['GITHUB_TOKEN'].freeze
|
62
|
-
when :gitlab
|
63
|
-
ENV['GITLAB_TOKEN'].freeze
|
64
|
-
end
|
65
|
-
|
66
|
-
# Sanity checks
|
67
|
-
|
68
|
-
unless supported_git_platforms.include?(GIT_PLATFORM)
|
69
|
-
raise "Unsupported Git hosting platform '#{GIT_PLATFORM}'."\
|
70
|
-
" Supported platforms are: #{supported_git_platforms.join(', ')}"
|
71
|
-
end
|
72
|
-
|
73
|
-
if ACCESS_TOKEN.nil?
|
74
|
-
raise "Git platform access token for #{GIT_PLATFORM.capitalize} not set"\
|
75
|
-
" - use 'export #{GIT_PLATFORM.upcase}_TOKEN=\"<your token>\"' to set"
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
data/spec/lib/pdksync_spec.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
require_relative '../../lib/pdksync'
|
2
|
-
require 'git'
|
3
|
-
require 'fileutils'
|
4
|
-
require 'octokit'
|
5
|
-
|
6
|
-
describe PdkSync do
|
7
|
-
before(:all) do
|
8
|
-
@pdksync_dir = './modules_pdksync'
|
9
|
-
module_name = 'puppetlabs-testing'
|
10
|
-
@module_names = ['puppetlabs-testing']
|
11
|
-
@output_path = "#{@pdksync_dir}/#{module_name}"
|
12
|
-
@folder = Dir.pwd
|
13
|
-
end
|
14
|
-
|
15
|
-
before(:each) do
|
16
|
-
allow(PdkSync).to receive(:return_modules).and_return(@module_names)
|
17
|
-
allow(PdkSync).to receive(:validate_modules_exist).and_return(@module_names)
|
18
|
-
Dir.chdir(@folder)
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'main method' do
|
22
|
-
it 'runs clone sucessfully' do
|
23
|
-
FileUtils.rm_rf(@pdksync_dir)
|
24
|
-
PdkSync.create_filespace
|
25
|
-
PdkSync.main(steps: [:clone])
|
26
|
-
expect(Dir.exist?(@pdksync_dir)).to be(true)
|
27
|
-
expect(Dir.exist?(@output_path)).to be(true)
|
28
|
-
end
|
29
|
-
it 'runs pdk convert, and files have changed' do
|
30
|
-
PdkSync.main(steps: [:pdk_convert])
|
31
|
-
File.exist?("#{@output_path}/convert_report.txt")
|
32
|
-
end
|
33
|
-
it 'raise when running a command with no argument' do
|
34
|
-
expect { PdkSync.main(steps: [:run_a_command]) }.to raise_error(RuntimeError, %r{"run_a_command" requires an argument to run.})
|
35
|
-
end
|
36
|
-
it 'runs a command "touch cat.meow"' do
|
37
|
-
PdkSync.main(steps: [:run_a_command], args: 'touch cat.meow')
|
38
|
-
expect File.exist?("#{@output_path}/cat.meow")
|
39
|
-
end
|
40
|
-
it 'raise when create_commit with no arguments' do
|
41
|
-
expect { PdkSync.main(steps: [:create_commit]) }.to raise_error(RuntimeError, %r{Needs a branch_name and commit_message})
|
42
|
-
end
|
43
|
-
it 'create_commit runs, and contains the "kittens in mittens"' do
|
44
|
-
PdkSync.main(steps: [:create_commit], args: { branch_name: 'temp_branch', commit_message: 'kittens in mittens' })
|
45
|
-
git_repo = Git.open(@output_path)
|
46
|
-
expect(git_repo.show).to include('kittens in mittens')
|
47
|
-
end
|
48
|
-
it 'raise when create_pr with no arguments' do
|
49
|
-
expect { PdkSync.main(steps: [:create_pr]) }.to raise_error(RuntimeError, %r{Needs a pr_title})
|
50
|
-
end
|
51
|
-
it 'raise when create_pr with invalid label' do
|
52
|
-
expect { PdkSync.main(steps: [:create_pr], args: { pr_title: 'My amazing PR', label: 'doot doot' }) }.to raise_error(RuntimeError, %r{Ensure label is valid})
|
53
|
-
end
|
54
|
-
it 'raise when clean_branches with no arguments' do
|
55
|
-
expect { PdkSync.main(steps: [:clean_branches]) }.to raise_error(RuntimeError, %r{Needs a branch_name, and the branch name contains the string pdksync})
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|