puppet-blacksmith 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTAzNDJmZTgyMGJhYjE3MmY2ZDM1MzM0MjI0ZmYzYTBhNWM5ZjIxOQ==
4
+ NDliNmIwNmE5NWY3NDU3MWE0ZDhiYjQ3MDhjZjBjZWI3ZjVkNWYwOQ==
5
5
  data.tar.gz: !binary |-
6
- M2RmMDlkZTljMzcwOWVlY2I5MzQ5MjJlYjEzMWE3YjAyYzAxZDkyMg==
6
+ YTMzNGMzZjhjYjBlMjAxMjJjNWVmMGJlMGE4ZGMyNDMyZWVlMGM4Nw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Yjc3MDI2MDNiMWQwY2RiNzcyNjgzYmE1MWExMmM2Nzg3ZDY2MWQ2NWE4MmIz
10
- YmU3ZmFiYTEzNzNiMTI5OGRiNzc4MjZjMTk0MzhhZjhiOTBiN2JlOTY0MDMz
11
- Mjk3MDdkZTlhZThlMzJiZWFhM2I2NDY1MjMwMTFlMTBhZWFmMjU=
9
+ ZDY3OTg3MzMyYjVmNWQyNWUxNjVkZjU0Njc3NzI2OGU3YTQ3ZDA3NjQ2MWIz
10
+ NDFiOGNhZmI0YTg4MTY4YmMyNGJkYTEyZjc4MjYzM2U5OGZkNjBhYzdlZjE4
11
+ ZDYyMjFkN2UxODQ3MmY2NTM1MjM0MmE2YWE3MDc2MWIzZWMxMzI=
12
12
  data.tar.gz: !binary |-
13
- N2JlMTY5Y2I3YjU5Y2M0Yzg4Mzg0Nzc4YmE5Yjc1NDEwYzcxNDIxYzRiNDBk
14
- YjBmNmE2Y2Y0MTQ2YWE0ZmQ3Y2ViODZmMmM1M2IwYmQyY2U0OTQ1NmQ4MmYz
15
- Yzg5ODEzN2ZmNWE4NDVmM2RmM2EzZTY1YTkzZWIyNGQzNDY0NzE=
13
+ ZWIyYmIzZWVhZTUwY2MxYjcyNTgwZGM2NTVhMWE2YWYzMDgxM2VjYTQ2NzBl
14
+ ZjcxZjY3NDUxNDdhZWQ1Yjc5M2U4YWNlYmViNTMzYWNiODRhM2EzMjgzYzYx
15
+ NDIzZWMwMzY3ODQ1NjY2NjEwMDY4YWI5YTUyYTMxYWJhZDExYzg=
@@ -17,26 +17,38 @@ Puppet[:confdir] = "."
17
17
  module Blacksmith
18
18
  class Modulefile
19
19
 
20
+ FILES = ["metadata.json", "Modulefile"]
21
+
20
22
  attr_reader :path
21
23
 
22
- def initialize(path = "Modulefile")
23
- @path = path
24
+ def initialize(path = nil)
25
+ @path = path.nil? ? FILES.find {|f| File.exists? f} : path
26
+ raise Blacksmith::Error, "Unable to find any of #{FILES}" unless @path
27
+ @modulefile = @path =~ /Modulefile$/
24
28
  end
25
29
 
26
30
  def metadata
27
31
  unless @metadata
28
- metadata = Puppet::ModuleTool::Metadata.new
29
- Puppet::ModuleTool::ModulefileReader.evaluate(metadata, path)
30
- @metadata = metadata
32
+ if @modulefile
33
+ metadata = Puppet::ModuleTool::Metadata.new
34
+ Puppet::ModuleTool::ModulefileReader.evaluate(metadata, path)
35
+ @metadata = { 'name' => metadata.name, 'version' => metadata.version, 'author' => metadata.author }
36
+ else
37
+ @metadata = JSON.parse(File.read(path))
38
+ end
31
39
  end
32
40
  @metadata
33
41
  end
34
42
 
43
+ # name in metadata.json is author-modulename
35
44
  def name
36
- metadata.name
45
+ @modulefile ? metadata['name'] : metadata['name'].split('-',2)[1]
46
+ end
47
+ def author
48
+ metadata['author'] || metadata['name'].split('-',2)[0]
37
49
  end
38
50
  def version
39
- metadata.version
51
+ metadata['version']
40
52
  end
41
53
 
42
54
  def bump!
@@ -48,7 +60,13 @@ module Blacksmith
48
60
  end
49
61
 
50
62
  def replace_version(text, version)
51
- text.gsub(/\nversion[ ]+['"].*['"]/, "\nversion '#{version}'")
63
+ if @modulefile
64
+ text.gsub(/\nversion[ ]+['"].*['"]/, "\nversion '#{version}'")
65
+ else
66
+ json = JSON.parse(text)
67
+ json['version'] = version
68
+ JSON.pretty_generate(json)
69
+ end
52
70
  end
53
71
 
54
72
  def increase_version(version)
@@ -1,3 +1,3 @@
1
1
  module Blacksmith
2
- VERSION = '2.1.0'
2
+ VERSION = '2.2.0'
3
3
  end
@@ -0,0 +1,32 @@
1
+ {
2
+ "operatingsystem_support": [
3
+ {
4
+ "operatingsystem": "CentOS",
5
+ "operatingsystemrelease": [
6
+ "4",
7
+ "5",
8
+ "6"
9
+ ]
10
+ }
11
+ ],
12
+ "requirements": [
13
+ {
14
+ "name": "pe",
15
+ "version_requirement": "3.2.x"
16
+ },
17
+ {
18
+ "name": "puppet",
19
+ "version_requirement": ">=2.7.20 <4.0.0"
20
+ }
21
+ ],
22
+ "name": "maestrodev-test",
23
+ "version": "1.0.0",
24
+ "source": "git://github.com/puppetlabs/puppetlabs-stdlib",
25
+ "author": "maestrodev",
26
+ "license": "Apache 2.0",
27
+ "summary": "Puppet Module Standard Library",
28
+ "description": "Standard Library for Puppet Modules",
29
+ "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib",
30
+ "dependencies": [
31
+ ]
32
+ }
@@ -13,7 +13,7 @@ describe 'Blacksmith::Forge' do
13
13
 
14
14
  describe 'missing credentials file' do
15
15
  before do
16
- File.stub(:expand_path => '/home/mr_puppet/.puppetforge.yml')
16
+ allow(File).to receive(:expand_path) { '/home/mr_puppet/.puppetforge.yml' }
17
17
  end
18
18
 
19
19
  context "when the credentials file is missing" do
@@ -10,56 +10,72 @@ describe 'Blacksmith::Git' do
10
10
  FileUtils.rm_rf path
11
11
  FileUtils.mkdir_p(path)
12
12
  `git init #{path}`
13
- FileUtils.touch(File.join(path, "Modulefile"))
14
- `cd #{path} && git add Modulefile && git commit -am "Init"`
15
13
  end
16
14
 
17
- describe 'tag!' do
18
- before { subject.tag!(version) }
19
- it "should have the tag" do
20
- out = `cd #{path} && git tag`
21
- out.chomp.should match(/^v1.0.0$/)
15
+ shared_examples_for :git do
16
+ describe 'tag!' do
17
+ before { subject.tag!(version) }
18
+ it "should have the tag" do
19
+ out = `cd #{path} && git tag`
20
+ expect(out.chomp).to match(/^v1.0.0$/)
21
+ end
22
22
  end
23
- end
24
23
 
25
- describe 'exec_git' do
26
- let(:cmd) { 'log' }
27
- let(:stdin) { nil }
28
- let(:stdout) { '' }
29
- let(:stderr) { '' }
30
- let(:exit_code) { double('exit_code', :success? => true) }
31
- let(:wait_thr) { double('wait_thr', :value => exit_code) }
24
+ describe 'exec_git' do
25
+ let(:cmd) { 'log' }
26
+ let(:stdin) { nil }
27
+ let(:stdout) { '' }
28
+ let(:stderr) { '' }
29
+ let(:exit_code) { double('exit_code', :success? => true) }
30
+ let(:wait_thr) { double('wait_thr', :value => exit_code) }
32
31
 
33
- context 'when git succeeds' do
34
- before do
35
- Open3.stub(:popen3).and_yield(nil, double(:read => stdout), double(:read => stderr), wait_thr)
36
- expect { subject.exec_git(cmd) }.to_not raise_error
37
- end
32
+ context 'when git succeeds' do
33
+ before do
34
+ allow(Open3).to receive(:popen3).and_yield(nil, double(:read => stdout), double(:read => stderr), wait_thr)
35
+ expect { subject.exec_git(cmd) }.to_not raise_error
36
+ end
38
37
 
39
- context 'when stderr is empty' do
40
- it {}
41
- end
38
+ context 'when stderr is empty' do
39
+ it {}
40
+ end
41
+
42
+ context 'when stderr is not empty' do
43
+ let(:stderr) { 'some error' }
44
+ it {}
45
+ end
42
46
 
43
- context 'when stderr is not empty' do
44
- let(:stderr) { 'some error' }
45
- it {}
46
47
  end
47
48
 
48
- end
49
+ context 'when git fails' do
50
+ before { allow(subject).to receive(:git_cmd_with_path) {cmd} }
49
51
 
50
- context 'when git fails' do
51
- before { subject.stub(:git_cmd_with_path => cmd) }
52
+ # this spec fails on jruby, can't detect exit code of script
53
+ context 'when stderr is empty' do
54
+ let(:cmd) { "git" } # exits with 1
55
+ it { expect { subject.exec_git(cmd) }.to raise_error(Blacksmith::Error, /^Command .* failed with exit status.*1$/) }
56
+ end
52
57
 
53
- # this spec fails on jruby, can't detect exit code of script
54
- context 'when stderr is empty' do
55
- let(:cmd) { "git" } # exits with 1
56
- it { expect { subject.exec_git(cmd) }.to raise_error(Blacksmith::Error, /^Command .* failed with exit status.*1$/) }
58
+ context 'when stderr is not empty' do
59
+ let(:cmd) { "git help xxxx" } # exits with 1 and prints to stdout
60
+ it { expect { subject.exec_git(cmd) }.to raise_error(Blacksmith::Error, /No manual entry for gitxxx/) }
61
+ end
57
62
  end
63
+ end
64
+ end
58
65
 
59
- context 'when stderr is not empty' do
60
- let(:cmd) { "git help xxxx" } # exits with 1 and prints to stdout
61
- it { expect { subject.exec_git(cmd) }.to raise_error(Blacksmith::Error, /No manual entry for gitxxx/) }
62
- end
66
+ context "Using Modulefile" do
67
+ before do
68
+ FileUtils.touch(File.join(path, "Modulefile"))
69
+ `cd #{path} && git add Modulefile && git commit -am "Init"`
70
+ end
71
+ it_behaves_like :git
72
+ end
73
+
74
+ context "Using metadata.json" do
75
+ before do
76
+ FileUtils.touch(File.join(path, "metadata.json"))
77
+ `cd #{path} && git add metadata.json && git commit -am "Init"`
63
78
  end
79
+ it_behaves_like :git
64
80
  end
65
81
  end
@@ -2,50 +2,92 @@ require 'spec_helper'
2
2
 
3
3
  describe 'Blacksmith::Modulefile' do
4
4
 
5
+ let(:path) { "spec/data/metadata.json" }
6
+
5
7
  subject { Blacksmith::Modulefile.new(path) }
6
- let(:path) { "spec/data/Modulefile" }
7
8
 
8
- context 'when modulefile is parsed' do
9
- it { subject.metadata.version.should eql("1.0.0") }
10
- it { subject.metadata.author.should eql("maestrodev") }
11
- it { subject.metadata.name.should eql("test") }
9
+ shared_examples_for :metadata do
10
+ it { expect(subject.version).to eql("1.0.0") }
11
+ it { expect(subject.name).to eql("test") }
12
12
  end
13
13
 
14
- describe 'replace_version' do
15
- it "should replace the version" do
16
- original = <<-eos
17
- name 'maestrodev-test'
18
- version '1.0.0'
14
+ context "using metadata.json" do
19
15
 
20
- author 'maestrodev'
21
- license 'Apache License, Version 2.0'
22
- project_page 'http://github.com/maestrodev/puppet-blacksmith'
23
- source 'http://github.com/maestrodev/puppet-blacksmith'
24
- summary 'version "1"'
25
- description "version '1'"
26
- eos
16
+ it_behaves_like :metadata
17
+
18
+ describe 'replace_version' do
19
+ it "should replace the version in metadata" do
27
20
 
28
- expected = <<-eos
21
+ expected = <<-eos
22
+ {
23
+ "operatingsystem_support": [
24
+ {
25
+ "operatingsystem": "CentOS",
26
+ "operatingsystemrelease": [
27
+ "4",
28
+ "5",
29
+ "6"
30
+ ]
31
+ }
32
+ ],
33
+ "requirements": [
34
+ {
35
+ "name": "pe",
36
+ "version_requirement": "3.2.x"
37
+ },
38
+ {
39
+ "name": "puppet",
40
+ "version_requirement": ">=2.7.20 <4.0.0"
41
+ }
42
+ ],
43
+ "name": "maestrodev-test",
44
+ "version": "1.0.1",
45
+ "source": "git://github.com/puppetlabs/puppetlabs-stdlib",
46
+ "author": "maestrodev",
47
+ "license": "Apache 2.0",
48
+ "summary": "Puppet Module Standard Library",
49
+ "description": "Standard Library for Puppet Modules",
50
+ "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib",
51
+ "dependencies": [
52
+ ]
53
+ }
54
+ eos
55
+
56
+ expect(JSON.parse(subject.replace_version(File.read(path), "1.0.1"))).to eql(JSON.parse(expected))
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ context "using a Modulefile" do
63
+
64
+ let(:path) { "spec/data/Modulefile" }
65
+
66
+ it_behaves_like :metadata
67
+
68
+ describe 'replace_version' do
69
+ it "should replace the version in a Modulefile" do
70
+ expected = <<-eos
29
71
  name 'maestrodev-test'
30
72
  version '1.0.1'
31
73
 
32
- author 'maestrodev'
33
74
  license 'Apache License, Version 2.0'
34
75
  project_page 'http://github.com/maestrodev/puppet-blacksmith'
35
76
  source 'http://github.com/maestrodev/puppet-blacksmith'
36
- summary 'version "1"'
37
- description "version '1'"
77
+ summary 'Testing Puppet module operations'
78
+ description 'Testing Puppet module operations'
38
79
  eos
39
80
 
40
- subject.replace_version(original, "1.0.1").should eql(expected)
81
+ expect(subject.replace_version(File.read(path), "1.0.1")).to eql(expected)
82
+ end
41
83
  end
84
+
42
85
  end
43
86
 
44
87
  describe 'increase_version' do
45
- it { subject.increase_version("1.0").should eql("1.1") }
46
- it { subject.increase_version("1.0.0").should eql("1.0.1") }
47
- it { subject.increase_version("1.0.1").should eql("1.0.2") }
88
+ it { expect(subject.increase_version("1.0")).to eql("1.1") }
89
+ it { expect(subject.increase_version("1.0.0")).to eql("1.0.1") }
90
+ it { expect(subject.increase_version("1.0.1")).to eql("1.0.2") }
48
91
  it { expect { subject.increase_version("1.0.12qwe") }.to raise_error }
49
92
  end
50
-
51
93
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-blacksmith
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - MaestroDev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-04 00:00:00.000000000 Z
11
+ date: 2014-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - ! '>='
116
116
  - !ruby/object:Gem::Version
117
- version: 2.7.0
117
+ version: 3.0.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - ! '>='
123
123
  - !ruby/object:Gem::Version
124
- version: 2.7.0
124
+ version: 3.0.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: webmock
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -154,6 +154,7 @@ files:
154
154
  - spec/data/Modulefile
155
155
  - spec/data/forge_error.html
156
156
  - spec/data/maestrodev-ant-1.0.4.tar.gz
157
+ - spec/data/metadata.json
157
158
  - spec/puppet_blacksmith/forge_spec.rb
158
159
  - spec/puppet_blacksmith/git_spec.rb
159
160
  - spec/puppet_blacksmith/modulefile_spec.rb
@@ -182,10 +183,11 @@ signing_key:
182
183
  specification_version: 4
183
184
  summary: Tasks to manage Puppet module builds
184
185
  test_files:
185
- - spec/spec_helper.rb
186
186
  - spec/data/maestrodev-ant-1.0.4.tar.gz
187
+ - spec/data/metadata.json
187
188
  - spec/data/forge_error.html
188
189
  - spec/data/Modulefile
189
190
  - spec/puppet_blacksmith/forge_spec.rb
190
191
  - spec/puppet_blacksmith/modulefile_spec.rb
191
192
  - spec/puppet_blacksmith/git_spec.rb
193
+ - spec/spec_helper.rb