packager-dsl 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,57 +1,57 @@
1
- require 'fileutils'
2
- require 'tmpdir'
3
-
4
- require './spec/shared_context/workdir.rb'
5
- RSpec.shared_context :integration do
6
- include_context :workdir
7
-
8
- before(:all) { Packager::DSL.default_type('test') }
9
- after(:all) { Packager::DSL.default_type = nil }
10
-
11
- # This is to get access to the 'test' FPM type in the FPM executable.
12
- before(:all) {
13
- Packager::Struct::Command.default_executable =
14
- "ruby -I#{File.join(@dir,'spec/lib')} -rfpm/package/test `which fpm`"
15
- }
16
- after(:all) {
17
- Packager::Struct::Command.default_executable = 'fpm'
18
- }
19
-
20
- before(:each) { $sourcedir = sourcedir }
21
- before(:all) {
22
- Packager::DSL.add_helper(:sourcedir) do |path|
23
- File.join($sourcedir, path)
24
- end
25
- }
26
- after(:all) {
27
- Packager::DSL.remove_helper(:sourcedir)
28
- }
29
- end
30
-
31
- RSpec.shared_context :test_package do
32
- # This is used to verify the FPM/test package format is created properly.
33
- def verify_test_package(name, metadata={}, files={})
34
- expect(File).to exist(name)
35
- expect(File).to exist(File.join(name, 'META.json'))
36
- expect(JSON.parse(IO.read(File.join(name, 'META.json')))).to eq({
37
- 'requires' => [],
38
- 'provides' => [],
39
- }.merge(metadata))
40
- if files.empty?
41
- expect(Dir[File.join(name, 'contents/*')].empty?).to be(true)
42
- else
43
- file_expectations = files.clone
44
- Dir[File.join(name, 'contents/**/*')].each do |filename|
45
- if File.file?(filename)
46
- content = IO.read(filename)
47
- filename.gsub! /#{File.join(name, 'contents', '')}/, ''
48
-
49
- expect(file_expectations).to have_key(filename)
50
- expect(file_expectations[filename]).to eq(content)
51
- file_expectations.delete(filename)
52
- end
53
- end
54
- expect(file_expectations).to be_empty
55
- end
56
- end
57
- end
1
+ require 'fileutils'
2
+ require 'tmpdir'
3
+
4
+ require './spec/shared_context/workdir.rb'
5
+ RSpec.shared_context :integration do
6
+ include_context :workdir
7
+
8
+ before(:all) { Packager::DSL.default_type('test') }
9
+ after(:all) { Packager::DSL.default_type = nil }
10
+
11
+ # This is to get access to the 'test' FPM type in the FPM executable.
12
+ before(:all) {
13
+ Packager::Struct::Command.default_executable =
14
+ "ruby -I#{File.join(@dir,'spec/lib')} -rfpm/package/test `which fpm`"
15
+ }
16
+ after(:all) {
17
+ Packager::Struct::Command.default_executable = 'fpm'
18
+ }
19
+
20
+ before(:each) { $sourcedir = sourcedir }
21
+ before(:all) {
22
+ Packager::DSL.add_helper(:sourcedir) do |path|
23
+ File.join($sourcedir, path)
24
+ end
25
+ }
26
+ after(:all) {
27
+ Packager::DSL.remove_helper(:sourcedir)
28
+ }
29
+ end
30
+
31
+ RSpec.shared_context :test_package do
32
+ # This is used to verify the FPM/test package format is created properly.
33
+ def verify_test_package(name, metadata={}, files={})
34
+ expect(File).to exist(name)
35
+ expect(File).to exist(File.join(name, 'META.json'))
36
+ expect(JSON.parse(IO.read(File.join(name, 'META.json')))).to eq({
37
+ 'requires' => [],
38
+ 'provides' => [],
39
+ }.merge(metadata))
40
+ if files.empty?
41
+ expect(Dir[File.join(name, 'contents/*')].empty?).to be(true)
42
+ else
43
+ file_expectations = files.clone
44
+ Dir[File.join(name, 'contents/**/*')].each do |filename|
45
+ if File.file?(filename)
46
+ content = IO.read(filename)
47
+ filename.gsub! /#{File.join(name, 'contents', '')}/, ''
48
+
49
+ expect(file_expectations).to have_key(filename)
50
+ expect(file_expectations[filename]).to eq(content)
51
+ file_expectations.delete(filename)
52
+ end
53
+ end
54
+ expect(file_expectations).to be_empty
55
+ end
56
+ end
57
+ end
@@ -1,51 +1,51 @@
1
- require './spec/integration/context.rb'
2
- describe "Packager integration" do
3
- context "dependencies" do
4
- include_context :integration
5
- include_context :test_package
6
-
7
- it "can create a package with 1 dependency" do
8
- append_to_file('definition', "
9
- package {
10
- name 'foo'
11
- version '0.0.1'
12
- requires 'bar'
13
- }
14
- ")
15
-
16
- FileUtils.chdir(workdir) do
17
- capture(:stdout) {
18
- Packager::CLI.start(['execute', './definition'])
19
- }
20
-
21
- verify_test_package('foo.test', {
22
- 'name' => 'foo',
23
- 'version' => '0.0.1',
24
- 'requires' => ['bar'],
25
- })
26
- end
27
- end
28
-
29
- it "can create a package with 1 provides" do
30
- append_to_file('definition', "
31
- package {
32
- name 'foo'
33
- version '0.0.1'
34
- provides 'bar'
35
- }
36
- ")
37
-
38
- FileUtils.chdir(workdir) do
39
- capture(:stdout) {
40
- Packager::CLI.start(['execute', './definition'])
41
- }
42
-
43
- verify_test_package('foo.test', {
44
- 'name' => 'foo',
45
- 'version' => '0.0.1',
46
- 'provides' => ['bar'],
47
- })
48
- end
49
- end
50
- end
51
- end
1
+ require './spec/integration/context.rb'
2
+ describe "Packager integration" do
3
+ context "dependencies" do
4
+ include_context :integration
5
+ include_context :test_package
6
+
7
+ it "can create a package with 1 dependency" do
8
+ append_to_file('definition', "
9
+ package {
10
+ name 'foo'
11
+ version '0.0.1'
12
+ requires 'bar'
13
+ }
14
+ ")
15
+
16
+ FileUtils.chdir(workdir) do
17
+ capture(:stdout) {
18
+ Packager::CLI.start(['execute', './definition'])
19
+ }
20
+
21
+ verify_test_package('foo.test', {
22
+ 'name' => 'foo',
23
+ 'version' => '0.0.1',
24
+ 'requires' => ['bar'],
25
+ })
26
+ end
27
+ end
28
+
29
+ it "can create a package with 1 provides" do
30
+ append_to_file('definition', "
31
+ package {
32
+ name 'foo'
33
+ version '0.0.1'
34
+ provides 'bar'
35
+ }
36
+ ")
37
+
38
+ FileUtils.chdir(workdir) do
39
+ capture(:stdout) {
40
+ Packager::CLI.start(['execute', './definition'])
41
+ }
42
+
43
+ verify_test_package('foo.test', {
44
+ 'name' => 'foo',
45
+ 'version' => '0.0.1',
46
+ 'provides' => ['bar'],
47
+ })
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,104 +1,104 @@
1
- # Because of the vagaries of producing OS-specific packages on varying platforms,
2
- # we will test command execution using a new output target for FPM called 'test.
3
- # This target is based on the 'dir' target and exists in spec/lib.
4
- #
5
- # Note: We assume that fpm produces good packages of other types, given a correct
6
- # invocations.
7
-
8
- require './spec/integration/context.rb'
9
- describe "Packager integration" do
10
- context 'files' do
11
- include_context :integration
12
- include_context :test_package
13
-
14
- it "can create a package with no files" do
15
- append_to_file('definition', "
16
- package {
17
- name 'foo'
18
- version '0.0.1'
19
- }
20
- ")
21
-
22
- FileUtils.chdir(workdir) do
23
- capture(:stdout) {
24
- Packager::CLI.start(['execute', './definition'])
25
- }
26
-
27
- verify_test_package('foo.test', {
28
- 'name' => 'foo',
29
- 'version' => '0.0.1',
30
- })
31
- end
32
- end
33
-
34
- it "can create a package with one file" do
35
- FileUtils.chdir(sourcedir) do
36
- FileUtils.touch('file1')
37
- end
38
-
39
- append_to_file('definition', "
40
- package {
41
- name 'foo'
42
- version '0.0.1'
43
-
44
- file {
45
- source sourcedir('file1')
46
- dest '/foo/bar/file2'
47
- }
48
- }
49
- ")
50
-
51
- # Stub out execute_command
52
- FileUtils.chdir(workdir) do
53
- capture(:stdout) {
54
- Packager::CLI.start(['execute', './definition'])
55
- }
56
-
57
- verify_test_package('foo.test', {
58
- 'name' => 'foo',
59
- 'version' => '0.0.1',
60
- }, {
61
- 'foo/bar/file2' => '',
62
- })
63
- end
64
- end
65
-
66
- it "can create a package with two files" do
67
- FileUtils.chdir(sourcedir) do
68
- FileUtils.touch('file1')
69
- append_to_file('file3', 'stuff')
70
- end
71
-
72
- append_to_file('definition', "
73
- package {
74
- name 'foo'
75
- version '0.0.1'
76
-
77
- file {
78
- source sourcedir('file1')
79
- dest '/foo/bar/file2'
80
- }
81
-
82
- file {
83
- source sourcedir('file3')
84
- dest '/bar/foo/file4'
85
- }
86
- }
87
- ")
88
-
89
- FileUtils.chdir(workdir) do
90
- capture(:stdout) {
91
- Packager::CLI.start(['execute', './definition'])
92
- }
93
-
94
- verify_test_package('foo.test', {
95
- 'name' => 'foo',
96
- 'version' => '0.0.1',
97
- }, {
98
- 'foo/bar/file2' => '',
99
- 'bar/foo/file4' => 'stuff',
100
- })
101
- end
102
- end
103
- end
104
- end
1
+ # Because of the vagaries of producing OS-specific packages on varying platforms,
2
+ # we will test command execution using a new output target for FPM called 'test.
3
+ # This target is based on the 'dir' target and exists in spec/lib.
4
+ #
5
+ # Note: We assume that fpm produces good packages of other types, given a correct
6
+ # invocations.
7
+
8
+ require './spec/integration/context.rb'
9
+ describe "Packager integration" do
10
+ context 'files' do
11
+ include_context :integration
12
+ include_context :test_package
13
+
14
+ it "can create a package with no files" do
15
+ append_to_file('definition', "
16
+ package {
17
+ name 'foo'
18
+ version '0.0.1'
19
+ }
20
+ ")
21
+
22
+ FileUtils.chdir(workdir) do
23
+ capture(:stdout) {
24
+ Packager::CLI.start(['execute', './definition'])
25
+ }
26
+
27
+ verify_test_package('foo.test', {
28
+ 'name' => 'foo',
29
+ 'version' => '0.0.1',
30
+ })
31
+ end
32
+ end
33
+
34
+ it "can create a package with one file" do
35
+ FileUtils.chdir(sourcedir) do
36
+ FileUtils.touch('file1')
37
+ end
38
+
39
+ append_to_file('definition', "
40
+ package {
41
+ name 'foo'
42
+ version '0.0.1'
43
+
44
+ file {
45
+ source sourcedir('file1')
46
+ dest '/foo/bar/file2'
47
+ }
48
+ }
49
+ ")
50
+
51
+ # Stub out execute_command
52
+ FileUtils.chdir(workdir) do
53
+ capture(:stdout) {
54
+ Packager::CLI.start(['execute', './definition'])
55
+ }
56
+
57
+ verify_test_package('foo.test', {
58
+ 'name' => 'foo',
59
+ 'version' => '0.0.1',
60
+ }, {
61
+ 'foo/bar/file2' => '',
62
+ })
63
+ end
64
+ end
65
+
66
+ it "can create a package with two files" do
67
+ FileUtils.chdir(sourcedir) do
68
+ FileUtils.touch('file1')
69
+ append_to_file('file3', 'stuff')
70
+ end
71
+
72
+ append_to_file('definition', "
73
+ package {
74
+ name 'foo'
75
+ version '0.0.1'
76
+
77
+ file {
78
+ source sourcedir('file1')
79
+ dest '/foo/bar/file2'
80
+ }
81
+
82
+ file {
83
+ source sourcedir('file3')
84
+ dest '/bar/foo/file4'
85
+ }
86
+ }
87
+ ")
88
+
89
+ FileUtils.chdir(workdir) do
90
+ capture(:stdout) {
91
+ Packager::CLI.start(['execute', './definition'])
92
+ }
93
+
94
+ verify_test_package('foo.test', {
95
+ 'name' => 'foo',
96
+ 'version' => '0.0.1',
97
+ }, {
98
+ 'foo/bar/file2' => '',
99
+ 'bar/foo/file4' => 'stuff',
100
+ })
101
+ end
102
+ end
103
+ end
104
+ end
@@ -1,27 +1,27 @@
1
- require 'fpm/package/dir'
2
-
3
- require 'fileutils'
4
-
5
- class FPM::Package::Test < FPM::Package::Dir
6
- # Trigger the inherited capture of subclasses.
7
- FPM::Package.inherited(FPM::Package::Test)
8
-
9
- def output(output_path)
10
- output_check(output_path)
11
-
12
- # We have to create the ouput_path so that the Dir type will write out to the
13
- # contents subdirectory.
14
- FileUtils.mkdir_p output_path
15
- super(File.join(output_path, 'contents'))
16
-
17
- # Write out the META.json file.
18
- File.open(File.join(output_path, 'META.json'), 'w') do |f|
19
- f.write({
20
- :name => name,
21
- :version => version,
22
- :requires => dependencies.sort,
23
- :provides => provides.sort,
24
- }.to_json)
25
- end
26
- end
27
- end
1
+ require 'fpm/package/dir'
2
+
3
+ require 'fileutils'
4
+
5
+ class FPM::Package::Test < FPM::Package::Dir
6
+ # Trigger the inherited capture of subclasses.
7
+ FPM::Package.inherited(FPM::Package::Test)
8
+
9
+ def output(output_path)
10
+ output_check(output_path)
11
+
12
+ # We have to create the ouput_path so that the Dir type will write out to the
13
+ # contents subdirectory.
14
+ FileUtils.mkdir_p output_path
15
+ super(File.join(output_path, 'contents'))
16
+
17
+ # Write out the META.json file.
18
+ File.open(File.join(output_path, 'META.json'), 'w') do |f|
19
+ f.write({
20
+ :name => name,
21
+ :version => version,
22
+ :requires => dependencies.sort,
23
+ :provides => provides.sort,
24
+ }.to_json)
25
+ end
26
+ end
27
+ end