packager-dsl 0.0.1
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 +15 -0
- data/.rspec +5 -0
- data/Changes +4 -0
- data/Gemfile +12 -0
- data/LICENSE +340 -0
- data/README.md +48 -0
- data/Rakefile +37 -0
- data/bin/packager +8 -0
- data/lib/packager.rb +5 -0
- data/lib/packager/cli.rb +72 -0
- data/lib/packager/dsl.rb +55 -0
- data/lib/packager/executor.rb +63 -0
- data/lib/packager/struct.rb +80 -0
- data/lib/packager/version.rb +3 -0
- data/on_what.rb +15 -0
- data/packager.gemspec +44 -0
- data/spec/cli/context.rb +17 -0
- data/spec/cli/execute_spec.rb +79 -0
- data/spec/cli/validate_spec.rb +47 -0
- data/spec/cli/version_spec.rb +7 -0
- data/spec/dsl/args_spec.rb +16 -0
- data/spec/dsl/context.rb +5 -0
- data/spec/dsl/defaults_spec.rb +19 -0
- data/spec/dsl/dependency_spec.rb +62 -0
- data/spec/dsl/error_spec.rb +48 -0
- data/spec/dsl/files_spec.rb +46 -0
- data/spec/executor/basic_spec.rb +21 -0
- data/spec/executor/command_spec.rb +18 -0
- data/spec/executor/context.rb +4 -0
- data/spec/executor/dependency_spec.rb +46 -0
- data/spec/executor/execute_command_spec.rb +25 -0
- data/spec/executor/files_spec.rb +33 -0
- data/spec/fpm-test_spec.rb +98 -0
- data/spec/integration/context.rb +57 -0
- data/spec/integration/dependency_spec.rb +51 -0
- data/spec/integration/files_spec.rb +104 -0
- data/spec/lib/fpm/package/test.rb +27 -0
- data/spec/shared_context/workdir.rb +18 -0
- data/spec/spec_helper.rb +55 -0
- data/spec/struct/command_spec.rb +67 -0
- data/spec/struct/error_spec.rb +12 -0
- metadata +268 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require './spec/cli/context.rb'
|
|
2
|
+
describe Packager::CLI do
|
|
3
|
+
context '#validate' do
|
|
4
|
+
include_context :cli
|
|
5
|
+
|
|
6
|
+
it "handles nothing passed" do
|
|
7
|
+
expect {
|
|
8
|
+
cli.validate
|
|
9
|
+
}.to raise_error(Thor::Error, "No filenames provided for validate")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "handles a non-existent filename" do
|
|
13
|
+
expect {
|
|
14
|
+
cli.validate('foo')
|
|
15
|
+
}.to raise_error(Thor::Error, "'foo' cannot be found")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "handles an empty file" do
|
|
19
|
+
FileUtils.touch('definition')
|
|
20
|
+
expect {
|
|
21
|
+
cli.validate('definition')
|
|
22
|
+
}.to raise_error(Thor::Error, "'definition' produces nothing")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "handles a bad file" do
|
|
26
|
+
append_to_file('definition', 'package {}')
|
|
27
|
+
|
|
28
|
+
expect {
|
|
29
|
+
cli.validate('definition')
|
|
30
|
+
}.to raise_error(Thor::Error, "'definition' has the following errors:\nEvery package must have a name")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "handles a file that works" do
|
|
34
|
+
append_to_file('definition', "
|
|
35
|
+
package {
|
|
36
|
+
name 'foo'
|
|
37
|
+
version '0.0.1'
|
|
38
|
+
type 'dir'
|
|
39
|
+
}
|
|
40
|
+
")
|
|
41
|
+
|
|
42
|
+
expect(
|
|
43
|
+
capture(:stdout) { cli.validate('definition') }
|
|
44
|
+
).to eq("'definition' parses cleanly\n")
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require './spec/dsl/context.rb'
|
|
2
|
+
describe Packager::DSL do
|
|
3
|
+
context "arguments" do
|
|
4
|
+
include_context :dsl
|
|
5
|
+
|
|
6
|
+
it "handles a name in the arguments" do
|
|
7
|
+
items = parse_dsl {
|
|
8
|
+
package 'foo' do
|
|
9
|
+
version '0.0.1'
|
|
10
|
+
type 'test'
|
|
11
|
+
end
|
|
12
|
+
}
|
|
13
|
+
expect(items[0].name).to eq('foo')
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
data/spec/dsl/context.rb
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require './spec/dsl/context.rb'
|
|
2
|
+
describe Packager::DSL do
|
|
3
|
+
context "default type" do
|
|
4
|
+
include_context :dsl
|
|
5
|
+
|
|
6
|
+
before(:all) { Packager::DSL.default_type('unknown') }
|
|
7
|
+
after(:all) { Packager::DSL.default_type = nil }
|
|
8
|
+
|
|
9
|
+
it "will use the default type" do
|
|
10
|
+
items = parse_dsl {
|
|
11
|
+
package {
|
|
12
|
+
name 'foo'
|
|
13
|
+
version '0.0.1'
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
expect(items[0].type).to eq('unknown')
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require './spec/dsl/context.rb'
|
|
2
|
+
describe Packager::DSL do
|
|
3
|
+
include_context :dsl
|
|
4
|
+
|
|
5
|
+
context "requires" do
|
|
6
|
+
it "handles a dependency" do
|
|
7
|
+
items = parse_dsl {
|
|
8
|
+
package {
|
|
9
|
+
name 'foo'
|
|
10
|
+
version '0.0.1'
|
|
11
|
+
type 'test'
|
|
12
|
+
requires 'foo'
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
expect(items[0].requires).to be_instance_of(Array)
|
|
16
|
+
expect(items[0].requires[0]).to eq('foo')
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "handles multiple dependencies" do
|
|
20
|
+
items = parse_dsl {
|
|
21
|
+
package {
|
|
22
|
+
name 'foo'
|
|
23
|
+
version '0.0.1'
|
|
24
|
+
type 'test'
|
|
25
|
+
requires 'foo', 'bar'
|
|
26
|
+
requires 'baz'
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
expect(items[0].requires).to be_instance_of(Array)
|
|
30
|
+
expect(items[0].requires).to eq([ 'foo', 'bar', 'baz' ])
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context "provides" do
|
|
35
|
+
it "handles a provides" do
|
|
36
|
+
items = parse_dsl {
|
|
37
|
+
package {
|
|
38
|
+
name 'foo'
|
|
39
|
+
version '0.0.1'
|
|
40
|
+
type 'test'
|
|
41
|
+
provides 'foo'
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
expect(items[0].provides).to be_instance_of(Array)
|
|
45
|
+
expect(items[0].provides[0]).to eq('foo')
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "handles multiple dependencies" do
|
|
49
|
+
items = parse_dsl {
|
|
50
|
+
package {
|
|
51
|
+
name 'foo'
|
|
52
|
+
version '0.0.1'
|
|
53
|
+
type 'test'
|
|
54
|
+
provides 'foo', 'bar'
|
|
55
|
+
provides 'baz'
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
expect(items[0].provides).to be_instance_of(Array)
|
|
59
|
+
expect(items[0].provides).to eq([ 'foo', 'bar', 'baz' ])
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require './spec/dsl/context.rb'
|
|
2
|
+
describe Packager::DSL do
|
|
3
|
+
context "error handling" do
|
|
4
|
+
include_context :dsl
|
|
5
|
+
|
|
6
|
+
it "reject an empty package" do
|
|
7
|
+
expect {
|
|
8
|
+
parse_dsl { package {} }
|
|
9
|
+
}.to raise_error("Every package must have a name")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "reject a package without a name" do
|
|
13
|
+
expect {
|
|
14
|
+
parse_dsl { package { version '0.0.1' } }
|
|
15
|
+
}.to raise_error("Every package must have a name")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context "for versions" do
|
|
19
|
+
it "reject a package without a version" do
|
|
20
|
+
expect {
|
|
21
|
+
parse_dsl { package { name 'foo' } }
|
|
22
|
+
}.to raise_error("Every package must have a version")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "rejects a package with a bad version" do
|
|
26
|
+
expect {
|
|
27
|
+
parse_dsl {
|
|
28
|
+
package {
|
|
29
|
+
name 'foo'
|
|
30
|
+
version 'b'
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}.to raise_error("'b' is not a legal version string")
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "rejects a package without a type" do
|
|
38
|
+
expect {
|
|
39
|
+
parse_dsl {
|
|
40
|
+
package {
|
|
41
|
+
name 'foo'
|
|
42
|
+
version '0.0.1'
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}.to raise_error("Every package must have a type")
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require './spec/dsl/context.rb'
|
|
2
|
+
describe Packager::DSL do
|
|
3
|
+
context "files" do
|
|
4
|
+
include_context :dsl
|
|
5
|
+
|
|
6
|
+
it "handles one file" do
|
|
7
|
+
items = parse_dsl {
|
|
8
|
+
package {
|
|
9
|
+
name 'foo'
|
|
10
|
+
version '0.0.1'
|
|
11
|
+
type 'test'
|
|
12
|
+
file {
|
|
13
|
+
source 'foo'
|
|
14
|
+
dest 'bar'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
expect(items[0].files).to be_instance_of(Array)
|
|
19
|
+
expect(items[0].files[0].source).to eq('foo')
|
|
20
|
+
expect(items[0].files[0].dest).to eq('bar')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "handles two files" do
|
|
24
|
+
items = parse_dsl {
|
|
25
|
+
package {
|
|
26
|
+
name 'foo'
|
|
27
|
+
version '0.0.1'
|
|
28
|
+
type 'test'
|
|
29
|
+
file {
|
|
30
|
+
source 'foo'
|
|
31
|
+
dest 'bar'
|
|
32
|
+
}
|
|
33
|
+
files {
|
|
34
|
+
source 'foo2'
|
|
35
|
+
dest 'bar2'
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
expect(items[0].files).to be_instance_of(Array)
|
|
40
|
+
expect(items[0].files[0].source).to eq('foo')
|
|
41
|
+
expect(items[0].files[0].dest).to eq('bar')
|
|
42
|
+
expect(items[0].files[1].source).to eq('foo2')
|
|
43
|
+
expect(items[0].files[1].dest).to eq('bar2')
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require './spec/executor/context.rb'
|
|
2
|
+
describe Packager::Executor do
|
|
3
|
+
include_context :executor
|
|
4
|
+
|
|
5
|
+
it "creates an empty directory" do
|
|
6
|
+
item = Packager::Struct::Package.new(
|
|
7
|
+
:name => 'foo',
|
|
8
|
+
:version => '0.0.1',
|
|
9
|
+
:type => 'dir',
|
|
10
|
+
)
|
|
11
|
+
executor.execute_on([item])
|
|
12
|
+
expect(executor.commands[0]).to eq(
|
|
13
|
+
Packager::Struct::Command.new({
|
|
14
|
+
:name => 'foo',
|
|
15
|
+
:version => '0.0.1',
|
|
16
|
+
:source => 'empty',
|
|
17
|
+
:target => 'dir',
|
|
18
|
+
})
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
describe Packager::Struct::Command do
|
|
2
|
+
it "creates a FPM command correctly" do
|
|
3
|
+
cmd = Packager::Struct::Command.new(
|
|
4
|
+
:name => 'foo',
|
|
5
|
+
:version => '0.0.1',
|
|
6
|
+
:target => 'test',
|
|
7
|
+
)
|
|
8
|
+
cmd.add_directory('foo')
|
|
9
|
+
expect(cmd.to_system).to eq([
|
|
10
|
+
'fpm',
|
|
11
|
+
'--name', 'foo',
|
|
12
|
+
'--version', '0.0.1',
|
|
13
|
+
'-s', 'dir',
|
|
14
|
+
'-t', 'test',
|
|
15
|
+
'foo',
|
|
16
|
+
])
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require './spec/executor/context.rb'
|
|
2
|
+
describe Packager::Executor do
|
|
3
|
+
include_context :executor
|
|
4
|
+
|
|
5
|
+
context "dependencies" do
|
|
6
|
+
it "handles a dependency" do
|
|
7
|
+
item = Packager::Struct::Package.new(
|
|
8
|
+
:name => 'foo',
|
|
9
|
+
:version => '0.0.1',
|
|
10
|
+
:type => 'test',
|
|
11
|
+
:requires => [ 'foo' ],
|
|
12
|
+
)
|
|
13
|
+
executor.execute_on([item])
|
|
14
|
+
expect(executor.commands[0]).to eq(
|
|
15
|
+
Packager::Struct::Command.new({
|
|
16
|
+
:name => 'foo',
|
|
17
|
+
:version => '0.0.1',
|
|
18
|
+
:source => 'empty',
|
|
19
|
+
:target => 'test',
|
|
20
|
+
:requires => [ 'foo' ],
|
|
21
|
+
})
|
|
22
|
+
)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
context "provides" do
|
|
27
|
+
it "handles a provides" do
|
|
28
|
+
item = Packager::Struct::Package.new(
|
|
29
|
+
:name => 'foo',
|
|
30
|
+
:version => '0.0.1',
|
|
31
|
+
:type => 'test',
|
|
32
|
+
:provides => [ 'foo' ],
|
|
33
|
+
)
|
|
34
|
+
executor.execute_on([item])
|
|
35
|
+
expect(executor.commands[0]).to eq(
|
|
36
|
+
Packager::Struct::Command.new({
|
|
37
|
+
:name => 'foo',
|
|
38
|
+
:version => '0.0.1',
|
|
39
|
+
:source => 'empty',
|
|
40
|
+
:target => 'test',
|
|
41
|
+
:provides => [ 'foo' ],
|
|
42
|
+
})
|
|
43
|
+
)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
describe Packager::Executor do
|
|
2
|
+
class Packager::Struct::TestCommand < Packager::Struct.new(:command)
|
|
3
|
+
def to_system
|
|
4
|
+
command
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
context "#execute_command" do
|
|
9
|
+
it "handles errors" do
|
|
10
|
+
cmd = Packager::Struct::TestCommand.new(
|
|
11
|
+
:command => ["echo '{:error=>\"foo\"}'"]
|
|
12
|
+
)
|
|
13
|
+
expect {
|
|
14
|
+
subject.execute_command(cmd)
|
|
15
|
+
}.to raise_error('foo')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "handles success" do
|
|
19
|
+
cmd = Packager::Struct::TestCommand.new(
|
|
20
|
+
:command => ["echo '{:path=>\"foo\"}'"]
|
|
21
|
+
)
|
|
22
|
+
expect(subject.execute_command(cmd)).to eq('foo')
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require './spec/executor/context.rb'
|
|
2
|
+
require './spec/shared_context/workdir.rb'
|
|
3
|
+
describe Packager::Executor do
|
|
4
|
+
include_context :executor
|
|
5
|
+
include_context :workdir
|
|
6
|
+
|
|
7
|
+
it "creates a package with one file" do
|
|
8
|
+
FileUtils.chdir(sourcedir) do
|
|
9
|
+
FileUtils.touch('file1')
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
item = Packager::Struct::Package.new(
|
|
13
|
+
:name => 'foo',
|
|
14
|
+
:version => '0.0.1',
|
|
15
|
+
:type => 'test',
|
|
16
|
+
:files => [
|
|
17
|
+
Packager::Struct::File.new(File.join(sourcedir, 'file1'), '/bar/file2'),
|
|
18
|
+
]
|
|
19
|
+
)
|
|
20
|
+
FileUtils.chdir(workdir) do
|
|
21
|
+
executor.execute_on([item])
|
|
22
|
+
end
|
|
23
|
+
expect(executor.commands[0]).to eq(
|
|
24
|
+
Packager::Struct::Command.new({
|
|
25
|
+
:name => 'foo',
|
|
26
|
+
:version => '0.0.1',
|
|
27
|
+
:source => 'dir',
|
|
28
|
+
:target => 'test',
|
|
29
|
+
:directories => { 'bar' => true },
|
|
30
|
+
})
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Q.V. the initial comment in spec/integration/files_spec.rb
|
|
2
|
+
#
|
|
3
|
+
# Missing features:
|
|
4
|
+
# * dependencies
|
|
5
|
+
# * before/after scripts
|
|
6
|
+
|
|
7
|
+
require 'tempfile'
|
|
8
|
+
|
|
9
|
+
require './spec/integration/context.rb'
|
|
10
|
+
require './spec/shared_context/workdir.rb'
|
|
11
|
+
describe 'FPM::Package::Test' do
|
|
12
|
+
include_context :workdir
|
|
13
|
+
include_context :test_package
|
|
14
|
+
|
|
15
|
+
# This is to get access to the 'test' FPM type in the FPM executable.
|
|
16
|
+
before(:all) {
|
|
17
|
+
includedir = File.join(@dir,'spec/lib')
|
|
18
|
+
@fpm = "ruby -I#{includedir} -rfpm/package/test `which fpm`"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
# FIXME: 2>/dev/null is to suppress a Gem::Specification complaint about JSON.
|
|
22
|
+
# After 'bundle install', Ruby 2.2 has JSON 1.8.3 and 1.8.1 (default) installed
|
|
23
|
+
# and something gets confused because both are sufficient for JSON >= 1.7.7
|
|
24
|
+
# You can disable it by setting the envvar VERBOSE=1
|
|
25
|
+
def execute(cmd)
|
|
26
|
+
cmd.unshift @fpm
|
|
27
|
+
cmd.push '2>/dev/null' unless ENV['VERBOSE'] && ENV['VERBOSE'] != '0'
|
|
28
|
+
return eval `#{cmd.join(' ')}`#
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "creates an empty package" do
|
|
32
|
+
execute([
|
|
33
|
+
'--name foo',
|
|
34
|
+
'--version 0.0.1',
|
|
35
|
+
'-s empty',
|
|
36
|
+
'-t test',
|
|
37
|
+
])
|
|
38
|
+
|
|
39
|
+
verify_test_package('foo.test', {
|
|
40
|
+
'name' => 'foo',
|
|
41
|
+
'version' => '0.0.1',
|
|
42
|
+
})
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "creates an empty package with dependencies" do
|
|
46
|
+
execute([
|
|
47
|
+
'--name foo',
|
|
48
|
+
'--version 0.0.2',
|
|
49
|
+
'--depends baz',
|
|
50
|
+
'--depends bar',
|
|
51
|
+
'-s empty',
|
|
52
|
+
'-t test',
|
|
53
|
+
])
|
|
54
|
+
|
|
55
|
+
verify_test_package('foo.test', {
|
|
56
|
+
'name' => 'foo',
|
|
57
|
+
'version' => '0.0.2',
|
|
58
|
+
'requires' => [ 'bar', 'baz' ],
|
|
59
|
+
})
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "creates an empty package with provides" do
|
|
63
|
+
execute([
|
|
64
|
+
'--name foo',
|
|
65
|
+
'--version 0.0.2',
|
|
66
|
+
'--provides baz',
|
|
67
|
+
'--provides bar',
|
|
68
|
+
'-s empty',
|
|
69
|
+
'-t test',
|
|
70
|
+
])
|
|
71
|
+
|
|
72
|
+
verify_test_package('foo.test', {
|
|
73
|
+
'name' => 'foo',
|
|
74
|
+
'version' => '0.0.2',
|
|
75
|
+
'provides' => [ 'bar', 'baz' ],
|
|
76
|
+
})
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
it "creates a package with files" do
|
|
81
|
+
append_to_file('foo', 'stuff')
|
|
82
|
+
|
|
83
|
+
execute([
|
|
84
|
+
'--name foo',
|
|
85
|
+
'--version 0.0.1',
|
|
86
|
+
'-s dir',
|
|
87
|
+
'-t test',
|
|
88
|
+
'foo'
|
|
89
|
+
])
|
|
90
|
+
|
|
91
|
+
verify_test_package('foo.test', {
|
|
92
|
+
'name' => 'foo',
|
|
93
|
+
'version' => '0.0.1',
|
|
94
|
+
}, {
|
|
95
|
+
'foo' => 'stuff',
|
|
96
|
+
})
|
|
97
|
+
end
|
|
98
|
+
end
|