Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Minitest live integration tests instead of Shindo mocked tests #51

Merged
merged 58 commits into from
Jun 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
b954f99
[shindo-minitest] update Rakefile to not require 'fog/google' and not…
Apr 6, 2015
e7cd557
[shindo-minitest] make minitest_helper use :test for Fog.credential, …
Apr 10, 2015
006655f
[shindo-minitest] convert tests/credentials_tests.rb to spec/fog/goog…
Apr 10, 2015
6c45ac8
[shindo-minitest] convert and collapse tests/helpers/collection_helpe…
Apr 9, 2015
8b57b66
[shindo-minitest] convert tests/models/compute/server_tests.rb and te…
Apr 10, 2015
1b49b55
[shindo-minitest] add TEST_SIZE_GB constant
Apr 10, 2015
40104fa
[shindo-minitest] convert tests/models/compute/disk_tests.rb and test…
Apr 10, 2015
a0fb11b
[shindo-minitest] convert http_health_check tests
Apr 10, 2015
dd6496f
[shindo-minitest] refactor CollectionSpec to be a module and include …
Apr 10, 2015
f80d5fc
[shindo-minitest] refactor CollectionSpec to wait for a resource to b…
Apr 13, 2015
35138bb
[shindo-minitest] Split up CollectionSpec tests into smaller bits
Apr 13, 2015
095bf51
[shindo-minitest] Use MiniTest::Test instead of Spec DSL
Apr 13, 2015
6663d8c
[shindo-minitest] TestServer, not ServerTest
Apr 15, 2015
f8a23cb
[shindo-minitest] use VCR
Apr 15, 2015
7076ac8
[shindo-minitest] skip TestServer::test_bootstrap_ssh_destroy when mo…
Apr 15, 2015
ee9eaab
[shindo-minitest] bootstrap test cleans up after itself
Apr 15, 2015
6b8d485
[shindo-minitest] VCR uses different wait intervals for recording and…
Apr 15, 2015
210daef
[XXX|shindo-minitest] add fog-core trunk dependency for faster tests
Apr 15, 2015
0b3ea16
[shindo-minitest] TestServer waits for disks to be destroyed on teardown
Apr 15, 2015
5b9540f
[shindo-minitest] use Factories to generate params and clean up after
Apr 16, 2015
72b6b7b
[shindo-minitest] move tests from models to integration
Apr 16, 2015
9a4b6df
[shindo|minitest] Factories should free up their own resources before…
Apr 16, 2015
b80eecf
[shindo-minitest] convert TargetPool tests to minitest
Apr 16, 2015
b55340c
[shindo-minitest] convert ForwardingRule tests to minitest
Apr 16, 2015
7422cd3
[shindo-minitest] make integration test names plural
Apr 16, 2015
99555c2
[shindo-minitest] change TODO REMOVE notes in shindo tests to be more…
Apr 16, 2015
1bace8c
[shindo-minitest] move test_name generator inside CollectionFactory
Apr 16, 2015
43eb96f
[shindo-minitest] integration tests inherit from FogIntegrationTest; …
Apr 17, 2015
cd22f9b
[shindo-minitest] use example name in resource naming
Apr 17, 2015
fbda13c
[shindo-minitest] use counter in resource naming
Apr 17, 2015
718eb85
[shindo-minitest] convert DiskTypes tests to minitest
Apr 17, 2015
72818f8
[shindo-minitest] convert Regions tests to minitest
Apr 17, 2015
fb03f23
[shindo-minitest] rework resource naming to allow multiple resources …
Apr 20, 2015
5e708eb
[shindo-minitest] convert Images tests to minitest
Apr 21, 2015
b303148
Remove .ruby-version from version control to allow multiple versions …
May 22, 2015
2596a97
Don't use VCR
May 26, 2015
1987209
Add information on how to run the tests to CONTRIBUTING
May 26, 2015
37fa074
fix typo 'fliters' -> 'filters' in resource_views model
May 26, 2015
3e59cd0
[shindo-minitest] convert TargetInstances tests to minitest, includin…
May 26, 2015
e95e161
Add rake console task
May 27, 2015
3f2c7ac
Ensure factory cleanup happens across all integration collection tests
May 27, 2015
66f2864
README information about finding history
May 27, 2015
052dac2
Explain setup required for bootstrapping ssh-able instances in README
May 28, 2015
15b810c
Testing information in README
May 28, 2015
c394c36
Explain in README how to run just one test
May 28, 2015
ec562c9
Change test_has_no_identity_if_it_has_not_been_persisted in TestColle…
May 28, 2015
1a141a3
[shindo-minitest] convert BackendServices tests to minitest, includin…
May 28, 2015
c5ec693
[shindo-minitest] convert UrlMaps tests to minitest, including a few …
May 28, 2015
9105d5b
[shindo-minitest] convert TargetHttpProxies tests to minitest, includ…
May 28, 2015
6b67fb0
Merge contributing information in README into CONTRIBUTING, plus othe…
May 29, 2015
8755a7e
Fix links in CONTRIBUTING
May 29, 2015
44c1627
Move minitest_helper to helpers/ directory, and split out integration…
May 29, 2015
a791df1
More information for development
May 29, 2015
5b1f327
Link to Nokogiri documentation in CONTRIBUTING
May 29, 2015
e9a4990
[shindo-minitest] convert GlobalForwardingRules tests to minitest, in…
Jun 8, 2015
1c200f9
[shindo-minitest] remove old shindo model tests
Jun 8, 2015
0087b1b
test against us-central1-f instead of us-central1-a
Jun 8, 2015
3976e01
Keep shindo tests as default tests
Jun 23, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
*.o
*.a
mkmf.log
.ruby-version
1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

67 changes: 66 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

New contributors are always welcome, and when in doubt please ask questions! We strive to be an open and welcoming community. Please be nice to one another.

I recommend heading over to fog's [CONTRIBUTING](https://github.com/fog/fog/blob/master/CONTRIBUTING.md) and having a look around as well. It has information and context about the state of the `fog` project as a whole.

### Coding

* Pick a task:
* Offer feedback on open [pull requests](https://github.com/fog/fog-google/pulls).
* Review open [issues](https://github.com/fog/fog-google/issues) for things to help on.
* [Create an issue](https://github.com/fog/fog-google/issues/new) to start a discussion on additions or features.
* Fork the project, add your changes and tests to cover them in a topic branch.
* [Fork](https://github.com/fog/fog-google/fork)
* Create your feature branch (`git checkout -b my-new-feature`)
* Commit your changes (`git commit -am 'Add some feature'`)
* Push to the branch (`git push origin my-new-feature`)
* Create a new pull request
* Commit your changes and rebase against `fog/fog-google` to ensure everything is up to date.
* [Submit a pull request](https://github.com/fog/fog-google/compare/)

Expand All @@ -17,4 +24,62 @@ New contributors are always welcome, and when in doubt please ask questions! We
* Offer feedback on open [issues](https://github.com/fog/fog-google/issues).
* Organize or volunteer at events.

I recommend heading over to fog's [CONTRIBUTING](https://github.com/fog/fog/blob/master/CONTRIBUTING.md) and having a look around as well. It has information and context about the state of the `fog` project as a whole.
## Contributing Code

This document is very much a work in progress. Sorry about that.

It's worth noting that, if you're looking through the code, and you'd like to know the history of a line, you may not find it in the history of this repository, since most of the code was extracted from [fog/fog](https://github.com/fog/fog). So, you can look at the history from commit [fog/fog#c596e](https://github.com/fog/fog/tree/c596e710952aa9c90713da3fbfb3027db0608413) backward for more information.

### Development environment

If you're going to be doing any kind of modifications, I highly recommend using [rbenv](https://github.com/sstephenson/rbenv), [ruby-build](https://github.com/sstephenson/ruby-build), (don't forget the [dependencies](https://github.com/sstephenson/ruby-build/wiki#suggested-build-environment)!) and [bundler](http://bundler.io/).

Once you've got that all installed, run

```shell
$ bundle install
```

to install the required gems. You might have to [fight a bit](http://www.nokogiri.org/tutorials/installing_nokogiri.html) to get Nokogiri installed.

Then, you should be ready to go! If you'd like to drop into an interactive shell, configured with your `:test` credential, use

```shell
rake console
```

### Testing

This module is tested with [Minitest](https://github.com/seattlerb/minitest). Right now, the only tests that exist are live integration tests, found in `test/integration/`. After completing the installation in the README, (including setting up your credentials and keys,) make sure you have a `:test` credential in `~/.fog`, something like:

```
test:
google_project: my-project
google_client_email: [email protected]
google_key_location: /path/to/my-project-xxxxxxxxxxxxx.p12
google_json_key_location: /path/to/my-project-xxxxxxxxxxxxx.json
```

Note that you need both a `.p12` and a `.json` key file for all the tests to pass.

Then you can run all the live tests:

```shell
$ rake test
```

or just one:

```shell
$ rake test TEST=test/integration/compute/test_servers.rb TESTOPTS="--name=TestServers#test_bootstrap_ssh_destroy"
```

#### Some notes about the tests as they stand

The live integration tests for resources, (servers, disks, etc.,) have a few components:

- The `TestCollection` **mixin module** lives in `test/helpers/test_collection.rb` and contains the standard tests to run for all resources, (e.g. `test_lifecycle`). It also calls `cleanup` on the resource's factory during teardown, to make sure that resources are getting destroyed before the next test run.
- The **factory**, (e.g. `ServersFactory`, in `test/integration/factories/servers_factory.rb`,) automates the creation of resources and/or supplies parameters for explicit creation of resources. For example, `ServersFactory` initializes a `DisksFactory` to supply disks in order to create servers, and implements the `params` method so that tests can create servers with unique names, correct zones and machine types, and automatically-created disks. `ServersFactory` inherits the `create` method from `CollectionFactory`, which allows tests to create servers on-demand.
- The **main test**, (e.g. `TestServers`, in `test/integration/compute/test_servers.rb`,) is the test that actually runs. It mixes in the `TestCollection` module in order to run the tests in that module, it supplies the `setup` method in which it initializes a `ServersFactory`, and it includes any other tests specific to this collection, (e.g. `test_bootstrap_ssh_destroy`).

If you want to create another resource, you should add live integration tests; all you need to do is create a factory in `test/integration/factories/my_resource_factory.rb` and a main test in `test/integration/compute/test_my_resource.rb` that mixes in `TestCollection`.
31 changes: 24 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,33 @@ gem 'fog-google'

And then execute:

$ bundle
```shell
$ bundle
```

Or install it yourself as:

$ gem install fog-google
```shell
$ gem install fog-google
```

### Setup

#### Credentials

Follow the [instructions to generate a private key](https://cloud.google.com/storage/docs/authentication#generating-a-private-key). You can then create a fog credentials file at `~/.fog`, which will look something like this:

```
my_credential:
google_project: my-project
google_client_email: xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@developer.gserviceaccount.com
google_json_key_location: /path/to/my-project-xxxxxxxxxxxx.json
```

#### SSH-ing into instances

If you want to be able to bootstrap SSH-able instances, (using `servers.bootstrap`,) be sure you have a key in `~/.ssh/id_rsa` and `~/.ssh/id_rsa.pub`.

## Contributing

1. Fork it ( https://github.com/fog/fog-google/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
See `CONTRIBUTING.md` in this repository.
19 changes: 14 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
require 'bundler/gem_tasks'
require 'rake/testtask'
require 'fog/google'

Rake::TestTask.new do |t|
t.libs.push %w(spec)
t.test_files = FileList['spec/**/*_spec.rb']
t.verbose = true
t.libs << "test"
t.pattern = File.join("test", "**", "test_*.rb")
end

desc 'Default Task'
task :default => [ :test, 'test:travis' ]
task :default => [ 'test:travis' ]

namespace :test do
mock = ENV['FOG_MOCK'] || 'true'
Expand All @@ -32,3 +30,14 @@ namespace :google do
end
end
end

# From http://erniemiller.org/2014/02/05/7-lines-every-gems-rakefile-should-have/
# with some modification.
task :console do
require 'irb'
require 'irb/completion'
require 'fog/google'
Fog.credential = :test
ARGV.clear
IRB.start
end
1 change: 1 addition & 0 deletions lib/fog/google/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Google < Fog::Service
request :list_region_view_resources
request :list_zone_view_resources
request :list_target_instances
request :list_aggregated_target_instances

request :get_server
request :get_address
Expand Down
7 changes: 3 additions & 4 deletions lib/fog/google/models/compute/backend_services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ def all(filters={})
end

def get(identity)
response = nil
response = service.get_backend_service(identity)
return nil if response.nil?
new(response.body)
if backend_service = service.get_backend_service(identity).body
new(backend_service)
end
rescue Fog::Errors::NotFound
nil
end
Expand Down
8 changes: 5 additions & 3 deletions lib/fog/google/models/compute/global_forwarding_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ def all
end

def get(identity, region='global')
response = service.get_global_forwarding_rule(identity, region)
return nil if response.nil?
new(response.body)
if global_forwarding_rule = service.get_global_forwarding_rule(identity, region).body
new(global_forwarding_rule)
end
rescue Fog::Errors::NotFound
nil
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/fog/google/models/compute/resource_views.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ResourceViews < Fog::Collection
model Fog::Compute::Google::ResourceView

def all(filters={})
if fliters['region'].nil? && filters['zone'].nil?
if filters['region'].nil? && filters['zone'].nil?
data = []
service.list_regions.body['items'].each do |region|
data += service.list_region_views(region['name']).body['items'] || []
Expand All @@ -17,7 +17,7 @@ def all(filters={})
data += service.list_zone_views(zone['name']).body['items'] || []
end
elsif filters['zone']
data = service.list_zone_views(fliters['zone']).body['items'] || []
data = service.list_zone_views(filters['zone']).body['items'] || []
else
data = service.list_region_views(filters['region']).body['items'] || []
end
Expand Down
7 changes: 5 additions & 2 deletions lib/fog/google/models/compute/target_http_proxies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ def all(filters={})
end

def get(identity)
response = service.get_target_http_proxy(identity)
new(response.body) unless response.nil?
if target_http_proxy = service.get_target_http_proxy(identity).body
new(target_http_proxy)
end
rescue Fog::Errors::NotFound
nil
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/google/models/compute/target_http_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TargetHttpProxy < Fog::Model
attribute :id, :aliases => 'id'
attribute :creation_timestamp, :aliases => 'creationTimestamp'
attribute :description, :aliases => 'description'
attribute :urlMap, :aliases => "urlMap"
attribute :urlMap, :aliases => ["urlMap", :url_map]

def save
requires :name
Expand Down
4 changes: 2 additions & 2 deletions lib/fog/google/models/compute/target_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def save
'instance' => instance,
}

data = service.insert_target_instance(name, zone, options).body
operation = Fog::Compute::Google::Operations.new(:service => service).get(data['name'])
data = service.insert_target_instance(name, zone, options)
operation = Fog::Compute::Google::Operations.new(:service => service).get(data.body['name'], data.body['zone'])
operation.wait_for { !pending? }
reload
end
Expand Down
29 changes: 21 additions & 8 deletions lib/fog/google/models/compute/target_instances.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,33 @@ class Google
class TargetInstances < Fog::Collection
model Fog::Compute::Google::TargetInstance

def all(zone = nil)
if zone.nil?
data = []
data = service.list_target_instances.body['items'] || []

def all(filters={})
if filters['zone']
data = service.list_target_instances(filters['zone']).body['items'] || []
else
data = service.list_target_instances(zone).body['items'] || []
data = []
service.list_aggregated_target_instances.body['items'].each_value do |zone|
data.concat(zone['targetInstances']) if zone['targetInstances']
end
end
load(data)
end

def get(identity, zone=nil)
response = service.get_target_instance(identity, zone)
new(response.body) unless response.nil?
response = nil
if zone
response = service.get_target_instance(identity, zone).body
else
target_instances = service.list_aggregated_target_instances(:filter => "name eq .*#{identity}").body['items']
target_instance = target_instances.each_value.select { |zone| zone.key?('targetInstances') }

# It can only be 1 target_instance with the same name across all regions
response = target_instance.first['targetInstances'].first unless target_instance.empty?
end
return nil if response.nil?
new(response)
rescue Fog::Errors::NotFound
nil
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/google/models/compute/url_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class UrlMap < Fog::Model

attribute :kind, :aliases => 'kind'
attribute :creationTimestamp, :aliases => 'creation_timestamp'
attribute :defaultService, :aliases => 'default_service'
attribute :defaultService, :aliases => ['default_service', :default_service]
attribute :description, :aliases => 'description'
attribute :fingerprint, :aliases => 'fingerprint'
attribute :hostRules, :aliases => 'host_rules'
Expand Down
7 changes: 5 additions & 2 deletions lib/fog/google/models/compute/url_maps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ def all
end

def get(identity)
response = service.get_url_map(identity)
new(response.body) unless response.nil?
if url_map = service.get_url_map(identity).body
new(url_map)
end
rescue Fog::Errors::NotFound
nil
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/google/requests/compute/insert_target_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def insert_target_instance(target_instance_name, zone_name, opts = {})
'project' => @project,
'zone' => zone_name,
}
body_object = { 'name' => target_pool_name }
body_object = { 'name' => target_instance_name }
body_object.merge!(opts)

request(api_method, parameters, body_object=body_object)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module Fog
module Compute
class Google
# XXX @ihmccreery added this mock to get the Shindo tests to pass. I don't really understand how mocks are supposed to work; I'm in the process of moving
# all testing over to Minitest, but in the meantime, the Shindo tests need to pass. This Mock should be considered with a *lot* of skepticism.
class Mock
def list_aggregated_target_instances(options = {})
# Create a Hash of unique zones from the target_instances Array previously filled when target_instances are created
zones = Hash[self.data[:target_instances].values.map { |target_instance| ["zones/#{target_instance['zone'].split('/')[-1]}", {'targetInstances' => [] }] }]
if options[:filter]
# Look up for the target_instance name
target_instance = self.data[:target_instances][options[:filter].gsub(/name eq \.\*/, '')]
# Fill the zones Hash with the target_instance (if it's found)
zones["zones/#{target_instance['zone'].split('/')[-1]}"]['targetInstances'].concat([target_instance]) if target_instance
else
# Fill the zones Hash with the target_instances attached to each zone
self.data[:target_instances].values.each { |target_instance| zones["zones/#{target_instance['zone'].split('/')[-1]}"]['targetInstances'].concat([target_instance]) }
end
build_excon_response({
"kind" => "compute#targetInstanceAggregatedList",
"selfLink" => "https://www.googleapis.com/compute/#{api_version}/projects/#{@project}/aggregated/targetInstances",
"id" => "projects/#{@project}/aggregated/targetInstances",
"items" => zones

})
end
end

class Real
def list_aggregated_target_instances(options = {})
api_method = @compute.target_instances.aggregated_list
parameters = {
'project' => @project,
}
parameters['filter'] = options[:filter] if options[:filter]

request(api_method, parameters)
end
end
end
end
end
15 changes: 0 additions & 15 deletions spec/minitest_helper.rb

This file was deleted.

Loading