Skip to content

Commit 92a85c8

Browse files
authored
Merge pull request #400 from Temikus/nonexistent_und_nil_checks
Fixing empty get() behavior
2 parents 37fc54d + f46bff6 commit 92a85c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+662
-179
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Style/ConditionalAssignment:
66
SingleLineConditionsOnly: true
77
EnforcedStyle: assign_inside_condition
88

9+
Style/RedundantReturn:
10+
Enabled: false
11+
912
Style/FormatString:
1013
Enabled: false
1114

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ matrix:
1212
- rvm: 2.5
1313
- rvm: jruby-head
1414
allow_failures:
15-
# allow 2.5 to fail until Travis CI is fixed.
16-
# See travis-ci/travis-ci#8969
17-
- rvm: 2.5
1815
- rvm: jruby-head
1916
notifications:
2017
email: false

CHANGELOG.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,34 @@ The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1
99
#### Fixed
1010

1111
- \#419 Locked down fog upstream dependencies to alleviate deprecation warnings
12-
until they can be properly dealt with.
12+
until they can be properly dealt with. [temikus]
13+
- \#400 Small `%Collection%.get` and `%Collection%.all` behaviour fixes [temikus]
14+
- `Fog::Google::SQL::Instances.get(nil)` no longer returns an invalid
15+
`sql#instancesList` object.
16+
- `Fog::Compute::Google::InstanceGroups.get` and `.all` methods now support more than
17+
just `:filter` option, fixed `.all` output if zone wasn't provided.
18+
- Fix a typo causing `Operations.get(region:REGION)` to fail.
19+
- `Fog::Compute::Google::Images.get(IMAGE, PROJECT)`, now returns `nil` if image is not
20+
found rather than throwing `Google::Apis::ClientError`.
21+
22+
### Development changes
23+
24+
#### Added
25+
26+
- \#400 Additional test coverage [temikus]
27+
- Expanded tests for `%Collection%.get` behavior - scoped requests (e.g. `get(zone:ZONE)`)
28+
and their corresponding code paths are now also tested.
29+
- Increase `Fog::Compute::Google::Images` integration test coverage.
30+
- Unit tests now work without a `~/.fog` config file set up.
31+
- Expanded unit test coverage.
32+
33+
#### Changed
34+
35+
- \#400 Refactored most compute `get()` and `all()` methods to common format. [temikus]
36+
37+
#### Fixed
38+
39+
- \#400 Removed the Travis Ruby 2.5 workaround. [temikus]
1340

1441
## 1.7.1
1542

CONTRIBUTING.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,26 @@ test:
101101
Then you can run all the live tests:
102102

103103
```shell
104-
$ rake test
104+
$ bundle exec rake test
105105
```
106106

107107
or just one API:
108108

109109
```
110-
$ rake test:compute
110+
$ bundle exec rake test:compute
111111
```
112112
(See `rake -T` for all available tasks)
113113

114-
or just one file:
114+
or just one test:
115115

116116
```shell
117-
$ rake test TEST=test/integration/compute/test_servers.rb TESTOPTS="--name=TestServers#test_bootstrap_ssh_destroy"
117+
$ bundle exec rake test TESTOPTS="--name=TestServers#test_bootstrap_ssh_destroy"
118+
```
119+
120+
or a series of tests by name:
121+
122+
```
123+
$ bundle exec rake test TESTOPTS="--name=/test_nil_get/"
118124
```
119125

120126
#### Unit tests
@@ -133,7 +139,7 @@ We're in progress of extending the library with more unit tests and contribution
133139
#### The transition from `shindo` to Minitest
134140

135141
Previously, [shindo](https://github.com/geemus/shindo) was the primary testing framework.
136-
We've started moving away from it, and to Minitest, but some artifacts may remain.
142+
We've moved away from it, and to Minitest, but some artifacts may remain.
137143

138144
For more information on transition, read [#50](https://github.com/fog/fog-google/issues/50).
139145

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ We are always looking for people to improve our code and test coverage, so pleas
4242

4343
## Pubsub
4444

45-
Note: You **must** have a version of google-api-client > 0.8.5 to use the Pub/Sub API; previous versions will not work.
46-
4745
Fog mostly implements [v1](https://cloud.google.com/pubsub/docs/reference/rest/) of the Google Cloud Pub/Sub API; however some less common API methods are missing. Pull requests for additions would be greatly appreciated.
4846

4947
## Installation

lib/fog/bin/google.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def class_for(key)
1515
Fog::Storage::Google
1616
when :sql
1717
Fog::Google::SQL
18+
when :pubsub
19+
Fog::Google::Pubsub
1820
else
1921
raise ArgumentError, "Unsupported #{self} service: #{key}"
2022
end
@@ -33,6 +35,8 @@ def [](service)
3335
Fog::Google::Monitoring.new
3436
when :sql
3537
Fog::Google::SQL.new
38+
when :pubsub
39+
Fog::Google::Pubsub.new
3640
when :storage
3741
Fog::Logger.warning("Google[:storage] is not recommended, use Storage[:google] for portability")
3842
Fog::Storage.new(:provider => "Google")

lib/fog/compute/google/models/addresses.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@ def all(region: nil, filter: nil, max_results: nil, order_by: nil, page_token: n
2323
load(data.map(&:to_h))
2424
end
2525

26-
def get(identity, region)
27-
if address = service.get_address(identity, region).to_h
28-
new(address)
26+
def get(identity, region = nil)
27+
if region
28+
address = service.get_address(identity, region).to_h
29+
return new(address)
30+
elsif identity
31+
response = all(:filter => "name eq #{identity}",
32+
:max_results => 1)
33+
address = response.first unless response.empty?
34+
return address
2935
end
3036
rescue ::Google::Apis::ClientError => e
3137
raise e unless e.status_code == 404

lib/fog/compute/google/models/backend_services.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ def all(_filters = {})
1010
end
1111

1212
def get(identity)
13-
if backend_service = service.get_backend_service(identity)
14-
new(backend_service.to_h)
13+
if identity
14+
backend_service = service.get_backend_service(identity).to_h
15+
return new(backend_service)
1516
end
1617
rescue ::Google::Apis::ClientError => e
1718
raise e unless e.status_code == 404

lib/fog/compute/google/models/disk_types.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@ def all(zone: nil, filter: nil, max_results: nil,
2424
end
2525

2626
def get(identity, zone = nil)
27-
response = nil
2827
if zone
29-
response = service.get_disk_type(identity, zone).to_h
28+
disk_type = service.get_disk_type(identity, zone).to_h
29+
return new(disk_type)
3030
else
31-
disk_types = all(:filter => "name eq .*#{identity}")
32-
response = disk_types.first.attributes unless disk_types.empty?
31+
response = all(:filter => "name eq .*#{identity}")
32+
disk_type = response.first unless response.empty?
33+
return disk_type
3334
end
34-
return nil if response.nil?
35-
new(response)
3635
rescue ::Google::Apis::ClientError => e
3736
raise e unless e.status_code == 404
3837
nil

lib/fog/compute/google/models/disks.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@ def all(zone: nil, filter: nil, max_results: nil, order_by: nil,
2323
load(data.map(&:to_h))
2424
end
2525

26-
def get(identity, zone)
27-
response = service.get_disk(identity, zone)
28-
return nil if response.nil?
29-
new(response.to_h)
26+
def get(identity, zone = nil)
27+
if zone
28+
disk = service.get_disk(identity, zone).to_h
29+
return new(disk)
30+
elsif identity
31+
response = all(:filter => "name eq #{identity}",
32+
:max_results => 1)
33+
disk = response.first unless response.empty?
34+
return disk
35+
end
3036
rescue ::Google::Apis::ClientError => e
3137
raise e unless e.status_code == 404
3238
nil

0 commit comments

Comments
 (0)