wright 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +2 -2
- data/NEWS +8 -0
- data/README.md +70 -0
- data/Rakefile +19 -0
- data/lib/wright/config.rb +64 -0
- data/lib/wright/dry_run.rb +33 -0
- data/lib/wright/dsl.rb +63 -0
- data/lib/wright/logger.rb +73 -0
- data/lib/wright/provider/directory.rb +78 -0
- data/lib/wright/provider/file.rb +104 -0
- data/lib/wright/provider/package/apt.rb +93 -0
- data/lib/wright/provider/package.rb +38 -0
- data/lib/wright/provider/symlink.rb +86 -0
- data/lib/wright/provider.rb +30 -0
- data/lib/wright/resource/directory.rb +67 -0
- data/lib/wright/resource/file.rb +67 -0
- data/lib/wright/resource/package.rb +70 -0
- data/lib/wright/resource/symlink.rb +47 -0
- data/lib/wright/resource.rb +157 -0
- data/lib/wright/util/color.rb +51 -0
- data/lib/wright/util/file.rb +258 -0
- data/lib/wright/util/file_permissions.rb +129 -0
- data/lib/wright/util/recursive_autoloader.rb +91 -0
- data/lib/wright/util/stolen_from_activesupport.rb +202 -0
- data/lib/wright/util/user.rb +75 -0
- data/lib/wright/util.rb +72 -0
- data/lib/wright/version.rb +3 -2
- data/lib/wright.rb +10 -1
- data/spec/config_spec.rb +37 -0
- data/spec/dsl_spec.rb +65 -0
- data/spec/logger_spec.rb +65 -0
- data/spec/provider/directory_spec.rb +114 -0
- data/spec/provider/file_spec.rb +130 -0
- data/spec/provider/package/apt/apt-get_install_-qy_abcde=2.5.4-1.return +1 -0
- data/spec/provider/package/apt/apt-get_install_-qy_abcde=2.5.4-1.stderr +0 -0
- data/spec/provider/package/apt/apt-get_install_-qy_abcde=2.5.4-1.stdout +15 -0
- data/spec/provider/package/apt/apt-get_install_-qy_htop.return +1 -0
- data/spec/provider/package/apt/apt-get_install_-qy_htop.stderr +0 -0
- data/spec/provider/package/apt/apt-get_install_-qy_htop.stdout +19 -0
- data/spec/provider/package/apt/apt-get_install_-qy_unknown-package.return +1 -0
- data/spec/provider/package/apt/apt-get_install_-qy_unknown-package.stderr +1 -0
- data/spec/provider/package/apt/apt-get_install_-qy_unknown-package.stdout +3 -0
- data/spec/provider/package/apt/apt-get_remove_-qy_abcde.return +1 -0
- data/spec/provider/package/apt/apt-get_remove_-qy_abcde.stderr +0 -0
- data/spec/provider/package/apt/apt-get_remove_-qy_abcde.stdout +14 -0
- data/spec/provider/package/apt/dpkg-query_-s_abcde.return +1 -0
- data/spec/provider/package/apt/dpkg-query_-s_abcde.stderr +0 -0
- data/spec/provider/package/apt/dpkg-query_-s_abcde.stdout +23 -0
- data/spec/provider/package/apt/dpkg-query_-s_htop.return +1 -0
- data/spec/provider/package/apt/dpkg-query_-s_htop.stderr +0 -0
- data/spec/provider/package/apt/dpkg-query_-s_htop.stdout +19 -0
- data/spec/provider/package/apt/dpkg-query_-s_unknown-package.return +1 -0
- data/spec/provider/package/apt/dpkg-query_-s_unknown-package.stderr +3 -0
- data/spec/provider/package/apt/dpkg-query_-s_unknown-package.stdout +0 -0
- data/spec/provider/package/apt/dpkg-query_-s_vlc.return +1 -0
- data/spec/provider/package/apt/dpkg-query_-s_vlc.stderr +3 -0
- data/spec/provider/package/apt/dpkg-query_-s_vlc.stdout +0 -0
- data/spec/provider/package/apt_spec.rb +297 -0
- data/spec/provider/package_spec.rb +63 -0
- data/spec/provider/symlink_spec.rb +122 -0
- data/spec/provider_spec.rb +19 -0
- data/spec/recursive_autoloader/foo/bar/baz.rb +12 -0
- data/spec/recursive_autoloader/identically_named_dir_and_file/this_should_not_be_loaded.rb +1 -0
- data/spec/recursive_autoloader/identically_named_dir_and_file.rb +8 -0
- data/spec/recursive_autoloader/loaded_on_demand.rb +8 -0
- data/spec/recursive_autoloader/raises_exception.rb +1 -0
- data/spec/recursive_autoloader_spec.rb +41 -0
- data/spec/resource/directory_spec.rb +187 -0
- data/spec/resource/file_spec.rb +213 -0
- data/spec/resource/symlink_spec.rb +117 -0
- data/spec/resource_spec.rb +184 -0
- data/spec/spec_helper.rb +35 -0
- data/spec/spec_helpers/fake_capture3.rb +47 -0
- data/spec/util/activesupport_spec.rb +24 -0
- data/spec/util/file_permissions_spec.rb +141 -0
- data/spec/util/file_spec.rb +127 -0
- data/spec/util/user_spec.rb +46 -0
- data/spec/util_spec.rb +80 -0
- metadata +253 -20
- data/.gitignore +0 -17
- data/Gemfile +0 -3
- data/wright.gemspec +0 -16
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
require 'etc'
|
|
2
|
+
|
|
3
|
+
module Wright
|
|
4
|
+
module Util
|
|
5
|
+
# Internal: Various user utility functions.
|
|
6
|
+
module User
|
|
7
|
+
# Internal: Get a user's uid.
|
|
8
|
+
#
|
|
9
|
+
# user - The user name or uid.
|
|
10
|
+
#
|
|
11
|
+
# Examples
|
|
12
|
+
#
|
|
13
|
+
# Wright::Util::User.user_to_uid('root')
|
|
14
|
+
# # => 0
|
|
15
|
+
#
|
|
16
|
+
# Wright::Util::User.user_to_uid(0)
|
|
17
|
+
# # => 0
|
|
18
|
+
#
|
|
19
|
+
# Returns the integer uid of the given user or nil if user was
|
|
20
|
+
# nil.
|
|
21
|
+
def self.user_to_uid(user)
|
|
22
|
+
return nil if user.nil?
|
|
23
|
+
user.is_a?(String) ? Etc.getpwnam(user).uid : user.to_i
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Internal: Get a group's gid.
|
|
27
|
+
#
|
|
28
|
+
# group - The group name or gid.
|
|
29
|
+
#
|
|
30
|
+
# Examples
|
|
31
|
+
#
|
|
32
|
+
# Wright::Util::User.group_to_gid('root')
|
|
33
|
+
# # => 0
|
|
34
|
+
#
|
|
35
|
+
# Wright::Util::User.group_to_gid(0)
|
|
36
|
+
# # => 0
|
|
37
|
+
#
|
|
38
|
+
# Returns the integer gid of the given group or nil if group was
|
|
39
|
+
# nil.
|
|
40
|
+
def self.group_to_gid(group)
|
|
41
|
+
return nil if group.nil?
|
|
42
|
+
group.is_a?(String) ? Etc.getgrnam(group).gid : group.to_i
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Internal: Split a colon-separated owner string into owner and
|
|
46
|
+
# group.
|
|
47
|
+
#
|
|
48
|
+
# owner - The owner string
|
|
49
|
+
#
|
|
50
|
+
# Examples
|
|
51
|
+
#
|
|
52
|
+
# Wright::Util::User.owner_to_owner_group('foo:bar')
|
|
53
|
+
# # => ["foo", "bar"]
|
|
54
|
+
#
|
|
55
|
+
# Wright::Util::User.owner_to_owner_group('foo')
|
|
56
|
+
# # => ["foo", nil]
|
|
57
|
+
#
|
|
58
|
+
# Wright::Util::User.owner_to_owner_group(23)
|
|
59
|
+
# # => [23, nil]
|
|
60
|
+
#
|
|
61
|
+
# Returns the owner and group. Returns nil if no group was
|
|
62
|
+
# specified. Non-string owners are returned unmodified.
|
|
63
|
+
# Raises ArgumentError if the owner string contains more than
|
|
64
|
+
# one colon.
|
|
65
|
+
def self.owner_to_owner_group(owner)
|
|
66
|
+
group = nil
|
|
67
|
+
return [owner, group] unless owner.is_a?(String)
|
|
68
|
+
|
|
69
|
+
fail ArgumentError, "Invalid owner: '#{owner}'" if owner.count(':') > 1
|
|
70
|
+
owner, group = owner.split(':')
|
|
71
|
+
[owner, group]
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
data/lib/wright/util.rb
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
require 'wright/util/stolen_from_activesupport'
|
|
2
|
+
|
|
3
|
+
module Wright
|
|
4
|
+
# Internal: Various utility functions.
|
|
5
|
+
module Util
|
|
6
|
+
# Internal: Get the resource name corresponding to a class.
|
|
7
|
+
#
|
|
8
|
+
# klass - The class constant for which to get the resource name.
|
|
9
|
+
#
|
|
10
|
+
# Examples
|
|
11
|
+
#
|
|
12
|
+
# Wright::Util.class_to_resource_name(Wright::Resource::Package)
|
|
13
|
+
# # => "package"
|
|
14
|
+
#
|
|
15
|
+
# Wright::Util.class_to_resource_name(Foo::Bar::BazQux)
|
|
16
|
+
# # => "baz_qux"
|
|
17
|
+
#
|
|
18
|
+
# Returns the String resource name of the given class.
|
|
19
|
+
def self.class_to_resource_name(klass)
|
|
20
|
+
ActiveSupport.underscore(klass.name).split('/').last
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Internal: Get the class name corresponding to a file path.
|
|
24
|
+
#
|
|
25
|
+
# filename - The filename for which to get the class name.
|
|
26
|
+
#
|
|
27
|
+
# Examples
|
|
28
|
+
#
|
|
29
|
+
# Wright::Util.filename_to_classname("foo/bar/baz.rb")
|
|
30
|
+
# # => "Foo::Bar::Baz"
|
|
31
|
+
#
|
|
32
|
+
# Wright::Util.filename_to_classname("foo/bar/")
|
|
33
|
+
# # => "Foo::Bar"
|
|
34
|
+
#
|
|
35
|
+
# Returns the String class name for the given filename.
|
|
36
|
+
def self.filename_to_classname(filename)
|
|
37
|
+
ActiveSupport.camelize(filename.chomp('.rb').chomp('/'))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.distro
|
|
41
|
+
os_release = ::File.read('/etc/os-release')
|
|
42
|
+
/^ID_LIKE=(?<id_like>.*)$/ =~ os_release
|
|
43
|
+
/^ID=(?<id>.*)$/ =~ os_release
|
|
44
|
+
id_like || id || 'linux'
|
|
45
|
+
end
|
|
46
|
+
private_class_method :distro
|
|
47
|
+
|
|
48
|
+
# Internal: Get the system's OS family.
|
|
49
|
+
#
|
|
50
|
+
# Examples
|
|
51
|
+
#
|
|
52
|
+
# Wright::Util.os_family
|
|
53
|
+
# # => "debian"
|
|
54
|
+
#
|
|
55
|
+
# Wright::Util.os_family
|
|
56
|
+
# # => "macosx"
|
|
57
|
+
#
|
|
58
|
+
# Returns the String system OS family (base distribution for
|
|
59
|
+
# GNU/Linux systems) or 'other' for unknown operating systems.
|
|
60
|
+
def self.os_family
|
|
61
|
+
system_arch = RbConfig::CONFIG['target_os']
|
|
62
|
+
case system_arch
|
|
63
|
+
when /darwin/
|
|
64
|
+
'macosx'
|
|
65
|
+
when /linux/
|
|
66
|
+
distro
|
|
67
|
+
else
|
|
68
|
+
'other'
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
data/lib/wright/version.rb
CHANGED
data/lib/wright.rb
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
require 'wright/
|
|
1
|
+
require 'wright/config'
|
|
2
|
+
require 'wright/dsl'
|
|
3
|
+
require 'wright/provider'
|
|
4
|
+
require 'wright/resource'
|
|
2
5
|
|
|
6
|
+
require 'wright/resource/directory'
|
|
7
|
+
require 'wright/resource/file'
|
|
8
|
+
require 'wright/resource/package'
|
|
9
|
+
require 'wright/resource/symlink'
|
|
10
|
+
|
|
11
|
+
# Public: TODO: Add some documentation
|
|
3
12
|
module Wright
|
|
4
13
|
end
|
data/spec/config_spec.rb
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require_relative 'spec_helper'
|
|
2
|
+
|
|
3
|
+
require 'wright/config'
|
|
4
|
+
|
|
5
|
+
describe Wright::Config do
|
|
6
|
+
before(:each) do
|
|
7
|
+
@config = Wright::Config.config_hash.clone
|
|
8
|
+
Wright::Config.config_hash.clear
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
after(:each) do
|
|
12
|
+
Wright::Config.config_hash = @config
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'should behave like a Hash' do
|
|
16
|
+
Wright::Config.size.must_equal 0
|
|
17
|
+
Wright::Config[:foo] = :bar
|
|
18
|
+
Wright::Config[:bar] = :baz
|
|
19
|
+
Wright::Config[:foo].must_equal :bar
|
|
20
|
+
Wright::Config[:bar].must_equal :baz
|
|
21
|
+
Wright::Config.size.must_equal 2
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'should handle nested key checks' do
|
|
25
|
+
Wright::Config[:foo] = { bar: :baz }
|
|
26
|
+
Wright::Config.nested_key?(:foo, :bar).must_equal true
|
|
27
|
+
Wright::Config.nested_key?(:foo, :bar, :qux).must_equal false
|
|
28
|
+
Wright::Config.nested_key?(:nonexistent).must_equal false
|
|
29
|
+
Wright::Config.nested_key?(:nonexistent1, :nonexistent2).must_equal false
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'should return values for nested keys' do
|
|
33
|
+
Wright::Config[:foo] = { bar: :baz }
|
|
34
|
+
Wright::Config.nested_value(:foo, :bar).must_equal :baz
|
|
35
|
+
Wright::Config.nested_value(:im, :not, :there).must_be_nil
|
|
36
|
+
end
|
|
37
|
+
end
|
data/spec/dsl_spec.rb
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
require_relative 'spec_helper'
|
|
2
|
+
|
|
3
|
+
require 'wright/dsl'
|
|
4
|
+
|
|
5
|
+
describe Wright::DSL do
|
|
6
|
+
before(:each) do
|
|
7
|
+
# duplicate Wright::DSL for testing
|
|
8
|
+
dsl = Wright::DSL.dup
|
|
9
|
+
@recipe = Class.new do
|
|
10
|
+
extend dsl
|
|
11
|
+
end
|
|
12
|
+
@wright_dsl = dsl
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'should register new resources at runtime' do
|
|
16
|
+
resource_class = Class.new do
|
|
17
|
+
def self.name
|
|
18
|
+
'ResourceKlass'
|
|
19
|
+
end
|
|
20
|
+
def initialize(_name); end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
@wright_dsl.register_resource(resource_class)
|
|
24
|
+
|
|
25
|
+
resource_name = 'resource_klass'
|
|
26
|
+
@recipe.must_respond_to(resource_name)
|
|
27
|
+
resource = @recipe.send(resource_name)
|
|
28
|
+
resource.must_be_instance_of(resource_class)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'should execute the default action for a resource' do
|
|
32
|
+
resource_class = Class.new do
|
|
33
|
+
def self.name
|
|
34
|
+
'Hello'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def initialize(name)
|
|
38
|
+
@name = name
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def run_action
|
|
42
|
+
puts "Hello #{@name}"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
@wright_dsl.register_resource(resource_class)
|
|
46
|
+
resource_name = Wright::Util.class_to_resource_name(resource_class)
|
|
47
|
+
-> { @recipe.send(resource_name, 'world') }.must_output("Hello world\n")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'should call blocks passed to a resource function' do
|
|
51
|
+
resource_class = Class.new do
|
|
52
|
+
def self.name
|
|
53
|
+
'ResourceKlass'
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def initialize(_name); end
|
|
57
|
+
end
|
|
58
|
+
@wright_dsl.register_resource(resource_class)
|
|
59
|
+
|
|
60
|
+
resource_name = Wright::Util.class_to_resource_name(resource_class)
|
|
61
|
+
block = ->(resource) { throw resource.class }
|
|
62
|
+
|
|
63
|
+
-> { @recipe.send(resource_name, nil, &block) }.must_throw resource_class
|
|
64
|
+
end
|
|
65
|
+
end
|
data/spec/logger_spec.rb
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
require_relative 'spec_helper'
|
|
2
|
+
|
|
3
|
+
require 'wright/logger'
|
|
4
|
+
require 'wright/config'
|
|
5
|
+
|
|
6
|
+
FORMATS = {
|
|
7
|
+
debug: :none,
|
|
8
|
+
info: :none,
|
|
9
|
+
warn: :yellow,
|
|
10
|
+
error: :red,
|
|
11
|
+
fatal: :red
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
describe Wright::Logger do
|
|
15
|
+
before(:each) do
|
|
16
|
+
@config = Wright::Config.config_hash.clone
|
|
17
|
+
Wright::Config.config_hash.clear
|
|
18
|
+
@message = 'Soylent Green is STILL made out of people!'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
after(:each) do
|
|
22
|
+
Wright::Config.config_hash = @config
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'should enable colors on TTYs' do
|
|
26
|
+
Wright::Logger.new
|
|
27
|
+
Wright::Config[:log][:colorize].must_equal true
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'should disable colors if the log device is not a TTY' do
|
|
31
|
+
Wright::Logger.new(StringIO.new)
|
|
32
|
+
Wright::Config[:log][:colorize].must_equal false
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'should not change predefined color preferences' do
|
|
36
|
+
Wright::Config[:log] = { colorize: false }
|
|
37
|
+
Wright::Logger.new
|
|
38
|
+
Wright::Config[:log][:colorize].must_equal false
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'should format log messages according to the config' do
|
|
42
|
+
[true, false].each do |enable_color|
|
|
43
|
+
Wright::Config[:log] = { colorize: enable_color }
|
|
44
|
+
|
|
45
|
+
FORMATS.each do |severity, color|
|
|
46
|
+
log_entry = "#{severity.upcase}: #{@message}\n"
|
|
47
|
+
output = if enable_color && color != :none
|
|
48
|
+
Wright::Util::Color.send(color, log_entry)
|
|
49
|
+
else
|
|
50
|
+
log_entry
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
lambda do
|
|
54
|
+
stdout = $stdout.dup
|
|
55
|
+
def stdout.tty?
|
|
56
|
+
true
|
|
57
|
+
end
|
|
58
|
+
logger = Wright::Logger.new(stdout)
|
|
59
|
+
logger.formatter = Wright::Logger::Formatter.new
|
|
60
|
+
logger.send(severity, @message)
|
|
61
|
+
end.must_output output
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
require_relative '../spec_helper'
|
|
2
|
+
|
|
3
|
+
require 'wright/provider/directory'
|
|
4
|
+
require 'wright/dry_run'
|
|
5
|
+
|
|
6
|
+
describe Wright::Provider::Directory do
|
|
7
|
+
before(:each) do
|
|
8
|
+
@dir_resource = OpenStruct.new(name: '/tmp/foo',
|
|
9
|
+
owner: 23,
|
|
10
|
+
group: 42,
|
|
11
|
+
mode: 0700)
|
|
12
|
+
|
|
13
|
+
dir = "'#{@dir_resource.name}'"
|
|
14
|
+
@create_message = "INFO: create directory: #{dir}\n"
|
|
15
|
+
@create_message_dry = "INFO: (would) create directory: #{dir}\n"
|
|
16
|
+
@create_message_debug = "DEBUG: directory already created: #{dir}\n"
|
|
17
|
+
@remove_message = "INFO: remove directory: #{dir}\n"
|
|
18
|
+
@remove_message_dry = "INFO: (would) remove directory: #{dir}\n"
|
|
19
|
+
@remove_message_debug = "DEBUG: directory already removed: #{dir}\n"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
after(:each) { FakeFS::FileSystem.clear }
|
|
23
|
+
|
|
24
|
+
def create_target_dir
|
|
25
|
+
dir = @dir_resource.name
|
|
26
|
+
FileUtils.mkdir_p(dir)
|
|
27
|
+
FileUtils.chmod(@dir_resource.mode, dir)
|
|
28
|
+
FileUtils.chown(@dir_resource.owner, @dir_resource.group, dir)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe '#updated?' do
|
|
32
|
+
it 'should return the update status if a directory was created' do
|
|
33
|
+
dir = Wright::Provider::Directory.new(@dir_resource)
|
|
34
|
+
lambda do
|
|
35
|
+
reset_logger
|
|
36
|
+
FakeFS { dir.create }
|
|
37
|
+
end.must_output @create_message
|
|
38
|
+
assert dir.updated?
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'should return the update status if a directory was not created' do
|
|
42
|
+
dir = Wright::Provider::Directory.new(@dir_resource)
|
|
43
|
+
lambda do
|
|
44
|
+
reset_logger
|
|
45
|
+
FakeFS do
|
|
46
|
+
create_target_dir
|
|
47
|
+
dir.create
|
|
48
|
+
end
|
|
49
|
+
assert !dir.updated?
|
|
50
|
+
end.must_output @create_message_debug
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'should return the update status if a directory was changed' do
|
|
54
|
+
dir = Wright::Provider::Directory.new(@dir_resource)
|
|
55
|
+
lambda do
|
|
56
|
+
reset_logger
|
|
57
|
+
FakeFS do
|
|
58
|
+
create_target_dir
|
|
59
|
+
FileUtils.chown(0, 0, @dir_resource.name)
|
|
60
|
+
dir.create
|
|
61
|
+
end
|
|
62
|
+
end.must_output @create_message
|
|
63
|
+
assert dir.updated?
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'should return the update status if a directory was removed' do
|
|
67
|
+
dir = Wright::Provider::Directory.new(@dir_resource)
|
|
68
|
+
lambda do
|
|
69
|
+
reset_logger
|
|
70
|
+
FakeFS do
|
|
71
|
+
create_target_dir
|
|
72
|
+
dir.remove
|
|
73
|
+
end
|
|
74
|
+
assert dir.updated?
|
|
75
|
+
end.must_output @remove_message
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it 'should return the update status if a directory was not removed' do
|
|
79
|
+
dir = Wright::Provider::Directory.new(@dir_resource)
|
|
80
|
+
lambda do
|
|
81
|
+
reset_logger
|
|
82
|
+
FakeFS { dir.remove }
|
|
83
|
+
assert !dir.updated?
|
|
84
|
+
end.must_output @remove_message_debug
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
describe 'dry_run' do
|
|
89
|
+
it 'should not actually create directories' do
|
|
90
|
+
dir = Wright::Provider::Directory.new(@dir_resource)
|
|
91
|
+
Wright.dry_run do
|
|
92
|
+
lambda do
|
|
93
|
+
reset_logger
|
|
94
|
+
FakeFS { dir.create }
|
|
95
|
+
end.must_output @create_message_dry
|
|
96
|
+
FakeFS { assert !File.directory?(@dir_resource.name) }
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it 'should not actually remove directories' do
|
|
101
|
+
dir = Wright::Provider::Directory.new(@dir_resource)
|
|
102
|
+
Wright.dry_run do
|
|
103
|
+
lambda do
|
|
104
|
+
reset_logger
|
|
105
|
+
FakeFS do
|
|
106
|
+
create_target_dir
|
|
107
|
+
dir.remove
|
|
108
|
+
end
|
|
109
|
+
end.must_output @remove_message_dry
|
|
110
|
+
end
|
|
111
|
+
FakeFS { assert File.directory?(@dir_resource.name) }
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
require_relative '../spec_helper'
|
|
2
|
+
|
|
3
|
+
require 'wright/provider/file'
|
|
4
|
+
require 'wright/dry_run'
|
|
5
|
+
|
|
6
|
+
describe Wright::Provider::File do
|
|
7
|
+
before(:each) do
|
|
8
|
+
@file_resource = OpenStruct.new(name: 'foo',
|
|
9
|
+
owner: 23,
|
|
10
|
+
group: 42,
|
|
11
|
+
mode: 0600,
|
|
12
|
+
content: 'Hello world')
|
|
13
|
+
|
|
14
|
+
file = "'#{@file_resource.name}'"
|
|
15
|
+
@create_message = "INFO: create file: #{file}\n"
|
|
16
|
+
@create_message_dry = "INFO: (would) create file: #{file}\n"
|
|
17
|
+
@create_message_debug = "DEBUG: file already created: #{file}\n"
|
|
18
|
+
@remove_message = "INFO: remove file: #{file}\n"
|
|
19
|
+
@remove_message_dry = "INFO: (would) remove file: #{file}\n"
|
|
20
|
+
@remove_message_debug = "DEBUG: file already removed: #{file}\n"
|
|
21
|
+
|
|
22
|
+
FakeFS { FileUtils.mkdir_p Dir.tmpdir }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
after(:each) { FakeFS::FileSystem.clear }
|
|
26
|
+
|
|
27
|
+
def create_target_file
|
|
28
|
+
file = @file_resource.name
|
|
29
|
+
File.write(file, @file_resource.content)
|
|
30
|
+
FileUtils.chmod(@file_resource.mode, file)
|
|
31
|
+
FileUtils.chown(@file_resource.owner, @file_resource.group, file)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe '#updated?' do
|
|
35
|
+
it 'should return the update status if a file was created' do
|
|
36
|
+
file = Wright::Provider::File.new(@file_resource)
|
|
37
|
+
lambda do
|
|
38
|
+
reset_logger
|
|
39
|
+
FakeFS { file.create }
|
|
40
|
+
end.must_output @create_message
|
|
41
|
+
assert file.updated?
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'should return the update status if a file was not created' do
|
|
45
|
+
file = Wright::Provider::File.new(@file_resource)
|
|
46
|
+
lambda do
|
|
47
|
+
reset_logger
|
|
48
|
+
FakeFS do
|
|
49
|
+
create_target_file
|
|
50
|
+
file.create
|
|
51
|
+
end
|
|
52
|
+
assert !file.updated?
|
|
53
|
+
end.must_output @create_message_debug
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'should return the update status if permissions were changed' do
|
|
57
|
+
file = Wright::Provider::File.new(@file_resource)
|
|
58
|
+
lambda do
|
|
59
|
+
reset_logger
|
|
60
|
+
FakeFS do
|
|
61
|
+
create_target_file
|
|
62
|
+
File.chmod(0111, @file_resource.name)
|
|
63
|
+
file.create
|
|
64
|
+
end
|
|
65
|
+
assert file.updated?
|
|
66
|
+
end.must_output @create_message
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it 'should return the update status if a file was changed' do
|
|
70
|
+
file = Wright::Provider::File.new(@file_resource)
|
|
71
|
+
lambda do
|
|
72
|
+
reset_logger
|
|
73
|
+
FakeFS do
|
|
74
|
+
create_target_file
|
|
75
|
+
File.write(@file_resource.name, 'wrong content')
|
|
76
|
+
file.create
|
|
77
|
+
end
|
|
78
|
+
end.must_output @create_message
|
|
79
|
+
assert file.updated?
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it 'should return the update status if a file was removed' do
|
|
83
|
+
file = Wright::Provider::File.new(@file_resource)
|
|
84
|
+
lambda do
|
|
85
|
+
reset_logger
|
|
86
|
+
FakeFS do
|
|
87
|
+
create_target_file
|
|
88
|
+
file.remove
|
|
89
|
+
end
|
|
90
|
+
assert file.updated?
|
|
91
|
+
end.must_output @remove_message
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it 'should return the update status if a file was not removed' do
|
|
95
|
+
file = Wright::Provider::File.new(@file_resource)
|
|
96
|
+
lambda do
|
|
97
|
+
reset_logger
|
|
98
|
+
FakeFS { file.remove }
|
|
99
|
+
assert !file.updated?
|
|
100
|
+
end.must_output @remove_message_debug
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
describe 'dry_run' do
|
|
105
|
+
it 'should not actually create files' do
|
|
106
|
+
file = Wright::Provider::File.new(@file_resource)
|
|
107
|
+
Wright.dry_run do
|
|
108
|
+
lambda do
|
|
109
|
+
reset_logger
|
|
110
|
+
FakeFS { file.create }
|
|
111
|
+
end.must_output @create_message_dry
|
|
112
|
+
FakeFS { assert !File.exist?(@file_resource.name) }
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it 'should not actually remove files' do
|
|
117
|
+
file = Wright::Provider::File.new(@file_resource)
|
|
118
|
+
Wright.dry_run do
|
|
119
|
+
lambda do
|
|
120
|
+
reset_logger
|
|
121
|
+
FakeFS do
|
|
122
|
+
create_target_file
|
|
123
|
+
file.remove
|
|
124
|
+
end
|
|
125
|
+
end.must_output @remove_message_dry
|
|
126
|
+
end
|
|
127
|
+
FakeFS { assert File.exist?(@file_resource.name) }
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Reading package lists...
|
|
2
|
+
Building dependency tree...
|
|
3
|
+
Reading state information...
|
|
4
|
+
Suggested packages:
|
|
5
|
+
distmp3 id3 id3v2 normalize-audio vorbisgain mkcue mp3gain atomicparsley
|
|
6
|
+
The following NEW packages will be installed:
|
|
7
|
+
abcde
|
|
8
|
+
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
|
|
9
|
+
Need to get 0 B/122 kB of archives.
|
|
10
|
+
After this operation, 289 kB of additional disk space will be used.
|
|
11
|
+
Selecting previously unselected package abcde.
|
|
12
|
+
(Reading database ...
|
|
13
|
+
Unpacking abcde (from .../archives/abcde_2.5.4-1_all.deb) ...
|
|
14
|
+
Processing triggers for man-db ...
|
|
15
|
+
Setting up abcde (2.5.4-1) ...
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Reading package lists...
|
|
2
|
+
Building dependency tree...
|
|
3
|
+
Reading state information...
|
|
4
|
+
Suggested packages:
|
|
5
|
+
ltrace
|
|
6
|
+
The following NEW packages will be installed:
|
|
7
|
+
htop
|
|
8
|
+
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
|
|
9
|
+
Need to get 0 B/74.9 kB of archives.
|
|
10
|
+
After this operation, 216 kB of additional disk space will be used.
|
|
11
|
+
Selecting previously unselected package htop.
|
|
12
|
+
(Reading database ...
|
|
13
|
+
Unpacking htop (from .../htop_1.0.1-1_amd64.deb) ...
|
|
14
|
+
Processing triggers for menu ...
|
|
15
|
+
Processing triggers for man-db ...
|
|
16
|
+
Processing triggers for desktop-file-utils ...
|
|
17
|
+
Processing triggers for gnome-menus ...
|
|
18
|
+
Setting up htop (1.0.1-1) ...
|
|
19
|
+
Processing triggers for menu ...
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
100
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
E: Unable to locate package unknown-package
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Reading package lists...
|
|
2
|
+
Building dependency tree...
|
|
3
|
+
Reading state information...
|
|
4
|
+
The following packages were automatically installed and are no longer required:
|
|
5
|
+
cd-discid cdparanoia libmusicbrainz-discid-perl
|
|
6
|
+
libwebservice-musicbrainz-perl vorbis-tools
|
|
7
|
+
Use 'apt-get autoremove' to remove them.
|
|
8
|
+
The following packages will be REMOVED:
|
|
9
|
+
abcde
|
|
10
|
+
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
|
|
11
|
+
After this operation, 289 kB disk space will be freed.
|
|
12
|
+
(Reading database ...
|
|
13
|
+
Removing abcde ...
|
|
14
|
+
Processing triggers for man-db ...
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0
|
|
File without changes
|