niman 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -6
- data/lib/niman/cli/application.rb +5 -2
- data/lib/niman/installer.rb +11 -1
- data/lib/niman/library/custom_package.rb +41 -0
- data/lib/niman/library/package.rb +2 -1
- data/lib/niman/nimanfile.rb +5 -4
- data/lib/niman/package_resolver.rb +38 -0
- data/lib/niman/provisioner.rb +5 -0
- data/lib/niman/vagrant/shell.rb +6 -3
- data/lib/niman/version.rb +1 -1
- data/lib/niman.rb +1 -0
- data/niman.gemspec +2 -0
- data/spec/lib/application_spec.rb +124 -0
- data/spec/lib/installer_spec.rb +31 -0
- data/spec/lib/library/custom_package_spec.rb +56 -0
- data/spec/lib/library/file_spec.rb +3 -0
- data/spec/lib/nimanfile_spec.rb +10 -3
- data/spec/lib/provisioner_spec.rb +17 -7
- data/spec/lib/recipe_spec.rb +4 -6
- metadata +36 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0dd2e66a5efe87391ae8ea496cf819c14cc611bb
|
4
|
+
data.tar.gz: 51bddf363cae6f579f3906cb2a86e62a13243e8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09b62fb72deb43fdb3455b3b11460bdc66eaf3dafd74f9f891481ffd35c4a981e659385d0e3336f241251afc80bd4fffe1ce6531f41b2d55a892ffdabb716603
|
7
|
+
data.tar.gz: 519dbe2cf887550e5c498c5c8a5af914c23cb4b90516155e3ce36650e00149be3ef2e33efa66a06937614cdf43fa917d4cef93247e1bbaf0805d6500c790fcda
|
data/README.md
CHANGED
@@ -25,10 +25,8 @@ It starts with a `Nimanfile`:
|
|
25
25
|
|
26
26
|
```ruby
|
27
27
|
Niman::Recipe.configure do |config|
|
28
|
-
config.file do |file|
|
29
|
-
file.path = '/home/bob/hello.txt'
|
28
|
+
config.file '/home/bob/hello.txt' do |file|
|
30
29
|
file.content = 'hello from alice'
|
31
|
-
file.mode = '0600'
|
32
30
|
end
|
33
31
|
end
|
34
32
|
```
|
@@ -49,7 +47,10 @@ Niman::Recipe.configure do |config|
|
|
49
47
|
end
|
50
48
|
```
|
51
49
|
|
50
|
+
#### Custom packages
|
51
|
+
|
52
52
|
Custom packages live in `packages/`. Every package gets its own file.
|
53
|
+
|
53
54
|
Package description:
|
54
55
|
```ruby
|
55
56
|
#packages/ruby.rb
|
@@ -62,9 +63,24 @@ end
|
|
62
63
|
In your `Nimanfile`:
|
63
64
|
```ruby
|
64
65
|
Niman::Recipe.configure do |config|
|
65
|
-
config.package
|
66
|
-
|
67
|
-
|
66
|
+
config.package "packages/ruby"
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
A custom package can have one or more configuration files inside of it:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
#packages/nginx
|
74
|
+
class NginxPackage < Niman::Package
|
75
|
+
package :ubuntu, 'nginx'
|
76
|
+
|
77
|
+
configuration '/etc/nginx/nginx.conf' do |config|
|
78
|
+
#general nginx configuration goes here
|
79
|
+
config.content = '...'
|
80
|
+
end
|
81
|
+
|
82
|
+
configuration '/etc/nginx/sites-available/example.com' do |config|
|
83
|
+
config.content = '...'
|
68
84
|
end
|
69
85
|
end
|
70
86
|
```
|
@@ -5,6 +5,7 @@ require "niman/shell"
|
|
5
5
|
require "niman/installer"
|
6
6
|
require "niman/exceptions"
|
7
7
|
require "niman/filehandler"
|
8
|
+
require "niman/package_resolver"
|
8
9
|
|
9
10
|
module Niman
|
10
11
|
module CLI
|
@@ -26,11 +27,13 @@ module Niman
|
|
26
27
|
debian: 'apt-get -y',
|
27
28
|
redhat: 'yum -y'
|
28
29
|
})
|
30
|
+
|
31
|
+
resolver = Niman::PackageResolver.new(config.instructions)
|
29
32
|
filehandler = Niman::FileHandler.new(client_shell)
|
30
|
-
provisioner = Niman::Provisioner.new(installer, filehandler,
|
33
|
+
provisioner = Niman::Provisioner.new(installer, filehandler, resolver.resolve)
|
31
34
|
this = self
|
32
35
|
provisioner.run do |instruction|
|
33
|
-
this.say "Executing task #{instruction.description}" unless @
|
36
|
+
this.say "Executing task #{instruction.description}" unless @silent
|
34
37
|
end
|
35
38
|
rescue LoadError => e
|
36
39
|
client_shell.print(e.message, :error)
|
data/lib/niman/installer.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'virtus'
|
2
2
|
require 'niman/exceptions'
|
3
|
+
require 'niman/package_resolver'
|
3
4
|
|
4
5
|
module Niman
|
5
6
|
class Installer
|
@@ -9,8 +10,17 @@ module Niman
|
|
9
10
|
attribute :shell, Object
|
10
11
|
|
11
12
|
def install(packages)
|
12
|
-
package_manager = managers.fetch(shell.os.to_sym) { raise Niman::InstallError, shell.os }
|
13
13
|
Array(packages).each do |package|
|
14
|
+
self.install_package(package)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def install_package(package)
|
19
|
+
package_manager = managers.fetch(shell.os.to_sym) { raise Niman::InstallError, shell.os }
|
20
|
+
if package.respond_to?(:package_names)
|
21
|
+
package_name = package.package_names.fetch(shell.os.to_sym) { raise Niman::InstallError, "Package has no support for #{shell.os}" }
|
22
|
+
shell.exec("#{package_manager} install #{package_name}", true)
|
23
|
+
elsif package.respond_to?(:name)
|
14
24
|
shell.exec("#{package_manager} install #{package.name}", true)
|
15
25
|
end
|
16
26
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Niman
|
2
|
+
module Library
|
3
|
+
class CustomPackage
|
4
|
+
class << self
|
5
|
+
attr_reader :package_names, :files
|
6
|
+
|
7
|
+
def valid?
|
8
|
+
!package_names.nil? &&
|
9
|
+
!package_names.empty? &&
|
10
|
+
package_names.keys.all?{|k| !package_names[k].empty?}
|
11
|
+
end
|
12
|
+
|
13
|
+
def package_name(os, name)
|
14
|
+
@package_names ||= {}
|
15
|
+
@package_names[os.to_sym] = name
|
16
|
+
end
|
17
|
+
|
18
|
+
def file(path)
|
19
|
+
@files ||= []
|
20
|
+
file = Niman::Library::File.new(path: path)
|
21
|
+
yield file if block_given?
|
22
|
+
@files << file
|
23
|
+
end
|
24
|
+
|
25
|
+
def description
|
26
|
+
''
|
27
|
+
end
|
28
|
+
|
29
|
+
def errors
|
30
|
+
return [] if self.valid?
|
31
|
+
package_names.keys.map do |key|
|
32
|
+
if package_names[key].empty?
|
33
|
+
"No package name configured for OS #{key}"
|
34
|
+
end
|
35
|
+
end.flatten
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
@@ -4,6 +4,7 @@ module Niman
|
|
4
4
|
include Virtus.model
|
5
5
|
|
6
6
|
attribute :name, String, default: ""
|
7
|
+
attribute :path, String, default: ""
|
7
8
|
attribute :version, String, default: ""
|
8
9
|
|
9
10
|
def description
|
@@ -11,7 +12,7 @@ module Niman
|
|
11
12
|
end
|
12
13
|
|
13
14
|
def valid?
|
14
|
-
!name.empty?
|
15
|
+
!name.empty? || !path.empty?
|
15
16
|
end
|
16
17
|
|
17
18
|
def errors
|
data/lib/niman/nimanfile.rb
CHANGED
@@ -8,15 +8,16 @@ module Niman
|
|
8
8
|
@instructions = []
|
9
9
|
end
|
10
10
|
|
11
|
-
def file
|
12
|
-
f = Niman::Library::File.new
|
11
|
+
def file(path)
|
12
|
+
f = Niman::Library::File.new(path: path)
|
13
13
|
yield(f)
|
14
14
|
@instructions.push(f)
|
15
15
|
end
|
16
16
|
|
17
|
-
def package
|
17
|
+
def package(path = nil)
|
18
18
|
package = Niman::Library::Package.new
|
19
|
-
|
19
|
+
package.path = path unless path.nil?
|
20
|
+
yield(package) if block_given?
|
20
21
|
@instructions.push(package)
|
21
22
|
end
|
22
23
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Niman
|
2
|
+
class PackageResolver
|
3
|
+
|
4
|
+
def initialize(instructions)
|
5
|
+
@instructions = instructions
|
6
|
+
end
|
7
|
+
|
8
|
+
def resolve
|
9
|
+
Array(@instructions).map do |instruction|
|
10
|
+
if is_file?(instruction) && !instruction.path.empty?
|
11
|
+
self.by_name(self.load(instruction.path))
|
12
|
+
else
|
13
|
+
instruction
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def load(filename)
|
19
|
+
basename = File.basename(filename ,File.extname(filename))
|
20
|
+
require File.expand_path(File.join('packages/', basename))
|
21
|
+
titleize(basename)
|
22
|
+
end
|
23
|
+
|
24
|
+
def by_name(name)
|
25
|
+
Kernel.const_get(name)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def is_file?(obj)
|
31
|
+
obj.respond_to?(:path) && obj.respond_to?(:name)
|
32
|
+
end
|
33
|
+
|
34
|
+
def titleize(filename)
|
35
|
+
filename.split('_').map(&:capitalize).join('')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/niman/provisioner.rb
CHANGED
@@ -22,6 +22,11 @@ module Niman
|
|
22
22
|
raise Niman::ConfigError, self.errors unless self.valid?
|
23
23
|
@instructions.each do |instruction|
|
24
24
|
yield(instruction) if block_given?
|
25
|
+
if instruction.respond_to?(:files)
|
26
|
+
instruction.files.each do |file|
|
27
|
+
@filehandler.run(file)
|
28
|
+
end
|
29
|
+
end
|
25
30
|
if instruction.respond_to?(:run)
|
26
31
|
@filehandler.run(instruction)
|
27
32
|
else
|
data/lib/niman/vagrant/shell.rb
CHANGED
@@ -43,10 +43,13 @@ module VagrantPlugins
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def create_file(path, content)
|
46
|
-
|
47
|
-
|
46
|
+
if content.include?("\n")
|
47
|
+
cmd = "cat > #{path} << EOL\n#{content}\nEOL"
|
48
|
+
else
|
49
|
+
cmd = "echo #{content} > #{path}"
|
50
|
+
end
|
51
|
+
@channel.sudo(cmd) do |type, data|
|
48
52
|
color = type == :stdout ? :green : :red
|
49
|
-
# Clear out the newline since we add one
|
50
53
|
data = data.chomp
|
51
54
|
next if data.empty?
|
52
55
|
options = {}
|
data/lib/niman/version.rb
CHANGED
data/lib/niman.rb
CHANGED
data/niman.gemspec
CHANGED
@@ -23,4 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "rspec", "3.1"
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.7"
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
27
|
+
spec.add_development_dependency "pry-byebug", "~> 3.0"
|
26
28
|
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'niman/cli/application'
|
3
|
+
require 'niman/shell'
|
4
|
+
|
5
|
+
describe Niman::CLI::Application do
|
6
|
+
let(:shell) { double(Niman::Shell) }
|
7
|
+
subject(:application) { Niman::CLI::Application.new }
|
8
|
+
|
9
|
+
before do
|
10
|
+
FakeFS.deactivate!
|
11
|
+
application.client_shell = shell
|
12
|
+
application.silent = true
|
13
|
+
allow(shell).to receive(:os).and_return(:debian)
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
Niman::Recipe.reset
|
18
|
+
File.delete(Niman::Recipe::DEFAULT_FILENAME)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "create files" do
|
22
|
+
before do
|
23
|
+
nimanfile = <<-EOS
|
24
|
+
#-*- mode: ruby -*-
|
25
|
+
# vi: set ft=ruby :
|
26
|
+
Niman::Recipe.configure do |config|
|
27
|
+
config.file "/etc/nginx/nginx.conf" do |file|
|
28
|
+
file.content = '...'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
EOS
|
32
|
+
File.open(Niman::Recipe::DEFAULT_FILENAME, "w") {|h| h.write(nimanfile)}
|
33
|
+
allow(shell).to receive(:create_file)
|
34
|
+
application.apply
|
35
|
+
end
|
36
|
+
|
37
|
+
specify 'with with content' do
|
38
|
+
expect(shell).to have_received(:create_file).with('/etc/nginx/nginx.conf', '...')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "install packages" do
|
43
|
+
before do
|
44
|
+
nimanfile = <<-EOS
|
45
|
+
#-*- mode: ruby -*-
|
46
|
+
# vi: set ft=ruby :
|
47
|
+
Niman::Recipe.configure do |config|
|
48
|
+
config.package do |package|
|
49
|
+
package.name = 'git'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
EOS
|
53
|
+
File.open(Niman::Recipe::DEFAULT_FILENAME, "w") {|h| h.write(nimanfile)}
|
54
|
+
allow(shell).to receive(:exec)
|
55
|
+
application.apply
|
56
|
+
end
|
57
|
+
it 'installs git package' do
|
58
|
+
expect(shell).to have_received(:exec).with("apt-get -y install git", true)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "custom package" do
|
63
|
+
context 'is nonexistant' do
|
64
|
+
before do
|
65
|
+
nimanfile = <<-EOS
|
66
|
+
#-*- mode: ruby -*-
|
67
|
+
# vi: set ft=ruby :
|
68
|
+
require 'niman'
|
69
|
+
Niman::Recipe.configure do |config|
|
70
|
+
config.package "packages/nginx"
|
71
|
+
end
|
72
|
+
EOS
|
73
|
+
File.open(Niman::Recipe::DEFAULT_FILENAME, "w") {|h| h.write(nimanfile)}
|
74
|
+
allow(shell).to receive(:print)
|
75
|
+
application.apply
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'prints out validation error' do
|
79
|
+
expect(shell).to have_received(:print)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
context 'is existant' do
|
83
|
+
before do
|
84
|
+
nginx_package = <<-EOS
|
85
|
+
require 'niman'
|
86
|
+
|
87
|
+
class Nginx < Niman::Library::CustomPackage
|
88
|
+
package_name :debian, 'nginx'
|
89
|
+
|
90
|
+
file '/etc/nginx/nginx.conf' do |config|
|
91
|
+
config.content = 'foo bar'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
EOS
|
95
|
+
|
96
|
+
nimanfile = <<-EOS
|
97
|
+
#-*- mode: ruby -*-
|
98
|
+
# vi: set ft=ruby :
|
99
|
+
require 'niman'
|
100
|
+
Niman::Recipe.configure do |config|
|
101
|
+
config.package "packages/nginx"
|
102
|
+
end
|
103
|
+
EOS
|
104
|
+
FileUtils.mkdir("packages")
|
105
|
+
File.open("packages/nginx.rb", "w") {|h| h.write(nginx_package)}
|
106
|
+
File.open(Niman::Recipe::DEFAULT_FILENAME, "w") {|h| h.write(nimanfile)}
|
107
|
+
allow(shell).to receive(:create_file)
|
108
|
+
allow(shell).to receive(:exec)
|
109
|
+
application.apply
|
110
|
+
end
|
111
|
+
after do
|
112
|
+
FileUtils.rm_r("packages")
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'installs nginx package' do
|
116
|
+
expect(shell).to have_received(:exec).with("apt-get -y install nginx", true)
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'writes /etc/nginx/nginx.conf' do
|
120
|
+
expect(shell).to have_received(:create_file).with('/etc/nginx/nginx.conf', 'foo bar')
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
data/spec/lib/installer_spec.rb
CHANGED
@@ -34,6 +34,10 @@ describe Niman::Installer do
|
|
34
34
|
}, shell: shell)}
|
35
35
|
let(:vim_package) { Niman::Library::Package.new(name: 'vim') }
|
36
36
|
let(:ssh_package) { Niman::Library::Package.new(name: 'ssh') }
|
37
|
+
let(:custom_ruby_package) { Class.new(Niman::Library::CustomPackage) do
|
38
|
+
package_name :redhat, 'ruby-2.0.0-full'
|
39
|
+
package_name :debian, 'ruby-2.0.0'
|
40
|
+
end }
|
37
41
|
let(:packages) { [vim_package, ssh_package] }
|
38
42
|
|
39
43
|
context 'with valid operating system' do
|
@@ -50,6 +54,33 @@ describe Niman::Installer do
|
|
50
54
|
end
|
51
55
|
end
|
52
56
|
|
57
|
+
[[:debian, 'apt-get install'], [:redhat, 'yum install']].each do |os, command|
|
58
|
+
context "with custom package on #{os}" do
|
59
|
+
before do
|
60
|
+
allow(shell).to receive(:os).and_return(os)
|
61
|
+
allow(shell).to receive(:exec)
|
62
|
+
installer.install(custom_ruby_package)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'installs with correct package name' do
|
66
|
+
package_name = custom_ruby_package.package_names[os]
|
67
|
+
expect(shell).to have_received(:exec).with("#{command} #{package_name}", true)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'with unsupported custom package' do
|
73
|
+
let(:custom_nginx_package) { Class.new(Niman::Library::CustomPackage) do
|
74
|
+
package_name :gentoo, 'nginx-full'
|
75
|
+
end }
|
76
|
+
before do
|
77
|
+
allow(shell).to receive(:os).and_return(:redhat)
|
78
|
+
end
|
79
|
+
it 'raises error' do
|
80
|
+
expect { installer.install(custom_nginx_package) }.to raise_error(Niman::InstallError)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
53
84
|
it 'raises for unknown operating system' do
|
54
85
|
allow(shell).to receive(:os).and_return(:freebsd)
|
55
86
|
expect { installer.install(packages) }.to raise_error(Niman::InstallError)
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'niman/library/custom_package'
|
3
|
+
|
4
|
+
describe Niman::Library::CustomPackage do
|
5
|
+
subject(:package) { Niman::Library::CustomPackage }
|
6
|
+
describe '.package_name' do
|
7
|
+
it 'sets a package name for a certain OS' do
|
8
|
+
package.package_name(:centos, 'ngnix')
|
9
|
+
expect(package.package_names.length).to eq 1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".file" do
|
14
|
+
let(:path) { '/etc/nginx/nginx.conf' }
|
15
|
+
it 'accepts a filename' do
|
16
|
+
package.file(path)
|
17
|
+
expect(package.files.first.path).to eq path
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'accepts a block and passes a file object' do
|
21
|
+
expect { |b| package.file(path, &b) }.to yield_with_args(Niman::Library::File)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '.valid?' do
|
26
|
+
before do
|
27
|
+
package.instance_variable_set(:@package_names, {})
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'is not valid when package_names not set' do
|
31
|
+
expect(package.valid?).to be false
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'is not valid when package name is empty' do
|
35
|
+
package.package_name :ubuntu, ''
|
36
|
+
expect(package.valid?).to be false
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'is valid when at least one package name is set' do
|
40
|
+
package.package_name :ubuntu, 'nginx'
|
41
|
+
expect(package.valid?).to be true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '.errors' do
|
46
|
+
it 'returns empty array when package is valid' do
|
47
|
+
package.package_name :centos, 'foo'
|
48
|
+
expect(package.errors).to eq []
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns error when package is not valid' do
|
52
|
+
package.package_name :centos, ''
|
53
|
+
expect(package.errors).to_not be nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/spec/lib/nimanfile_spec.rb
CHANGED
@@ -15,8 +15,15 @@ describe Niman::Nimanfile do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
describe '#file' do
|
19
|
+
it 'calls block with config object' do
|
20
|
+
expect { |b| niman_file.file('/home/foo.txt', &b) }.to yield_with_args(Niman::Library::File)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'sets path' do
|
24
|
+
niman_file.file('/home/foo.txt') {}
|
25
|
+
expect(niman_file.instructions.first.path).to eq '/home/foo.txt'
|
26
|
+
end
|
20
27
|
end
|
21
28
|
|
22
29
|
specify 'package calls block with config object' do
|
@@ -25,7 +32,7 @@ describe Niman::Nimanfile do
|
|
25
32
|
|
26
33
|
describe '#instructions' do
|
27
34
|
before do
|
28
|
-
niman_file.file {}
|
35
|
+
niman_file.file('') {}
|
29
36
|
end
|
30
37
|
|
31
38
|
specify 'increases when #file is being called' do
|
@@ -4,16 +4,22 @@ require 'niman/installer'
|
|
4
4
|
require 'niman/exceptions'
|
5
5
|
|
6
6
|
describe Niman::Provisioner do
|
7
|
-
let(:file)
|
8
|
-
let(:vim_package)
|
9
|
-
let(:
|
10
|
-
|
11
|
-
|
7
|
+
let(:file) { Niman::Library::File.new(path: '~/hello.txt', content: 'ohai') }
|
8
|
+
let(:vim_package) { Niman::Library::Package.new(name: 'vim') }
|
9
|
+
let(:nginx_package) { Class.new(Niman::Library::CustomPackage) do
|
10
|
+
package_name :ubuntu, 'nginx'
|
11
|
+
file '/etc/nginx/nginx.conf' do |file|
|
12
|
+
file.content = 'foo'
|
13
|
+
end
|
14
|
+
end}
|
15
|
+
let(:instructions) { [file,vim_package, nginx_package] }
|
16
|
+
let(:installer) { double(Niman::Installer) }
|
17
|
+
let(:filehandler) { double(Niman::FileHandler) }
|
12
18
|
subject(:provisioner) { Niman::Provisioner.new(installer, filehandler, instructions) }
|
13
19
|
|
14
20
|
describe "#initialize" do
|
15
21
|
it 'accepts a list of instructions' do
|
16
|
-
expect(provisioner.instructions).to eq
|
22
|
+
expect(provisioner.instructions).to eq instructions
|
17
23
|
end
|
18
24
|
|
19
25
|
it 'accepts a single instruction' do
|
@@ -57,12 +63,16 @@ describe Niman::Provisioner do
|
|
57
63
|
expect(filehandler).to have_received(:run).with(file)
|
58
64
|
end
|
59
65
|
|
66
|
+
it 'calls file handler for custom package files' do
|
67
|
+
expect(filehandler).to have_received(:run).with(nginx_package.files.first)
|
68
|
+
end
|
69
|
+
|
60
70
|
it 'calls installer for package' do
|
61
71
|
expect(installer).to have_received(:install).with(vim_package)
|
62
72
|
end
|
63
73
|
|
64
74
|
it 'calls block for every instruction' do
|
65
|
-
expect { |b| provisioner.run(&b) }.to yield_successive_args(file, vim_package)
|
75
|
+
expect { |b| provisioner.run(&b) }.to yield_successive_args(file, vim_package, nginx_package)
|
66
76
|
end
|
67
77
|
end
|
68
78
|
end
|
data/spec/lib/recipe_spec.rb
CHANGED
@@ -5,8 +5,7 @@ describe Niman::Recipe do
|
|
5
5
|
describe '.configure' do
|
6
6
|
before do
|
7
7
|
Niman::Recipe.configure do |config|
|
8
|
-
config.file do |file|
|
9
|
-
file.path = '/home/bob/hello.txt'
|
8
|
+
config.file '/home/bob/hello.txt' do |file|
|
10
9
|
file.content = 'hello from alice'
|
11
10
|
end
|
12
11
|
end
|
@@ -20,8 +19,7 @@ describe Niman::Recipe do
|
|
20
19
|
describe '.reset' do
|
21
20
|
before do
|
22
21
|
Niman::Recipe.configure do |config|
|
23
|
-
config.file do |file|
|
24
|
-
file.path = '/home/bob/hello.txt'
|
22
|
+
config.file '/home/bob/hello.txt' do |file|
|
25
23
|
file.content = 'hello from alice'
|
26
24
|
end
|
27
25
|
end
|
@@ -38,8 +36,7 @@ describe Niman::Recipe do
|
|
38
36
|
FakeFS.deactivate!
|
39
37
|
content = <<-EOS
|
40
38
|
Niman::Recipe.configure do |config|
|
41
|
-
config.file do |file|
|
42
|
-
file.path = '/home/bob/hello.txt'
|
39
|
+
config.file '/home/bob/hello.txt' do |file|
|
43
40
|
file.content = 'hello from alice'
|
44
41
|
end
|
45
42
|
end
|
@@ -49,6 +46,7 @@ describe Niman::Recipe do
|
|
49
46
|
end
|
50
47
|
after do
|
51
48
|
File.delete(Niman::Recipe::DEFAULT_FILENAME)
|
49
|
+
File.delete('CustomNimanfile')
|
52
50
|
FakeFS.activate!
|
53
51
|
Niman::Recipe.reset
|
54
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: niman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Schulte
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -94,6 +94,34 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.10'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.10'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry-byebug
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.0'
|
97
125
|
description:
|
98
126
|
email:
|
99
127
|
- hello@unexpected-co.de
|
@@ -115,9 +143,11 @@ files:
|
|
115
143
|
- lib/niman/exceptions.rb
|
116
144
|
- lib/niman/filehandler.rb
|
117
145
|
- lib/niman/installer.rb
|
146
|
+
- lib/niman/library/custom_package.rb
|
118
147
|
- lib/niman/library/file.rb
|
119
148
|
- lib/niman/library/package.rb
|
120
149
|
- lib/niman/nimanfile.rb
|
150
|
+
- lib/niman/package_resolver.rb
|
121
151
|
- lib/niman/platform.rb
|
122
152
|
- lib/niman/provisioner.rb
|
123
153
|
- lib/niman/recipe.rb
|
@@ -127,8 +157,10 @@ files:
|
|
127
157
|
- lib/niman/vagrant/shell.rb
|
128
158
|
- lib/niman/version.rb
|
129
159
|
- niman.gemspec
|
160
|
+
- spec/lib/application_spec.rb
|
130
161
|
- spec/lib/filehandler_spec.rb
|
131
162
|
- spec/lib/installer_spec.rb
|
163
|
+
- spec/lib/library/custom_package_spec.rb
|
132
164
|
- spec/lib/library/file_spec.rb
|
133
165
|
- spec/lib/library/package_spec.rb
|
134
166
|
- spec/lib/nimanfile_spec.rb
|
@@ -160,8 +192,10 @@ signing_key:
|
|
160
192
|
specification_version: 4
|
161
193
|
summary: Provisions your machine
|
162
194
|
test_files:
|
195
|
+
- spec/lib/application_spec.rb
|
163
196
|
- spec/lib/filehandler_spec.rb
|
164
197
|
- spec/lib/installer_spec.rb
|
198
|
+
- spec/lib/library/custom_package_spec.rb
|
165
199
|
- spec/lib/library/file_spec.rb
|
166
200
|
- spec/lib/library/package_spec.rb
|
167
201
|
- spec/lib/nimanfile_spec.rb
|