codestrap 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.travis.yml +4 -0
- data/.yardopts +3 -0
- data/BOILERPLATE.md +151 -0
- data/CODESTRAPFILE.md +28 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +13 -0
- data/README.md +69 -0
- data/Rakefile +51 -0
- data/bin/strap +8 -0
- data/bin/upstrap +8 -0
- data/codestrap.gemspec +37 -0
- data/config/projects/codestrap.rb +22 -0
- data/config/software/codestrap.rb +20 -0
- data/config/software/ruby.rb +247 -0
- data/config/software/zlib.rb +86 -0
- data/features/client.feature +99 -0
- data/features/fixtures/client/home/codestrap/bin/.empty +0 -0
- data/features/fixtures/client/home/codestrap/content/bash.erb +3 -0
- data/features/fixtures/client/home/codestrap/content/gem/dir/file +0 -0
- data/features/fixtures/client/home/codestrap/content/gem/dir/template +3 -0
- data/features/fixtures/client/home/codestrap/content/gem/file +1 -0
- data/features/fixtures/client/home/codestrap/content/gem/template +3 -0
- data/features/fixtures/client/home/codestrap/content/local_remote.erb +1 -0
- data/features/fixtures/client/home/codestrap/content/local_remote/dir/file +0 -0
- data/features/fixtures/client/home/codestrap/content/local_remote/dir/template +3 -0
- data/features/fixtures/client/home/codestrap/content/local_remote/file +1 -0
- data/features/fixtures/client/home/codestrap/content/local_remote/template +3 -0
- data/features/fixtures/client/home/codestrap/objects/local.json +3 -0
- data/features/fixtures/client/output/.empty +0 -0
- data/features/fixtures/client/var/lib/codestrap/bin/.empty +0 -0
- data/features/fixtures/client/var/lib/codestrap/content/bashremote.erb +3 -0
- data/features/fixtures/client/var/lib/codestrap/content/gemremote/dir/file +0 -0
- data/features/fixtures/client/var/lib/codestrap/content/gemremote/dir/template +3 -0
- data/features/fixtures/client/var/lib/codestrap/content/gemremote/file +0 -0
- data/features/fixtures/client/var/lib/codestrap/content/gemremote/template +3 -0
- data/features/fixtures/client/var/lib/codestrap/content/remote_local.erb +1 -0
- data/features/fixtures/client/var/lib/codestrap/content/remote_local/dir/file +0 -0
- data/features/fixtures/client/var/lib/codestrap/content/remote_local/dir/template +3 -0
- data/features/fixtures/client/var/lib/codestrap/content/remote_local/file +1 -0
- data/features/fixtures/client/var/lib/codestrap/content/remote_local/template +3 -0
- data/features/fixtures/client/var/lib/codestrap/content/remote_remote.erb +1 -0
- data/features/fixtures/client/var/lib/codestrap/content/remote_remote/dir/file +0 -0
- data/features/fixtures/client/var/lib/codestrap/content/remote_remote/dir/template +3 -0
- data/features/fixtures/client/var/lib/codestrap/content/remote_remote/file +0 -0
- data/features/fixtures/client/var/lib/codestrap/content/remote_remote/template +3 -0
- data/features/fixtures/client/var/lib/codestrap/objects/remote.json +3 -0
- data/features/fixtures/logging/home/logging/codestrap/bin/stubdirectory/.empty +0 -0
- data/features/fixtures/logging/home/logging/codestrap/bin/stubnotlink +0 -0
- data/features/fixtures/logging/home/logging/codestrap/content/.empty +0 -0
- data/features/fixtures/logging/home/logging/codestrap/objects/.empty +0 -0
- data/features/fixtures/server/mixed/var/lib/stub/content/address.erb +3 -0
- data/features/fixtures/server/mixed/var/lib/stub/content/cell.erb +3 -0
- data/features/fixtures/server/mixed/var/lib/stub/content/email.erb +3 -0
- data/features/fixtures/server/mixed/var/lib/stub/content/mobile.erb +3 -0
- data/features/fixtures/server/mixed/var/lib/stub/content/name.erb +3 -0
- data/features/fixtures/server/mixed/var/lib/stub/content/phone.erb +3 -0
- data/features/fixtures/server/mixed/var/lib/stub/content/puppetmodule/Modulefile +12 -0
- data/features/fixtures/server/mixed/var/lib/stub/content/puppetmodule/README +17 -0
- data/features/fixtures/server/mixed/var/lib/stub/content/puppetmodule/manifests/init.pp +42 -0
- data/features/fixtures/server/mixed/var/lib/stub/content/puppetmodule/spec/spec_helper.rb +18 -0
- data/features/fixtures/server/mixed/var/lib/stub/content/puppetmodule/tests/init.pp +13 -0
- data/features/fixtures/server/mixed/var/lib/stub/objects/contact.json +8 -0
- data/features/fixtures/server/mixed/var/lib/stub/objects/shadow/contact.json +8 -0
- data/features/fixtures/strap/projects/etc/.empty +0 -0
- data/features/fixtures/strap/projects/home/user/dir/bin/.empty +0 -0
- data/features/fixtures/strap/projects/home/user/dir/content/puppetmodule/Modulefile +12 -0
- data/features/fixtures/strap/projects/home/user/dir/content/puppetmodule/README +17 -0
- data/features/fixtures/strap/projects/home/user/dir/content/puppetmodule/manifests/:stub:project.name:/subclass.pp +3 -0
- data/features/fixtures/strap/projects/home/user/dir/content/puppetmodule/manifests/init.pp +42 -0
- data/features/fixtures/strap/projects/home/user/dir/content/puppetmodule/spec/spec_helper.rb +18 -0
- data/features/fixtures/strap/projects/home/user/dir/content/puppetmodule/tests/init.pp +13 -0
- data/features/fixtures/strap/projects/home/user/dir/objects/contact.json +8 -0
- data/features/fixtures/strap/projects/home/user/dir/objects/shadow/contact.json +8 -0
- data/features/fixtures/strap/projects/output/.empty +0 -0
- data/features/fixtures/stub/contact/etc/.empty +0 -0
- data/features/fixtures/stub/contact/home/user/dir/bin/.empty +0 -0
- data/features/fixtures/stub/contact/home/user/dir/content/address.erb +3 -0
- data/features/fixtures/stub/contact/home/user/dir/content/cell.erb +3 -0
- data/features/fixtures/stub/contact/home/user/dir/content/email.erb +3 -0
- data/features/fixtures/stub/contact/home/user/dir/content/mobile.erb +3 -0
- data/features/fixtures/stub/contact/home/user/dir/content/name.erb +3 -0
- data/features/fixtures/stub/contact/home/user/dir/content/phone.erb +3 -0
- data/features/fixtures/stub/contact/home/user/dir/objects/contact.json +8 -0
- data/features/fixtures/stub/contact/home/user/dir/objects/shadow/contact.json +8 -0
- data/features/fixtures/stub/contact/output/.empty +0 -0
- data/features/fixtures/stub/date/etc/.empty +0 -0
- data/features/fixtures/stub/date/home/user/stub/bin/.empty +0 -0
- data/features/fixtures/stub/date/home/user/stub/content/day.erb +3 -0
- data/features/fixtures/stub/date/home/user/stub/content/hour.erb +3 -0
- data/features/fixtures/stub/date/home/user/stub/content/minute.erb +3 -0
- data/features/fixtures/stub/date/home/user/stub/content/month.erb +3 -0
- data/features/fixtures/stub/date/home/user/stub/content/second.erb +3 -0
- data/features/fixtures/stub/date/home/user/stub/content/year.erb +3 -0
- data/features/fixtures/stub/date/home/user/stub/objects/.empty +0 -0
- data/features/fixtures/stub/date/output/.empty +0 -0
- data/features/fixtures/stub/script/etc/.empty +0 -0
- data/features/fixtures/stub/script/home/user/stub/bin/.empty +0 -0
- data/features/fixtures/stub/script/home/user/stub/content/credentials.erb +6 -0
- data/features/fixtures/stub/script/home/user/stub/objects/credentials.rb +11 -0
- data/features/fixtures/stub/script/output/.empty +0 -0
- data/features/logging.feature +39 -0
- data/features/object_scripts.feature +13 -0
- data/features/server.feature +36 -0
- data/features/step_definitions/client_steps.rb +99 -0
- data/features/step_definitions/logging_steps.rb +65 -0
- data/features/step_definitions/object_scripts_steps.rb +26 -0
- data/features/step_definitions/server_steps.rb +112 -0
- data/features/step_definitions/strap_steps.rb +69 -0
- data/features/step_definitions/stub_option_simple_steps.rb +31 -0
- data/features/step_definitions/stub_steps.rb +94 -0
- data/features/strap.feature +34 -0
- data/features/stub.feature +157 -0
- data/features/stub_option_simple.feature +14 -0
- data/features/stub_packages.feature +15 -0
- data/features/support/env.rb +197 -0
- data/lib/codestrap.rb +415 -0
- data/lib/codestrap/cli.rb +76 -0
- data/lib/codestrap/client.rb +179 -0
- data/lib/codestrap/config.rb +199 -0
- data/lib/codestrap/log.rb +56 -0
- data/lib/codestrap/mixin.rb +20 -0
- data/lib/codestrap/namespace.rb +19 -0
- data/lib/codestrap/object/abstract.rb +33 -0
- data/lib/codestrap/object/factory.rb +86 -0
- data/lib/codestrap/object/standard/datetime.rb +24 -0
- data/lib/codestrap/object/standard/files.rb +40 -0
- data/lib/codestrap/object/standard/project.rb +33 -0
- data/lib/codestrap/object/standard/rest.rb +30 -0
- data/lib/codestrap/patch.rb +122 -0
- data/lib/codestrap/server/rest.rb +177 -0
- data/lib/codestrap/server/version.rb +5 -0
- data/lib/codestrap/strap/abstract.rb +135 -0
- data/lib/codestrap/strap/factory.rb +85 -0
- data/lib/codestrap/strap/standard.rb +95 -0
- data/lib/codestrap/stub/abstract.rb +156 -0
- data/lib/codestrap/stub/factory.rb +87 -0
- data/lib/codestrap/stub/standard.rb +23 -0
- data/lib/codestrap/version.rb +3 -0
- data/omnibus.rb +53 -0
- data/package-scripts/codestrap/postinst +25 -0
- data/package-scripts/codestrap/postrm +17 -0
- data/package-scripts/codestrap/preinst +7 -0
- data/package-scripts/codestrap/prerm +15 -0
- data/resources/codestrap/pkg/background.png +0 -0
- data/resources/codestrap/pkg/distribution.xml.erb +22 -0
- data/resources/codestrap/pkg/license.html.erb +202 -0
- data/resources/codestrap/pkg/welcome.html.erb +7 -0
- metadata +466 -0
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,39 @@
|
|
1
|
+
Feature: Programing supports logging
|
2
|
+
If an exception occurs in order to receive a meaningful message
|
3
|
+
as a command line user
|
4
|
+
the command needs to support adequate logging
|
5
|
+
|
6
|
+
Scenario Outline: Logging
|
7
|
+
Given logging tmp directory
|
8
|
+
And logging fixtures file "fixtures.yaml" with:
|
9
|
+
"""
|
10
|
+
links: logging/home/logging/codestrap/bin
|
11
|
+
codestrapfile: |
|
12
|
+
Codestrapfile.config do |conf|
|
13
|
+
conf.local.base = [ 'logging/home/logging/codestrap' ]
|
14
|
+
conf.local.urls = 'http://127.0.0.1:4567/rest/capability.json'
|
15
|
+
end
|
16
|
+
commands:
|
17
|
+
stubcommand:
|
18
|
+
output: logging/output/command
|
19
|
+
output?: false
|
20
|
+
stderr:
|
21
|
+
- Could not find template "command".
|
22
|
+
exit: 1
|
23
|
+
strapproject:
|
24
|
+
output: logging/output/project
|
25
|
+
output?: false
|
26
|
+
stderr:
|
27
|
+
- Could not find project "project".
|
28
|
+
exit: 1
|
29
|
+
"""
|
30
|
+
And logging fixture "<command>"
|
31
|
+
And logging file linking
|
32
|
+
When logging command is executed
|
33
|
+
Then logging output may be generated
|
34
|
+
And logging STDERR contains a message
|
35
|
+
And logging exits
|
36
|
+
Examples:
|
37
|
+
| command |
|
38
|
+
| stubcommand |
|
39
|
+
| strapproject |
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Feature: Supports script object creation
|
2
|
+
The command supports objects created from JSON. The objects
|
3
|
+
can be used in the template.
|
4
|
+
|
5
|
+
Scenario Outline: creating a script object
|
6
|
+
Given a script directory "<dir>"
|
7
|
+
And a script "<script>"
|
8
|
+
When a script run to create an object
|
9
|
+
Then the objects JSON syntax is valid
|
10
|
+
And a object is created
|
11
|
+
Examples:
|
12
|
+
| dir | script |
|
13
|
+
| features/fixtures/stub/script/home/user/stub/objects | credentials.rb |
|
@@ -0,0 +1,36 @@
|
|
1
|
+
Feature: Remotely serve straps and stubs
|
2
|
+
In order to serve stubs and straps remotely
|
3
|
+
As a user
|
4
|
+
I want a server that supports both types
|
5
|
+
|
6
|
+
Scenario Outline: Serve a stub or strap
|
7
|
+
Given server tmp directory
|
8
|
+
And server fixtures file "fixtures.yaml" with:
|
9
|
+
"""
|
10
|
+
- type: stub
|
11
|
+
template: email
|
12
|
+
codestrapfile: |
|
13
|
+
Codestrapfile.config do |conf|
|
14
|
+
conf.server.base = ['server/mixed/var/lib/stub']
|
15
|
+
conf.local.urls = 'http://127.0.0.1:4567/rest/capability.json'
|
16
|
+
end
|
17
|
+
- type: strap
|
18
|
+
template: puppetmodule
|
19
|
+
codestrapfile: |
|
20
|
+
Codestrapfile.config do |conf|
|
21
|
+
conf.server.base = ['server/mixed/var/lib/stub']
|
22
|
+
conf.local.urls = 'http://127.0.0.1:4567/rest/capability.json'
|
23
|
+
end
|
24
|
+
"""
|
25
|
+
And server fixture "<number>"
|
26
|
+
And server capbility rest "/rest/capability.json" is valid
|
27
|
+
And server object rest "/rest/objects.json" is valid
|
28
|
+
And server stub metadata rest "/rest/stub/metadata.json" is valid
|
29
|
+
And server strap metadata rest "/rest/strap/metadata.json" is valid
|
30
|
+
And server list contains the correct keys
|
31
|
+
Then server file should contain the correct content
|
32
|
+
And server returns the right http code
|
33
|
+
Examples:
|
34
|
+
| number |
|
35
|
+
| 0 |
|
36
|
+
| 1 |
|
@@ -0,0 +1,99 @@
|
|
1
|
+
Given(/^client tmp directory$/) do
|
2
|
+
unless @client_tmp
|
3
|
+
@client_tmp = Dir.mktmpdir
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
And(/^client fixtures file "([^"]*)" with:$/) do |yaml, text|
|
8
|
+
@client_fixture_file = File.join(@client_tmp, yaml)
|
9
|
+
file = File.open(@client_fixture_file, 'w')
|
10
|
+
file.write(text)
|
11
|
+
file.close
|
12
|
+
@fixture_hash = YAML.load(text)
|
13
|
+
sf_data = @fixture_hash['codestrapfile']
|
14
|
+
sf_path = File.join(@client_tmp, 'Codestrapfile')
|
15
|
+
file = File.open(sf_path, 'w')
|
16
|
+
file.write(sf_data)
|
17
|
+
file.close
|
18
|
+
ENV['CODESTRAPFILE'] = sf_path
|
19
|
+
@links = @fixture_hash['links']
|
20
|
+
@testtools.path_reset
|
21
|
+
@testtools.path_unshift(@links)
|
22
|
+
end
|
23
|
+
|
24
|
+
And(/^client fixture "([^"]+)"$/) do |command|
|
25
|
+
@command = command
|
26
|
+
@fixture_cur = @fixture_hash['commands'][command]
|
27
|
+
@output = @fixture_cur['output']
|
28
|
+
@test = @fixture_cur['test']
|
29
|
+
end
|
30
|
+
|
31
|
+
And(/^client generate command is called$/) do
|
32
|
+
capture = Capture::Cli.inline do
|
33
|
+
args = %w[strap --generate]
|
34
|
+
Codestrap::Core.new(args).execute!
|
35
|
+
end
|
36
|
+
expect(capture.object_exit.status).to eql(0)
|
37
|
+
end
|
38
|
+
|
39
|
+
Then(/^client runs "stub output"$/) do
|
40
|
+
if @command =~ /^stub/
|
41
|
+
FileUtils.rm_rf(@output) if File.exist?(@output)
|
42
|
+
@client_capture = Capture::Cli.inline do
|
43
|
+
args = [@command, @output]
|
44
|
+
Codestrap::Core.new(args).execute!
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
And(/^client runs "strap output"$/) do
|
50
|
+
if @command =~ /^strap/
|
51
|
+
FileUtils.rm_rf(@output) if File.exist?(@output)
|
52
|
+
args = [@command, @output]
|
53
|
+
@client_capture = Capture::Cli.inline do
|
54
|
+
Codestrap::Core.new(args).execute!
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
And(/^client stub exit code is (\d+)$/) do |exit_code|
|
60
|
+
if @command =~ /^stub/
|
61
|
+
expect(@client_capture.object_exit.status).to eql(exit_code.to_i)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
And(/^client strap exit code is (\d+)$/) do |exit_code|
|
66
|
+
if @command =~ /^stub/
|
67
|
+
expect(@client_capture.object_exit.status).to eql(exit_code.to_i)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
And(/^client stub has the correct interpolated values$/) do
|
72
|
+
if @command =~ /^stub/
|
73
|
+
Tools::Test.contents(@test) do |content, str, bool|
|
74
|
+
case bool
|
75
|
+
when 'true'
|
76
|
+
expect(content).to include(str)
|
77
|
+
when 'false'
|
78
|
+
expect(content).not_to include(str)
|
79
|
+
else
|
80
|
+
fail "Expecting boolean got #{bool.to_s}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
And(/^client boilerplate has the correct interpolated values$/) do
|
87
|
+
if @command =~ /^strap/
|
88
|
+
Tools::Test.contents(@test) do |content, str, bool|
|
89
|
+
case bool
|
90
|
+
when 'true'
|
91
|
+
expect(content).to include(str)
|
92
|
+
when 'false'
|
93
|
+
expect(content).not_to include(str)
|
94
|
+
else
|
95
|
+
fail "Expecting boolean got #{bool.to_s}"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
Given(/^logging tmp directory$/) do
|
2
|
+
unless @logging_tmp
|
3
|
+
@logging_tmp = Dir.mktmpdir
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
And(/^logging fixtures file "([^"]*)" with:$/) do |yaml, text|
|
8
|
+
@logging_fixture_file = File.join(@logging_tmp, yaml)
|
9
|
+
file = File.open(@logging_fixture_file, 'w')
|
10
|
+
file.write(text)
|
11
|
+
file.close
|
12
|
+
@fixture_hash = YAML.load(text)
|
13
|
+
sf_data = @fixture_hash['codestrapfile']
|
14
|
+
sf_path = File.join(@logging_tmp, 'Codestrapfile')
|
15
|
+
file = File.open(sf_path, 'w')
|
16
|
+
file.write(sf_data)
|
17
|
+
file.close
|
18
|
+
ENV['CODESTRAPFILE'] = sf_path
|
19
|
+
@links = @fixture_hash['links']
|
20
|
+
@testtools.path_reset
|
21
|
+
@testtools.path_unshift(@links)
|
22
|
+
end
|
23
|
+
|
24
|
+
And(/^logging fixture "([^"]*)"$/) do |command|
|
25
|
+
@command = command
|
26
|
+
@fixture_cur = @fixture_hash['commands'][command]
|
27
|
+
@output = @fixture_cur['output']
|
28
|
+
@has_output = @fixture_cur['output?']
|
29
|
+
@test = @fixture_cur['test']
|
30
|
+
@stderr = @fixture_cur['stderr']
|
31
|
+
@exit = @fixture_cur['exit'].to_i
|
32
|
+
end
|
33
|
+
|
34
|
+
And(/^logging file linking$/) do
|
35
|
+
%W[stubcommand strapproject stubexists strapexists].each do |cmd|
|
36
|
+
link = "logging/home/logging/codestrap/bin/#{cmd}"
|
37
|
+
next if File.exist? link
|
38
|
+
FileUtils.ln_s(File.expand_path('logging/home/logging/codestrap/bin/strap'), link)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
When(/^logging command is executed$/) do
|
43
|
+
args = @command.split(/\s+/)
|
44
|
+
args << @output if @output
|
45
|
+
@logging_capture = Capture::Cli.inline do
|
46
|
+
cs = Codestrap::Core.new(args)
|
47
|
+
cs.execute!
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
Then(/^logging output may be generated$/) do
|
52
|
+
if @has_output and @has_output.eql?('true')
|
53
|
+
expect(File.exist? @output).to be_truthy
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
And(/^logging STDERR contains a message$/) do
|
58
|
+
Array(@stderr).each do |err|
|
59
|
+
expect(@logging_capture.stdout).to include(err)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
And(/^logging exits$/) do
|
64
|
+
expect(@logging_capture.object_exit.status).to eql(@exit)
|
65
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Feature: Supports script object creation
|
2
|
+
Given(/^a script directory "([^"]*)"$/) do |dir|
|
3
|
+
@dir = dir
|
4
|
+
end
|
5
|
+
|
6
|
+
And(/^a script "([^"]*)"$/) do |script|
|
7
|
+
@script = script
|
8
|
+
end
|
9
|
+
|
10
|
+
When(/^a script run to create an object$/) do
|
11
|
+
@output = `#{File.join(@curdir, @dir, @script)}`
|
12
|
+
@status = $?
|
13
|
+
end
|
14
|
+
|
15
|
+
Then(/^the objects JSON syntax is valid$/) do
|
16
|
+
expect(JSON.is_json?(@output)).to be true
|
17
|
+
end
|
18
|
+
|
19
|
+
And(/^a object is created$/) do
|
20
|
+
object = nil
|
21
|
+
Dir.chdir @curdir do
|
22
|
+
object = Codestrap::Object::Factory.new
|
23
|
+
object.dirs = 'test/fixtures/objects'
|
24
|
+
end
|
25
|
+
expect(object.nil?).to be false
|
26
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
#Given(/^server environment variables "([^"]*)"$/) do |etc|
|
2
|
+
# ENV['CODESTRAP_ETC'] = @etc = etc
|
3
|
+
#end
|
4
|
+
|
5
|
+
Given(/^server tmp directory$/) do
|
6
|
+
unless @server_tmp
|
7
|
+
@server_tmp = Dir.mktmpdir
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
And(/^server fixtures file "([^"]*)" with:$/) do |yaml, text|
|
12
|
+
@server_fixture_file = File.join(@server_tmp, yaml)
|
13
|
+
file = File.open(@server_fixture_file, 'w')
|
14
|
+
file.write(text)
|
15
|
+
file.close
|
16
|
+
@fixture_hash = YAML.load(text)
|
17
|
+
end
|
18
|
+
|
19
|
+
And(/^server fixture "([^"]+)"$/) do |number|
|
20
|
+
@fixture_idx = number.to_i
|
21
|
+
@fixture_cur = @fixture_hash[@fixture_idx]
|
22
|
+
@type = @fixture_cur['type']
|
23
|
+
@template = @fixture_cur['template']
|
24
|
+
sf_content = @fixture_cur['codestrapfile']
|
25
|
+
sf_path = File.join(@server_tmp, 'Codestrapfile')
|
26
|
+
sf_file = File.open(sf_path, 'w')
|
27
|
+
sf_file.write(sf_content)
|
28
|
+
sf_file.close
|
29
|
+
ENV['CODESTRAPFILE']=sf_path
|
30
|
+
end
|
31
|
+
|
32
|
+
And(/^server capbility rest "(\/rest\/capability\.json)" is valid$/) do |url|
|
33
|
+
get url
|
34
|
+
expect(last_response.ok?).to be_truthy
|
35
|
+
@capability = JSON.parse(last_response.body)
|
36
|
+
end
|
37
|
+
|
38
|
+
And(/^server object rest "(\/rest\/objects\.json)" is valid$/) do |url|
|
39
|
+
get url
|
40
|
+
expect(last_response.ok?).to be_truthy
|
41
|
+
@codestrap_objects = JSON.parse(last_response.body)
|
42
|
+
end
|
43
|
+
|
44
|
+
And(/^server stub metadata rest "(\/rest\/stub\/metadata\.json)" is valid$/) do |url|
|
45
|
+
get url
|
46
|
+
expect(last_response.ok?).to be_truthy
|
47
|
+
@codestrap_metadata = JSON.parse(last_response.body)
|
48
|
+
end
|
49
|
+
|
50
|
+
And(/^server strap metadata rest "(\/rest\/strap\/metadata\.json)" is valid$/) do |url|
|
51
|
+
get url
|
52
|
+
expect(last_response.ok?).to be_truthy
|
53
|
+
@strap_metadata = JSON.parse(last_response.body)
|
54
|
+
end
|
55
|
+
|
56
|
+
And(/^server list contains the correct keys$/) do
|
57
|
+
case @type
|
58
|
+
when 'stub'
|
59
|
+
expect(@codestrap_metadata).to have_key(@template)
|
60
|
+
when 'strap'
|
61
|
+
expect(@strap_metadata).to have_key(@template)
|
62
|
+
else
|
63
|
+
raise 'Error unknown type'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
Then(/^server file should contain the correct content$/) do
|
68
|
+
if @type == 'stub'
|
69
|
+
get @capability['urls']['stub']['file'] + '/' + @template
|
70
|
+
|
71
|
+
potentials = Array(Codestrapfile.server.content).map { |dir| File.join(dir,@template + '.erb') }
|
72
|
+
file = potentials.select { |f| File.exist? f }.first
|
73
|
+
expect(file).to be_truthy
|
74
|
+
|
75
|
+
file_sum = File.read(file)
|
76
|
+
body_sum = last_response.body
|
77
|
+
|
78
|
+
expect(body_sum).to eql(file_sum)
|
79
|
+
end
|
80
|
+
if @type == 'strap'
|
81
|
+
# Fetch metadata
|
82
|
+
get @capability['urls']['strap']['metadata']
|
83
|
+
expect(last_response.ok?).to be_truthy
|
84
|
+
metadata = JSON.parse(last_response.body)[@template]
|
85
|
+
|
86
|
+
tmpdir = Dir.mktmpdir
|
87
|
+
|
88
|
+
# Make directories
|
89
|
+
metadata['files'].each do |file|
|
90
|
+
next unless file['ftype'].eql?('directory')
|
91
|
+
FileUtils.mkdir_p File.join(tmpdir, file['file'])
|
92
|
+
end
|
93
|
+
|
94
|
+
# Make files
|
95
|
+
metadata['files'].each do |file|
|
96
|
+
next unless file['ftype'] == 'file'
|
97
|
+
get @capability['urls']['strap']['project'] + "/#{@template}/" + file['file']
|
98
|
+
expect(last_response.ok?).to be_truthy
|
99
|
+
File.open(File.join(tmpdir, file['file']), 'w') do |fh|
|
100
|
+
fh.write last_response.body
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
potentials = Array(Codestrapfile.server.content).map { |dir| File.join(dir,@template) }
|
105
|
+
strap_dir = potentials.select { |f| File.directory? f }.first
|
106
|
+
expect(diff_tree?(strap_dir, tmpdir)).to eq(0)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
And(/^server returns the right http code$/) do
|
111
|
+
expect(last_response.ok?).to be_truthy
|
112
|
+
end
|