gce-host 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9058278fe6965657e42e0852b083ecc42ab3b43
4
- data.tar.gz: 7d6687397b875e5e477e94c45d4db37c1b1417d2
3
+ metadata.gz: dad933feea005e321f009794fda85a7d5dd0c711
4
+ data.tar.gz: 24e9a937f5b92063ed03b739cd15de197b5f0b82
5
5
  SHA512:
6
- metadata.gz: 1dac786e7a247fa314955ed1a452e201e57696cf3ed0a0f8d07e8ba18e207392ddcb7a80736f1aadaae98d14231ad3e8838757d2fe809e703969e736044663fe
7
- data.tar.gz: 57ed8dc3ed59addae4be3745bb671fb7fec1b17248b50af71efe8bb8ec46e1e86e7dff9ad0b065ac51a3275468b288723d109fb24dee3e24a7db3f3f87373eaf
6
+ metadata.gz: df810097c230bacf4a0f5704673fab22886e372973ddc080d4f971bd8571309045525ab7754a64c033832cbc1d88ef897d4c79e30e84e77da52d2028ad0e7819
7
+ data.tar.gz: fce1c754372461a56cb6de061c0c60d8057c7358fe4c88233fb84c4147ff9f9db9bddf72229cae796828111307708c7b56904638996375be736b0ed9f19aadc4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 0.4.4 (2017/05/20)
2
+
3
+ Fixes:
4
+
5
+ * Fix to support multile roles and roleNs with command line arguments as
6
+ * gce-host --role foo:a,bar:b
7
+ * gce-host --role1 foo,bar --role2 a,b
8
+
1
9
  # 0.4.3 (2017/01/20)
2
10
 
3
11
  Enhancements:
@@ -175,13 +175,18 @@ class GCE
175
175
  def role_match?(condition)
176
176
  # usage is an alias of role
177
177
  if role = (condition[:role] || condition[:usage])
178
- parts = role.first.split(Config.role_value_delimiter, Config.role_max_depth)
178
+ role.any? do |r|
179
+ parts = r.split(Config.role_value_delimiter, Config.role_max_depth)
180
+ next true if parts.compact.empty? # no role conditions
181
+ roles.find {|role| role.match?(*parts) }
182
+ end
179
183
  else
180
184
  parts = 1.upto(Config.role_max_depth).map do |i|
181
- (condition["role#{i}".to_sym] || condition["usage#{i}".to_sym] || []).first
185
+ condition["role#{i}".to_sym] || condition["usage#{i}".to_sym]
182
186
  end
187
+ return true if parts.compact.empty? # no role conditions
188
+ roles.find {|role| role.match?(*parts) }
183
189
  end
184
- roles.find {|role| role.match?(*parts) }
185
190
  end
186
191
 
187
192
  def status_match?(condition)
@@ -53,11 +53,19 @@ class GCE
53
53
  # RoleData.new('admin', 'jenkins', 'slave').match?('admin', 'jenkins', 'master') #=> false
54
54
  # RoleData.new('admin', 'jenkins', 'slave').match?(nil, 'jenkins') #=> true
55
55
  # RoleData.new('admin', 'jenkins', 'slave').match?(nil, nil, 'slave') #=> true
56
- #
56
+ #
57
+ # RoleData.new('foo', 'a').match?(['foo', 'bar']) #=> true
58
+ # RoleData.new('bar', 'a').match?(['foo', 'bar']) #=> true
59
+ #
60
+ # RoleData.new('foo', 'a').match?(['foo', 'bar'], ['a', 'b']) #=> true
61
+ # RoleData.new('foo', 'a').match?(['foo', 'bar'], ['a', 'b']) #=> true
62
+ # RoleData.new('bar', 'b').match?(['foo', 'bar'], ['a', 'b']) #=> true
63
+ # RoleData.new('bar', 'b').match?(['foo', 'bar'], ['a', 'b']) #=> true
64
+ #
57
65
  # @param [Array] role_parts such as ["admin", "jenkins", "slave"]
58
66
  def match?(*role_parts)
59
67
  indexes = role_parts.map.with_index {|part, i| part ? i : nil }.compact
60
- @role_parts.values_at(*indexes) == role_parts.values_at(*indexes)
68
+ indexes.all? {|i| Array(role_parts[i]).include?(@role_parts[i]) }
61
69
  end
62
70
 
63
71
  # Equality
@@ -1,5 +1,5 @@
1
1
  class GCE
2
2
  class Host
3
- VERSION = '0.4.3'
3
+ VERSION = '0.4.4'
4
4
  end
5
5
  end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe GCE::Host::HostData do
4
+ describe '#role_match?' do
5
+ def host_with_role(role)
6
+ GCE::Host::HostData.new(Object.new).tap do |data|
7
+ roles = [GCE::Host::RoleData.build(role)]
8
+ data.instance_variable_set(:@roles, roles)
9
+ end
10
+ end
11
+
12
+ context 'with role' do
13
+ it do
14
+ expect(host_with_role('admin:jenkins:slave').send(:role_match?, role: ['admin'])).to be_truthy
15
+ expect(host_with_role('admin:jenkins:slave').send(:role_match?, role: ['admin:jenkins'])).to be_truthy
16
+ expect(host_with_role('admin:jenkins:slave').send(:role_match?, role: ['admin:jenkins:slave'])).to be_truthy
17
+
18
+ expect(host_with_role('foo:a').send(:role_match?, role: ['foo:a', 'bar:b'])).to be_truthy
19
+ expect(host_with_role('bar:a').send(:role_match?, role: ['foo:a', 'bar:b'])).to be_falsey
20
+ expect(host_with_role('foo:b').send(:role_match?, role: ['foo:a', 'bar:b'])).to be_falsey
21
+ expect(host_with_role('bar:b').send(:role_match?, role: ['foo:a', 'bar:b'])).to be_truthy
22
+ end
23
+ end
24
+
25
+ context 'with roleN' do
26
+ it do
27
+ expect(host_with_role('foo:a').send(:role_match?, role1: ['foo', 'bar'], role2: ['a', 'b'])).to be_truthy
28
+ expect(host_with_role('bar:a').send(:role_match?, role1: ['foo', 'bar'], role2: ['a', 'b'])).to be_truthy
29
+ expect(host_with_role('baz:a').send(:role_match?, role1: ['foo', 'bar'], role2: ['a', 'b'])).to be_falsey
30
+ expect(host_with_role('foo:b').send(:role_match?, role1: ['foo', 'bar'], role2: ['a', 'b'])).to be_truthy
31
+ expect(host_with_role('bar:b').send(:role_match?, role1: ['foo', 'bar'], role2: ['a', 'b'])).to be_truthy
32
+ expect(host_with_role('baz:b').send(:role_match?, role1: ['foo', 'bar'], role2: ['a', 'b'])).to be_falsey
33
+
34
+ expect(host_with_role('foo:a').send(:role_match?, role2: ['a', 'b'])).to be_truthy
35
+ expect(host_with_role('foo:b').send(:role_match?, role2: ['a', 'b'])).to be_truthy
36
+ expect(host_with_role('foo:c').send(:role_match?, role2: ['a', 'b'])).to be_falsey
37
+ end
38
+ end
39
+ end
40
+ end
@@ -29,12 +29,39 @@ describe GCE::Host::RoleData do
29
29
  end
30
30
 
31
31
  describe '#match?' do
32
- let(:subject) { GCE::Host::RoleData.build('web:test') }
33
- it do
34
- expect(subject.match?('web')).to be_truthy
35
- expect(subject.match?('web', 'test')).to be_truthy
36
- expect(subject.match?('web', 'test', 'wrong')).to be_falsey
37
- expect(subject.match?('web', 'wrong')).to be_falsey
32
+ context 'with single match' do
33
+ let(:subject) { GCE::Host::RoleData.build('admin:jenkins:slave') }
34
+
35
+ it do
36
+ expect(subject.match?('admin')).to be_truthy
37
+ expect(subject.match?('admin', 'jenkins')).to be_truthy
38
+ expect(subject.match?('admin', 'jenkins', 'slave')).to be_truthy
39
+ expect(subject.match?(nil, 'jenkins')).to be_truthy
40
+ expect(subject.match?(nil, nil, 'slave')).to be_truthy
41
+
42
+ expect(subject.match?('wrong')).to be_falsey
43
+ expect(subject.match?('admin', 'wrong')).to be_falsey
44
+ expect(subject.match?('admin', 'jenkins', 'wrong')).to be_falsey
45
+ expect(subject.match?(nil, 'wrong')).to be_falsey
46
+ expect(subject.match?(nil, nil, 'wrong')).to be_falsey
47
+ end
48
+ end
49
+
50
+ context 'with array match' do
51
+ it do
52
+ expect(GCE::Host::RoleData.build('foo:a').match?(['foo', 'bar'])).to be_truthy
53
+ expect(GCE::Host::RoleData.build('bar:a').match?(['foo', 'bar'])).to be_truthy
54
+ expect(GCE::Host::RoleData.build('baz:a').match?(['foo', 'bar'])).to be_falsey
55
+
56
+ expect(GCE::Host::RoleData.build('foo:a').match?(['foo', 'bar'], ['a', 'b'])).to be_truthy
57
+ expect(GCE::Host::RoleData.build('bar:a').match?(['foo', 'bar'], ['a', 'b'])).to be_truthy
58
+ expect(GCE::Host::RoleData.build('baz:a').match?(['foo', 'bar'], ['a', 'b'])).to be_falsey
59
+ expect(GCE::Host::RoleData.build('foo:b').match?(['foo', 'bar'], ['a', 'b'])).to be_truthy
60
+ expect(GCE::Host::RoleData.build('bar:b').match?(['foo', 'bar'], ['a', 'b'])).to be_truthy
61
+ expect(GCE::Host::RoleData.build('baz:b').match?(['foo', 'bar'], ['a', 'b'])).to be_falsey
62
+
63
+ expect(GCE::Host::RoleData.build('foo:a').match?(nil, ['a', 'b'])).to be_truthy
64
+ end
38
65
  end
39
66
  end
40
67
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gce-host
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-20 00:00:00.000000000 Z
11
+ date: 2017-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-api-client
@@ -207,6 +207,7 @@ files:
207
207
  - lib/gce/host/string_util.rb
208
208
  - lib/gce/host/version.rb
209
209
  - spec/gce_client_spec.rb
210
+ - spec/host_data_spec.rb
210
211
  - spec/host_spec.rb
211
212
  - spec/role_data_spec.rb
212
213
  - spec/spec_helper.rb
@@ -231,13 +232,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
232
  version: '0'
232
233
  requirements: []
233
234
  rubyforge_project:
234
- rubygems_version: 2.5.2
235
+ rubygems_version: 2.6.11
235
236
  signing_key:
236
237
  specification_version: 4
237
238
  summary: Search hosts on GCP GCE
238
239
  test_files:
239
240
  - spec/gce_client_spec.rb
241
+ - spec/host_data_spec.rb
240
242
  - spec/host_spec.rb
241
243
  - spec/role_data_spec.rb
242
244
  - spec/spec_helper.rb
243
- has_rdoc: