dd_spacecadet 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,77 @@
1
+ # Copyright 2016 DoubleDutch, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'spec_helper'
16
+
17
+ describe DoubleDutch::SpaceCadet::NodeIP do
18
+ let(:env) { 'dfw-test' }
19
+
20
+ before do
21
+ client_resp = double('ClientResponse', data: mock_data)
22
+
23
+ client = double('Client', list_servers: client_resp)
24
+
25
+ client_hash = { 'dfw-test' => client }
26
+
27
+ allow(DoubleDutch::SpaceCadet::Config).to receive(:servers_client)
28
+ .and_return(client_hash)
29
+ end
30
+
31
+ after { allow(DoubleDutch::SpaceCadet::Config).to receive(:servers_client).and_call_original }
32
+
33
+ describe '.get_ip_for' do
34
+ it 'should return the correct IP address for the name' do
35
+ expect(DoubleDutch::SpaceCadet::NodeIP.get_ip_for(env, 'test-app01'))
36
+ .to eql('127.0.0.1')
37
+
38
+ expect(DoubleDutch::SpaceCadet::NodeIP.get_ip_for(env, 'test-app02'))
39
+ .to eql('127.0.0.2')
40
+ end
41
+ end
42
+
43
+ describe '.get_name_for' do
44
+ it 'should return the correct IP address for the name' do
45
+ expect(DoubleDutch::SpaceCadet::NodeIP.get_name_for(env, '127.0.0.1'))
46
+ .to eql('test-app01')
47
+
48
+ expect(DoubleDutch::SpaceCadet::NodeIP.get_name_for(env, '127.0.0.2'))
49
+ .to eql('test-app02')
50
+ end
51
+ end
52
+ end
53
+
54
+ def mock_data
55
+ {
56
+ body: {
57
+ 'servers' => [
58
+ {
59
+ 'name' => 'test-app01',
60
+ 'addresses' => {
61
+ 'private' => [
62
+ { 'addr' => '127.0.0.1' }
63
+ ]
64
+ }
65
+ },
66
+ {
67
+ 'name' => 'tEst-APP02',
68
+ 'addresses' => {
69
+ 'private' => [
70
+ { 'addr' => '127.0.0.2' }
71
+ ]
72
+ }
73
+ }
74
+ ]
75
+ }
76
+ }
77
+ end
@@ -0,0 +1,66 @@
1
+ # Copyright 2016 DoubleDutch, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'spec_helper'
16
+
17
+ def mock_lbs_list
18
+ {
19
+ body: {
20
+ 'loadBalancers' => [
21
+ {
22
+ 'name' => 'test-lb01',
23
+ 'id' => 42
24
+ },
25
+ {
26
+ 'name' => 'test-lb02',
27
+ 'id' => 84
28
+ }
29
+ ]
30
+ }
31
+ }
32
+ end
33
+
34
+ describe DoubleDutch::SpaceCadet::Util do
35
+ let(:env) { 'test-env' }
36
+
37
+ before do
38
+ resp = double('Response', data: mock_lbs_list)
39
+
40
+ client = double('Fog::Rackspace::LoadBalancers', list_load_balancers: resp)
41
+
42
+ allow(DoubleDutch::SpaceCadet::Util).to receive(:_lbs_client).with(env)
43
+ .and_return(client)
44
+ end
45
+
46
+ after { allow(DoubleDutch::SpaceCadet::Util).to receive(:_lbs_client).and_call_original }
47
+
48
+ describe '.find_lb' do
49
+ it 'should find all load balancers containing the search string' do
50
+ r = DoubleDutch::SpaceCadet::Util.find_lb(env, 'lb')
51
+ expect(r.size).to eql(2)
52
+
53
+ expect(r[0][:name]).to eql('test-lb01')
54
+ expect(r[0][:id]).to eql(42)
55
+
56
+ expect(r[1][:name]).to eql('test-lb02')
57
+ expect(r[1][:id]).to eql(84)
58
+ end
59
+
60
+ it 'should return an empty array for a non-matching value' do
61
+ expect(
62
+ DoubleDutch::SpaceCadet::Util.find_lb(env, 'RANDOM_NOT_FOUND_STRING')
63
+ ).to be_empty
64
+ end
65
+ end
66
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dd_spacecadet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - DoubleDutch Engineering Operations
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 11.2.2
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 11.2.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.5.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.5.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.42.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.42.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: irbtools
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: fog
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.38.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.38.0
83
+ description: Rubygem for safely managing Rackspace Cloud Load Balancer backend servers
84
+ email: engops@doubledutch.me
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - ".gitignore"
90
+ - ".rubocop.yml"
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - LICENSE
94
+ - README.md
95
+ - Rakefile
96
+ - dd_spacecadet.gemspec
97
+ - lib/dd_spacecadet.rb
98
+ - lib/dd_spacecadet/config.rb
99
+ - lib/dd_spacecadet/error.rb
100
+ - lib/dd_spacecadet/lb.rb
101
+ - lib/dd_spacecadet/node_ip.rb
102
+ - lib/dd_spacecadet/util.rb
103
+ - lib/dd_spacecadet/version.rb
104
+ - spec/spec_helper.rb
105
+ - spec/unit/dd_spacecadet/config_spec.rb
106
+ - spec/unit/dd_spacecadet/lb_spec.rb
107
+ - spec/unit/dd_spacecadet/node_ip_spec.rb
108
+ - spec/unit/dd_spacecadet/util_spec.rb
109
+ homepage: https://github.com/DoubleDutch/spacecadet
110
+ licenses:
111
+ - Apache 2.0
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: '2.3'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.5.1
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Library for manipulating Rackspace Cloud Load Balancers
133
+ test_files:
134
+ - spec/spec_helper.rb
135
+ - spec/unit/dd_spacecadet/config_spec.rb
136
+ - spec/unit/dd_spacecadet/lb_spec.rb
137
+ - spec/unit/dd_spacecadet/node_ip_spec.rb
138
+ - spec/unit/dd_spacecadet/util_spec.rb