vscripts 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +1 -0
- data/CHANGELOG.md +20 -0
- data/README.md +17 -2
- data/bin/vscripts +1 -1
- data/lib/vscripts.rb +13 -4
- data/lib/vscripts/aws/ec2.rb +14 -5
- data/lib/vscripts/command_line.rb +28 -23
- data/lib/vscripts/commands/identify.rb +19 -16
- data/lib/vscripts/commands/tags2facts.rb +10 -10
- data/lib/vscripts/config.rb +52 -0
- data/lib/vscripts/util/local_system.rb +0 -5
- data/lib/vscripts/version.rb +11 -6
- data/spec/integration/commands/identify_spec.rb +101 -0
- data/spec/integration/commands/tags2facts_spec.rb +98 -0
- data/spec/integration/commands_spec.rb +12 -0
- data/spec/integration/config_spec.rb +56 -0
- data/spec/integration/global_opts_spec.rb +56 -0
- data/spec/spec_helper.rb +127 -3
- data/spec/unit/vscripts/aws/ec2_spec.rb +9 -1
- data/spec/unit/vscripts/aws_spec.rb +0 -1
- data/spec/unit/vscripts/command_line_spec.rb +5 -4
- data/spec/unit/vscripts/commands/identify_spec.rb +16 -12
- data/spec/unit/vscripts/commands/tags2facts_spec.rb +4 -0
- data/spec/unit/vscripts/commands_spec.rb +1 -1
- data/spec/unit/vscripts/config_spec.rb +53 -0
- data/spec/unit/vscripts/util/local_system_spec.rb +4 -12
- data/spec/unit/vscripts/version_spec.rb +13 -1
- data/spec/unit/vscripts_spec.rb +33 -14
- data/tasks/deploy.rake +23 -14
- data/vscripts.gemspec +8 -6
- metadata +15 -6
- data/VERSION +0 -1
- data/spec/aws_spec_helper.rb +0 -10
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'aws_spec_helper'
|
3
2
|
require 'vscripts/aws'
|
4
3
|
|
5
4
|
describe VScripts::AWS::EC2 do
|
@@ -55,6 +54,15 @@ describe VScripts::AWS::EC2 do
|
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
57
|
+
describe '#all_tags_hash' do
|
58
|
+
it 'returns a Hash' do
|
59
|
+
allow(subject).to receive('all_tags')
|
60
|
+
.and_return(tags)
|
61
|
+
expect(subject.all_tags_hash).to be_an_instance_of Hash
|
62
|
+
expect(subject.all_tags_hash).to eq({"Name"=>"test"})
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
58
66
|
describe '#tags_without' do
|
59
67
|
it 'returns a filtered Hash' do
|
60
68
|
allow(subject).to receive('all_tags')
|
@@ -2,9 +2,10 @@ require 'spec_helper'
|
|
2
2
|
require 'vscripts/command_line'
|
3
3
|
|
4
4
|
describe VScripts::CommandLine do
|
5
|
-
subject { VScripts::CommandLine.new([cmd, 'extra_args']) }
|
6
5
|
let(:cmd) { VScripts::Commands.list.first.to_s }
|
7
6
|
|
7
|
+
subject { VScripts::CommandLine.new([cmd, 'extra_args']) }
|
8
|
+
|
8
9
|
describe '#new' do
|
9
10
|
it 'returns the command line arguments' do
|
10
11
|
expect(subject).to be_an_instance_of VScripts::CommandLine
|
@@ -13,7 +14,7 @@ describe VScripts::CommandLine do
|
|
13
14
|
|
14
15
|
describe '#global' do
|
15
16
|
it 'returns the global options as a Hash' do
|
16
|
-
expect(subject.global).to
|
17
|
+
expect(subject.global).to be_a Hash
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
@@ -26,8 +27,8 @@ describe VScripts::CommandLine do
|
|
26
27
|
|
27
28
|
describe '#extra' do
|
28
29
|
it 'returns the rest of the arguments as an Array' do
|
29
|
-
expect(subject.
|
30
|
-
expect(subject.
|
30
|
+
expect(subject.command_options).to be_an_instance_of Array
|
31
|
+
expect(subject.command_options).to eql ['extra_args']
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
@@ -15,6 +15,10 @@ describe VScripts::Commands::Identify do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
describe '#new' do
|
18
|
+
it 'returns extra arguments' do
|
19
|
+
expect(subject.arguments).to be_an Array
|
20
|
+
end
|
21
|
+
|
18
22
|
context 'when theme is not passed' do
|
19
23
|
it 'returns the default theme' do
|
20
24
|
expect(subject.theme).to eq('Group-Role-#')
|
@@ -23,8 +27,8 @@ describe VScripts::Commands::Identify do
|
|
23
27
|
|
24
28
|
context 'when theme is passed' do
|
25
29
|
it 'returns the theme' do
|
26
|
-
|
27
|
-
expect(
|
30
|
+
subject = VScripts::Commands::Identify.new(['--ec2-tag-theme=test'])
|
31
|
+
expect(subject.theme).to eq('test')
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
@@ -36,8 +40,8 @@ describe VScripts::Commands::Identify do
|
|
36
40
|
|
37
41
|
context 'when host is passed' do
|
38
42
|
it 'returns the host' do
|
39
|
-
|
40
|
-
expect(
|
43
|
+
subject = VScripts::Commands::Identify.new(['--host=test'])
|
44
|
+
expect(subject.host).to eq('test')
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
@@ -49,8 +53,8 @@ describe VScripts::Commands::Identify do
|
|
49
53
|
|
50
54
|
context 'when domain is passed' do
|
51
55
|
it 'returns the domain' do
|
52
|
-
|
53
|
-
expect(
|
56
|
+
subject = VScripts::Commands::Identify.new(['--domain=test'])
|
57
|
+
expect(subject.domain).to eq('test')
|
54
58
|
end
|
55
59
|
end
|
56
60
|
end
|
@@ -100,8 +104,8 @@ describe VScripts::Commands::Identify do
|
|
100
104
|
|
101
105
|
context 'when host is passed' do
|
102
106
|
it 'returns a string' do
|
103
|
-
|
104
|
-
expect(
|
107
|
+
subject = VScripts::Commands::Identify.new(['--host=test'])
|
108
|
+
expect(subject.new_hostname).to eq('test')
|
105
109
|
end
|
106
110
|
end
|
107
111
|
end
|
@@ -127,8 +131,8 @@ describe VScripts::Commands::Identify do
|
|
127
131
|
|
128
132
|
context 'when domain is passed' do
|
129
133
|
it 'returns a string' do
|
130
|
-
|
131
|
-
expect(
|
134
|
+
subject = VScripts::Commands::Identify.new(['--domain=test'])
|
135
|
+
expect(subject.new_domain).to eq('test')
|
132
136
|
end
|
133
137
|
end
|
134
138
|
end
|
@@ -171,8 +175,8 @@ describe VScripts::Commands::Identify do
|
|
171
175
|
allow(subject).to receive(:set_name_tag)
|
172
176
|
allow(subject).to receive(:set_hostname)
|
173
177
|
allow(subject).to receive(:update_hosts)
|
174
|
-
|
175
|
-
subject.execute
|
178
|
+
allow(STDOUT).to receive(:puts)
|
179
|
+
expect(subject.execute).to be_nil
|
176
180
|
end
|
177
181
|
end
|
178
182
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'vscripts/config'
|
3
|
+
|
4
|
+
describe VScripts::Config do
|
5
|
+
include_context 'Temporary'
|
6
|
+
subject { VScripts::Config.new }
|
7
|
+
|
8
|
+
describe '#new' do
|
9
|
+
context 'when config file not passed' do
|
10
|
+
it 'returns nil' do
|
11
|
+
expect(subject.instance_variable_get(:@file)).to be_nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
context 'when config file passed' do
|
15
|
+
it 'returns the path' do
|
16
|
+
subject = VScripts::Config.new('/path/to/file')
|
17
|
+
expect(subject.instance_variable_get(:@file)).to eq('/path/to/file')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#get' do
|
23
|
+
it 'returns a Hash' do
|
24
|
+
expect(subject.get).to be_a Hash
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#options' do
|
29
|
+
it 'returns a Hash' do
|
30
|
+
expect(subject.options).to be_a Hash
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#parse' do
|
35
|
+
it 'returns a Hash' do
|
36
|
+
allow(File).to receive(:exist?).and_return(true)
|
37
|
+
allow(File).to receive(:read).and_return('testkey: testvalue')
|
38
|
+
expect(subject.parse('test')).to be_a Hash
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#read' do
|
43
|
+
it 'returns a String' do
|
44
|
+
expect(subject.read(test_file)).to be_a String
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#check_config' do
|
49
|
+
it 'returns Boolean' do
|
50
|
+
expect(subject.check_config(test_file))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -1,13 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'tempfile'
|
3
2
|
require 'vscripts/util'
|
4
3
|
|
5
4
|
describe VScripts::Util::LocalSystem do
|
6
5
|
subject { Object.new.extend VScripts::Util }
|
7
6
|
|
8
|
-
|
9
|
-
let(:test_file) { "#{test_dir}/test_file" }
|
10
|
-
let(:test_cont) { 'testing content' }
|
7
|
+
include_context 'Temporary'
|
11
8
|
|
12
9
|
describe '#hosts_path' do
|
13
10
|
it 'returns the path to hosts file' do
|
@@ -21,13 +18,6 @@ describe VScripts::Util::LocalSystem do
|
|
21
18
|
end
|
22
19
|
end
|
23
20
|
|
24
|
-
describe '#hosts_file' do
|
25
|
-
it 'returns the an array' do
|
26
|
-
allow(File).to receive(:read).and_return(test_cont)
|
27
|
-
expect(subject.hosts_file).to be_a String
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
21
|
describe '#local_fqdn' do
|
32
22
|
it 'returns the local FQDN' do
|
33
23
|
expect(subject.local_fqdn).to be_a String
|
@@ -43,6 +33,8 @@ describe VScripts::Util::LocalSystem do
|
|
43
33
|
describe '#local_domain_name' do
|
44
34
|
it 'returns the local domain name' do
|
45
35
|
expect(subject.local_domain_name).to be_a String
|
36
|
+
allow(subject).to receive('`').and_raise(StandardError)
|
37
|
+
expect(subject.local_domain_name).to eq('local')
|
46
38
|
end
|
47
39
|
end
|
48
40
|
|
@@ -57,7 +49,7 @@ describe VScripts::Util::LocalSystem do
|
|
57
49
|
|
58
50
|
describe '#ensure_file_dir' do
|
59
51
|
it 'create a directory for the specified files' do
|
60
|
-
subject.ensure_file_dir(
|
52
|
+
subject.ensure_file_dir(test_missing_file)
|
61
53
|
expect(Dir.exists?(test_dir)).to be true
|
62
54
|
end
|
63
55
|
end
|
@@ -3,6 +3,18 @@ require 'vscripts/version'
|
|
3
3
|
|
4
4
|
describe 'VScripts::VERSION' do
|
5
5
|
it 'Should be a string' do
|
6
|
-
expect(VScripts::VERSION).to
|
6
|
+
expect(VScripts::VERSION::STRING).to be_a String
|
7
|
+
end
|
8
|
+
it 'Should have a major version' do
|
9
|
+
expect(VScripts::VERSION::MAJOR).to be_an Integer
|
10
|
+
end
|
11
|
+
it 'Should have a minor version' do
|
12
|
+
expect(VScripts::VERSION::MINOR).to be_an Integer
|
13
|
+
end
|
14
|
+
it 'Should have a patch version' do
|
15
|
+
expect(VScripts::VERSION::PATCH).to be_an Integer
|
16
|
+
end
|
17
|
+
it 'Should have a copyright version' do
|
18
|
+
expect(VScripts::VERSION::COPYRIGHT).to be_a String
|
7
19
|
end
|
8
20
|
end
|
data/spec/unit/vscripts_spec.rb
CHANGED
@@ -2,26 +2,45 @@ require 'spec_helper'
|
|
2
2
|
require 'vscripts'
|
3
3
|
|
4
4
|
describe VScripts do
|
5
|
-
|
6
|
-
|
7
|
-
@cmd = VScripts::Commands.list.first.to_s.downcase
|
8
|
-
end
|
5
|
+
include_context 'Suppressed output'
|
6
|
+
include_context 'VScripts'
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
describe '.run' do
|
9
|
+
context 'when no command line arguments' do
|
10
|
+
it 'returns help' do
|
11
|
+
expect{stub_cli_with('')}.to raise_error(SystemExit)
|
12
|
+
expect($stdout.string).to match(/Available commands/)
|
13
|
+
end
|
14
|
+
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
16
|
+
context 'when \'-h\'' do
|
17
|
+
it 'returns help' do
|
18
|
+
expect{stub_cli_with('-h')}.to raise_error(SystemExit)
|
19
|
+
expect($stdout.string).to match(/Available commands/)
|
20
|
+
end
|
17
21
|
end
|
18
22
|
|
19
|
-
|
20
|
-
|
23
|
+
context 'when \'-v\'' do
|
24
|
+
it 'returns version' do
|
25
|
+
expect{stub_cli_with('-v')}.to raise_error(SystemExit)
|
26
|
+
expect($stdout.string).to match(/VScripts.*(c)/)
|
27
|
+
end
|
21
28
|
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '.cli' do
|
32
|
+
it 'returns subcommand and arguments' do
|
33
|
+
allow(VScripts::CommandLine).to receive(:new)
|
34
|
+
.and_return(VScripts::CommandLine.new("#{cmd} -h".split))
|
35
|
+
expect{subject.run}.to raise_error(SystemExit)
|
36
|
+
expect($stdout.string).to match(/USAGE:/)
|
37
|
+
expect($stdout.string).to match(/OPTIONS:/)
|
38
|
+
end
|
39
|
+
end
|
22
40
|
|
23
|
-
|
24
|
-
|
41
|
+
describe '.config' do
|
42
|
+
it 'returns a hash' do
|
43
|
+
expect(subject.config.get).to be_a Hash
|
25
44
|
end
|
26
45
|
end
|
27
46
|
end
|
data/tasks/deploy.rake
CHANGED
@@ -1,27 +1,32 @@
|
|
1
|
+
require 'vscripts/version'
|
2
|
+
|
1
3
|
DEV_BRANCH = 'development'
|
2
4
|
LOG_RANGE = "master...#{DEV_BRANCH}"
|
3
|
-
VERSION_FILE = 'VERSION'
|
4
5
|
CHANGELOG_FILE = 'CHANGELOG.md'
|
5
6
|
|
6
7
|
desc 'Automated deployment (increment patch)'
|
7
8
|
task :deploy do
|
8
|
-
|
9
|
+
check_branch
|
10
|
+
bump_version
|
9
11
|
deploy
|
10
12
|
end
|
11
13
|
|
12
14
|
namespace 'deploy' do
|
13
15
|
desc 'Automated deployment (increment patch)'
|
14
16
|
task :patch do
|
17
|
+
check_branch
|
15
18
|
bump_version('patch')
|
16
19
|
deploy
|
17
20
|
end
|
18
21
|
desc 'Automated deployment (increment minor)'
|
19
22
|
task :minor do
|
23
|
+
check_branch
|
20
24
|
bump_version('minor')
|
21
25
|
deploy
|
22
26
|
end
|
23
27
|
desc 'Automated deployment (increment major)'
|
24
28
|
task :major do
|
29
|
+
check_branch
|
25
30
|
bump_version('major')
|
26
31
|
deploy
|
27
32
|
end
|
@@ -30,7 +35,6 @@ end
|
|
30
35
|
def deploy
|
31
36
|
commit_changelog
|
32
37
|
merge_changes
|
33
|
-
push_release
|
34
38
|
end
|
35
39
|
|
36
40
|
def check_branch
|
@@ -43,20 +47,23 @@ def check_branch
|
|
43
47
|
end
|
44
48
|
|
45
49
|
def bump_version(type = 'patch')
|
46
|
-
|
47
|
-
@version = File.read(VERSION_FILE).strip
|
48
|
-
@version.gsub(/(\d+)\.(\d+)\.(\d+)/) {
|
49
|
-
@major, @minor, @patch = $1.to_i, $2.to_i, $3.to_i
|
50
|
-
}
|
50
|
+
include VScripts::VERSION
|
51
51
|
case type
|
52
52
|
when 'patch'
|
53
|
-
@new_version = "#{
|
53
|
+
@new_version = "#{MAJOR}.#{MINOR}.#{PATCH + 1}"
|
54
54
|
when 'minor'
|
55
|
-
@new_version = "#{
|
55
|
+
@new_version = "#{MAJOR}.#{MINOR + 1}.0"
|
56
56
|
when 'major'
|
57
|
-
@new_version = "#{
|
57
|
+
@new_version = "#{MAJOR + 1}.0.0"
|
58
58
|
end
|
59
|
-
|
59
|
+
write_bumped_version
|
60
|
+
end
|
61
|
+
|
62
|
+
def write_bumped_version
|
63
|
+
version_file = 'lib/vscripts/version.rb'
|
64
|
+
version_content = File.read(version_file)
|
65
|
+
modified = version_content.gsub(/#{VScripts::VERSION::STRING}/, @new_version)
|
66
|
+
File.write(version_file, modified)
|
60
67
|
end
|
61
68
|
|
62
69
|
def changelog
|
@@ -91,7 +98,7 @@ def commit_changelog
|
|
91
98
|
end
|
92
99
|
|
93
100
|
def branch
|
94
|
-
|
101
|
+
`git branch`.match(/^\* (\S+)/)[1]
|
95
102
|
end
|
96
103
|
|
97
104
|
def switch_to_branch(name)
|
@@ -103,10 +110,12 @@ def merge
|
|
103
110
|
end
|
104
111
|
|
105
112
|
def merge_changes
|
113
|
+
previous = branch
|
106
114
|
switch_to_branch('master')
|
107
115
|
puts "Merging \"#{DEV_BRANCH}\" branch"
|
108
116
|
abort 'ERROR: Conflicts found; Stopping!' if merge =~ /conflict/i
|
109
|
-
|
117
|
+
push_release
|
118
|
+
switch_to_branch(previous)
|
110
119
|
end
|
111
120
|
|
112
121
|
def push_release
|
data/vscripts.gemspec
CHANGED
@@ -5,20 +5,22 @@ require 'vscripts/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'vscripts'
|
8
|
-
spec.version = VScripts::VERSION
|
8
|
+
spec.version = VScripts::VERSION::STRING
|
9
9
|
spec.authors = ['Vlad Ghinea']
|
10
10
|
spec.email = ['vlad@ghn.me']
|
11
11
|
spec.summary = %q{VladGh.com's automation scripts}
|
12
|
+
spec.homepage = 'https://github.com/vghn/vscripts'
|
13
|
+
spec.license = 'Apache 2.0'
|
12
14
|
spec.description = <<-EOF
|
13
15
|
VScripts is a command line utility that performs a series of tasks used on
|
14
16
|
VladGh.com's deployment.
|
15
17
|
EOF
|
16
|
-
spec.homepage = 'https://github.com/vghn/vscripts'
|
17
|
-
spec.license = 'Apache 2.0'
|
18
18
|
|
19
|
-
spec.metadata
|
20
|
-
|
21
|
-
|
19
|
+
if spec.respond_to?(:metadata=)
|
20
|
+
spec.metadata = {
|
21
|
+
'issue_tracker' => 'https://github.com/vghn/vscripts/issues'
|
22
|
+
}
|
23
|
+
end
|
22
24
|
|
23
25
|
spec.files = `git ls-files -z`.split("\x0")
|
24
26
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|