fog-google 1.7.1 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/.travis.yml +0 -3
  4. data/CHANGELOG.md +45 -1
  5. data/CONTRIBUTING.md +11 -5
  6. data/README.md +0 -2
  7. data/fog-google.gemspec +4 -5
  8. data/lib/fog/bin/google.rb +4 -0
  9. data/lib/fog/compute/google/models/addresses.rb +9 -3
  10. data/lib/fog/compute/google/models/backend_services.rb +3 -2
  11. data/lib/fog/compute/google/models/disk_types.rb +5 -6
  12. data/lib/fog/compute/google/models/disks.rb +10 -4
  13. data/lib/fog/compute/google/models/firewalls.rb +3 -2
  14. data/lib/fog/compute/google/models/forwarding_rules.rb +8 -12
  15. data/lib/fog/compute/google/models/global_addresses.rb +3 -2
  16. data/lib/fog/compute/google/models/global_forwarding_rules.rb +3 -2
  17. data/lib/fog/compute/google/models/http_health_checks.rb +4 -3
  18. data/lib/fog/compute/google/models/images.rb +23 -12
  19. data/lib/fog/compute/google/models/instance_group_managers.rb +10 -7
  20. data/lib/fog/compute/google/models/instance_groups.rb +21 -15
  21. data/lib/fog/compute/google/models/instance_templates.rb +3 -2
  22. data/lib/fog/compute/google/models/machine_types.rb +13 -4
  23. data/lib/fog/compute/google/models/networks.rb +3 -2
  24. data/lib/fog/compute/google/models/operations.rb +8 -8
  25. data/lib/fog/compute/google/models/projects.rb +3 -2
  26. data/lib/fog/compute/google/models/regions.rb +3 -2
  27. data/lib/fog/compute/google/models/routes.rb +3 -2
  28. data/lib/fog/compute/google/models/servers.rb +7 -7
  29. data/lib/fog/compute/google/models/snapshots.rb +5 -4
  30. data/lib/fog/compute/google/models/ssl_certificates.rb +4 -3
  31. data/lib/fog/compute/google/models/subnetworks.rb +13 -7
  32. data/lib/fog/compute/google/models/target_http_proxies.rb +3 -2
  33. data/lib/fog/compute/google/models/target_https_proxies.rb +3 -2
  34. data/lib/fog/compute/google/models/target_instances.rb +8 -8
  35. data/lib/fog/compute/google/models/target_pools.rb +7 -10
  36. data/lib/fog/compute/google/models/url_maps.rb +3 -2
  37. data/lib/fog/compute/google/models/zones.rb +4 -2
  38. data/lib/fog/compute/google/real.rb +2 -0
  39. data/lib/fog/compute/google/requests/list_aggregated_instance_groups.rb +1 -2
  40. data/lib/fog/dns/google/real.rb +1 -0
  41. data/lib/fog/google/models/sql/instances.rb +4 -1
  42. data/lib/fog/google/monitoring/real.rb +1 -0
  43. data/lib/fog/google/pubsub/real.rb +1 -0
  44. data/lib/fog/google/shared.rb +15 -1
  45. data/lib/fog/google/sql/real.rb +1 -0
  46. data/lib/fog/google/version.rb +1 -1
  47. data/lib/fog/storage/google_json/real.rb +2 -0
  48. data/test/helpers/integration_test_helper.rb +2 -0
  49. data/test/helpers/test_collection.rb +26 -3
  50. data/test/integration/compute/core_compute/test_client_options.rb +12 -0
  51. data/test/integration/compute/core_compute/test_disk_types.rb +9 -0
  52. data/test/integration/compute/core_compute/test_images.rb +21 -0
  53. data/test/integration/compute/core_compute/test_machine_types.rb +13 -0
  54. data/test/integration/compute/core_compute/test_operations.rb +19 -1
  55. data/test/integration/compute/instance_groups/test_instance_group_managers.rb +1 -1
  56. data/test/integration/factories/addresses_factory.rb +4 -0
  57. data/test/integration/factories/collection_factory.rb +1 -1
  58. data/test/integration/factories/disks_factory.rb +4 -0
  59. data/test/integration/factories/forwarding_rules_factory.rb +4 -0
  60. data/test/integration/factories/images_factory.rb +4 -0
  61. data/test/integration/factories/instance_group_manager_factory.rb +8 -0
  62. data/test/integration/factories/instance_groups_factory.rb +4 -0
  63. data/test/integration/factories/servers_factory.rb +8 -0
  64. data/test/integration/factories/subnetworks_factory.rb +4 -0
  65. data/test/integration/factories/target_instances_factory.rb +4 -0
  66. data/test/integration/factories/target_pools_factory.rb +4 -0
  67. data/test/unit/compute/test_common_collections.rb +19 -8
  68. data/test/unit/compute/test_common_models.rb +10 -11
  69. data/test/unit/compute/test_server.rb +2 -1
  70. data/test/unit/dns/test_common_collections.rb +43 -0
  71. data/test/unit/monitoring/test_comon_collections.rb +44 -0
  72. data/test/unit/pubsub/test_common_collections.rb +35 -0
  73. data/test/unit/sql/test_common_collections.rb +46 -0
  74. data/test/unit/storage/test_common_json_collections.rb +38 -0
  75. data/test/unit/storage/test_common_xml_collections.rb +39 -0
  76. metadata +33 -27
@@ -0,0 +1,12 @@
1
+ require "helpers/integration_test_helper"
2
+
3
+ class TestComputeClient < FogIntegrationTest
4
+ def test_client_options
5
+ # XXX This is a very rudimentary test checking that proxy option is applied
6
+ client_options = { proxy_url: "https://user:password@host:8080" }
7
+ connection = Fog::Compute::Google.new(google_client_options: client_options)
8
+
9
+ err = assert_raises(ArgumentError) { connection.servers.all }
10
+ assert_match(/unsupported proxy/, err.message)
11
+ end
12
+ end
@@ -16,6 +16,15 @@ class TestDiskTypes < FogIntegrationTest
16
16
  "Number of all disk type references should be greater or equal to test zones * disk types")
17
17
  end
18
18
 
19
+ def test_scoped_all
20
+ subject_list = @subject.all
21
+ scoped_subject_list = @subject.all(zone: TEST_ZONE)
22
+
23
+ # Assert that whatever .all(scope) returns is a subset of .all
24
+ assert(scoped_subject_list.all? { |x| subject_list.include? x },
25
+ "Output of @subject.all(zone:#{TEST_ZONE}) must be a subset of @subject.all")
26
+ end
27
+
19
28
  def test_get
20
29
  NAMES.each do |name|
21
30
  ZONES.each do |zone|
@@ -8,4 +8,25 @@ class TestImages < FogIntegrationTest
8
8
  @subject = Fog::Compute[:google].images
9
9
  @factory = ImagesFactory.new(namespaced_name)
10
10
  end
11
+
12
+ def test_get_specific_image
13
+ image = @subject.get(TEST_IMAGE)
14
+ refute_nil(image, "Images.get(#{TEST_IMAGE}) should not return nil")
15
+ assert_equal(image.family, TEST_IMAGE_FAMILY)
16
+ assert_equal(image.project, TEST_IMAGE_PROJECT)
17
+ end
18
+
19
+ def test_get_specific_image_from_project
20
+ image = @subject.get(TEST_IMAGE,TEST_IMAGE_PROJECT)
21
+ refute_nil(image, "Images.get(#{TEST_IMAGE}) should not return nil")
22
+ assert_equal(image.family, TEST_IMAGE_FAMILY)
23
+ assert_equal(image.project, TEST_IMAGE_PROJECT)
24
+ end
25
+
26
+ def test_get_from_family
27
+ image = @subject.get_from_family(TEST_IMAGE_FAMILY)
28
+ refute_nil(image,"Images.get_from_family(#{TEST_IMAGE_FAMILY}) should not return nil")
29
+ assert_equal(image.family, TEST_IMAGE_FAMILY)
30
+ assert_equal(image.project, TEST_IMAGE_PROJECT)
31
+ end
11
32
  end
@@ -23,6 +23,15 @@ class TestMachineTypes < FogIntegrationTest
23
23
  "Number of all machine types should be greater or equal to test zones * machine_types")
24
24
  end
25
25
 
26
+ def test_scoped_all
27
+ subject_list = @subject.all
28
+ scoped_subject_list = @subject.all(zone: TEST_ZONE)
29
+
30
+ # Assert that whatever .all(scope) returns is a subset of .all
31
+ assert(scoped_subject_list.all? { |x| subject_list.include? x },
32
+ "Output of @subject.all(zone:#{TEST_ZONE}) must be a subset of @subject.all")
33
+ end
34
+
26
35
  def test_get
27
36
  # This tests only in last zone since not all zones contain all machine types
28
37
  NAMES.each do |name|
@@ -39,4 +48,8 @@ class TestMachineTypes < FogIntegrationTest
39
48
  def test_enumerable
40
49
  assert_respond_to @subject, :each
41
50
  end
51
+
52
+ def test_nil_get
53
+ assert_nil @subject.get(nil)
54
+ end
42
55
  end
@@ -1,6 +1,6 @@
1
1
  require "helpers/integration_test_helper"
2
2
 
3
- class TestRoutes < FogIntegrationTest
3
+ class TestOperations < FogIntegrationTest
4
4
  def setup
5
5
  @subject = Fog::Compute[:google].operations
6
6
  end
@@ -17,6 +17,24 @@ class TestRoutes < FogIntegrationTest
17
17
  end
18
18
  end
19
19
 
20
+ def test_zone_scoped_all
21
+ subject_list = @subject.all
22
+ scoped_subject_list = @subject.all(zone: TEST_ZONE)
23
+
24
+ # Assert that whatever .all(scope) returns is a subset of .all
25
+ assert(scoped_subject_list.all? { |x| subject_list.include? x },
26
+ "Output of @subject.all(zone:#{TEST_ZONE}) must be a subset of @subject.all")
27
+ end
28
+
29
+ def test_region_scoped_all
30
+ subject_list = @subject.all
31
+ scoped_subject_list = @subject.all(region: TEST_REGION)
32
+
33
+ # Assert that whatever .all(scope) returns is a subset of .all
34
+ assert(scoped_subject_list.all? { |x| subject_list.include? x },
35
+ "Output of @subject.all(region:#{TEST_REGION}) must be a subset of @subject.all")
36
+ end
37
+
20
38
  def test_bad_get
21
39
  assert_nil @subject.get("bad-name")
22
40
  end
@@ -1,7 +1,7 @@
1
1
  require "helpers/integration_test_helper"
2
2
  require "integration/factories/instance_group_manager_factory"
3
3
 
4
- class TestInstanceGroupManager < FogIntegrationTest
4
+ class TestInstanceGroupManagers < FogIntegrationTest
5
5
  include TestCollection
6
6
 
7
7
  def setup
@@ -9,6 +9,10 @@ class AddressesFactory < CollectionFactory
9
9
  @subject.get(identity, TEST_REGION)
10
10
  end
11
11
 
12
+ def all
13
+ @subject.all(region: TEST_REGION)
14
+ end
15
+
12
16
  def params
13
17
  { :name => resource_name,
14
18
  :region => TEST_REGION }
@@ -12,7 +12,7 @@ class CollectionFactory
12
12
  # @param async [FalseClass or TrueClass] perform resource destruction asynchronously
13
13
  def cleanup(async = false)
14
14
  suit_name = @example.gsub(/\W/, "").tr("_", "-").downcase.split('-')[0]
15
- resources = @subject.all.select { |resource| resource.name.match /#{PREFIX}-[0-9]*-#{suit_name}/ }
15
+ resources = @subject.all.select { |resource| resource.name.match(/#{PREFIX}-[0-9]*-#{suit_name}/) }
16
16
  if DEBUG
17
17
  p "Cleanup invoked in #{self} for example: #{@example}"
18
18
  p "Resources to be deleted: #{resources.map { |r| r.name }}"
@@ -9,6 +9,10 @@ class DisksFactory < CollectionFactory
9
9
  @subject.get(identity, TEST_ZONE)
10
10
  end
11
11
 
12
+ def all
13
+ @subject.all(zone: TEST_ZONE)
14
+ end
15
+
12
16
  def params
13
17
  { :name => resource_name,
14
18
  :zone_name => TEST_ZONE,
@@ -12,6 +12,10 @@ class ForwardingRulesFactory < CollectionFactory
12
12
  @target_pools.cleanup
13
13
  end
14
14
 
15
+ def all
16
+ @subject.all(region: TEST_REGION)
17
+ end
18
+
15
19
  def params
16
20
  { :name => resource_name,
17
21
  :port_range => "80-80",
@@ -5,6 +5,10 @@ class ImagesFactory < CollectionFactory
5
5
  super(Fog::Compute[:google].images, example)
6
6
  end
7
7
 
8
+ def get(identity)
9
+ @subject.get(identity, TEST_PROJECT)
10
+ end
11
+
8
12
  def params
9
13
  { :name => resource_name,
10
14
  :raw_disk => { :source => TEST_RAW_DISK_SOURCE } }
@@ -12,6 +12,14 @@ class InstanceGroupManagerFactory < CollectionFactory
12
12
  @instance_template.cleanup
13
13
  end
14
14
 
15
+ def get(identity)
16
+ @subject.get(identity, TEST_ZONE)
17
+ end
18
+
19
+ def all
20
+ @subject.all(zone: TEST_ZONE)
21
+ end
22
+
15
23
  def params
16
24
  { :name => resource_name,
17
25
  :zone => TEST_ZONE,
@@ -9,6 +9,10 @@ class InstanceGroupsFactory < CollectionFactory
9
9
  @subject.get(identity, TEST_ZONE)
10
10
  end
11
11
 
12
+ def all
13
+ @subject.all(zone: TEST_ZONE)
14
+ end
15
+
12
16
  def params
13
17
  { :name => resource_name,
14
18
  :zone => TEST_ZONE }
@@ -13,6 +13,14 @@ class ServersFactory < CollectionFactory
13
13
  @disks.cleanup
14
14
  end
15
15
 
16
+ def get(identity)
17
+ @subject.get(identity, TEST_ZONE)
18
+ end
19
+
20
+ def all
21
+ @subject.all(zone: TEST_ZONE)
22
+ end
23
+
16
24
  def params
17
25
  { :name => resource_name,
18
26
  :zone => TEST_ZONE,
@@ -13,6 +13,10 @@ class SubnetworksFactory < CollectionFactory
13
13
  @subject.get(identity, TEST_REGION)
14
14
  end
15
15
 
16
+ def all
17
+ @subject.all(region: TEST_REGION)
18
+ end
19
+
16
20
  def params
17
21
  { :name => resource_name,
18
22
  :network => "default",
@@ -12,6 +12,10 @@ class TargetInstancesFactory < CollectionFactory
12
12
  @servers.cleanup
13
13
  end
14
14
 
15
+ def all
16
+ @subject.all(zone: TEST_ZONE)
17
+ end
18
+
15
19
  def params
16
20
  { :name => resource_name,
17
21
  :zone => TEST_ZONE,
@@ -15,6 +15,10 @@ class TargetPoolsFactory < CollectionFactory
15
15
  @http_health_checks.cleanup
16
16
  end
17
17
 
18
+ def all
19
+ @subject.all(region: TEST_REGION)
20
+ end
21
+
18
22
  def params
19
23
  { :name => resource_name,
20
24
  :region => TEST_REGION,
@@ -3,29 +3,40 @@ require "helpers/test_helper"
3
3
  class UnitTestCollections < MiniTest::Test
4
4
  def setup
5
5
  Fog.mock!
6
- @client = Fog::Compute.new(:provider => "Google", :google_project => "foo")
7
6
 
8
- # Top-level ancestors we do not dest
9
- common_ancestors = [Fog::Collection, Fog::Association, Fog::PagedCollection]
10
- # Projects do not have a "list" method in compute API
11
- exceptions = [Fog::Compute::Google::Projects]
7
+ @client = Fog::Compute.new(provider: "google",
8
+ google_project: "foo")
9
+
10
+ # Exceptions that do not pass test_common_methods:
11
+ #
12
+ # Projects do not have a "list" method in compute API, so 'all' is not implemented
13
+ @common_method_exceptions = [Fog::Compute::Google::Projects]
12
14
  # Enumerate all descendants of Fog::Collection
13
15
  descendants = ObjectSpace.each_object(Fog::Collection.singleton_class).to_a
14
16
 
15
- @collections = descendants - common_ancestors - exceptions
17
+ @collections = descendants.select { |d| d.name.match(/Fog::Compute::Google/) }
16
18
  end
17
19
 
18
20
  def teardown
19
21
  Fog.unmock!
20
22
  end
21
23
 
24
+ # This tests whether Fog::Compute::Google collections have common lifecycle methods
22
25
  def test_common_methods
23
- # This tests whether Fog::Compute::Google collections have common lifecycle methods
24
- @collections.each do |klass|
26
+ subjects = @collections - @common_method_exceptions
27
+ subjects.each do |klass|
25
28
  obj = klass.new
26
29
  assert obj.respond_to?(:all), "#{klass} should have an .all method"
27
30
  assert obj.respond_to?(:get), "#{klass} should have a .get method"
28
31
  assert obj.respond_to?(:each), "#{klass} should behave like Enumerable"
29
32
  end
30
33
  end
34
+
35
+ def test_collection_get_arguments
36
+ @collections.each do |klass|
37
+ obj = klass.new
38
+ assert_operator(obj.method(:get).arity, :<=, 1,
39
+ "#{klass} should have at most 1 required parameter in get()")
40
+ end
41
+ end
31
42
  end
@@ -3,22 +3,21 @@ require "helpers/test_helper"
3
3
  class UnitTestModels < MiniTest::Test
4
4
  def setup
5
5
  Fog.mock!
6
- @client = Fog::Compute.new(:provider => "Google", :google_project => "foo")
6
+ @client = Fog::Compute.new(provider: "google",
7
+ google_project: "foo")
7
8
 
8
- # Top-level ancestors we do not test
9
- common_ancestors = [Fog::Model, Fog::Compute::Server]
10
9
  # Do not test models that do not have a create method in API
11
- exceptions = [ Fog::Compute::Google::MachineType,
12
- Fog::Compute::Google::Region,
13
- Fog::Compute::Google::DiskType,
14
- Fog::Compute::Google::Operation,
15
- Fog::Compute::Google::Zone,
16
- Fog::Compute::Google::Snapshot,
17
- Fog::Compute::Google::Project ]
10
+ exceptions = [Fog::Compute::Google::MachineType,
11
+ Fog::Compute::Google::Region,
12
+ Fog::Compute::Google::DiskType,
13
+ Fog::Compute::Google::Operation,
14
+ Fog::Compute::Google::Zone,
15
+ Fog::Compute::Google::Snapshot,
16
+ Fog::Compute::Google::Project]
18
17
  # Enumerate all descendants of Fog::Model
19
18
  descendants = ObjectSpace.each_object(Fog::Model.singleton_class).to_a
20
19
 
21
- @models = descendants - common_ancestors - exceptions
20
+ @models = descendants.select { |d| d.name.match(/Fog::Compute::Google/) } - exceptions
22
21
  end
23
22
 
24
23
  def teardown
@@ -3,7 +3,8 @@ require "helpers/test_helper"
3
3
  class UnitTestServer < MiniTest::Test
4
4
  def setup
5
5
  Fog.mock!
6
- @client = Fog::Compute.new(:provider => "Google", :google_project => "foo")
6
+ @client = Fog::Compute.new(provider: "google",
7
+ google_project: "foo")
7
8
  end
8
9
 
9
10
  def teardown
@@ -0,0 +1,43 @@
1
+ require "helpers/test_helper"
2
+
3
+ class UnitTestDNSCollections < MiniTest::Test
4
+ def setup
5
+ Fog.mock!
6
+ @client = Fog::DNS.new(provider: "google",
7
+ google_project: "foo")
8
+
9
+ # Exceptions that do not pass test_common_methods:
10
+ #
11
+ # DNS Projects API does not support 'list', so 'all' method is not possible
12
+ @common_methods_exceptions = [Fog::DNS::Google::Projects]
13
+ # Enumerate all descendants of Fog::Collection
14
+ descendants = ObjectSpace.each_object(Fog::Collection.singleton_class)
15
+
16
+ @collections = descendants.select { |d| d.name.match(/Fog::DNS::Google/) }
17
+ end
18
+
19
+ def teardown
20
+ Fog.unmock!
21
+ end
22
+
23
+ # This tests whether Fog::Compute::Google collections have common lifecycle methods
24
+ def test_common_methods
25
+ subjects = @collections - @common_methods_exceptions
26
+ subjects.each do |klass|
27
+ obj = klass.new
28
+ assert obj.respond_to?(:all), "#{klass} should have an .all method"
29
+ assert obj.respond_to?(:get), "#{klass} should have a .get method"
30
+ assert obj.respond_to?(:each), "#{klass} should behave like Enumerable"
31
+ end
32
+ end
33
+
34
+ def test_collection_get_arguments
35
+ # TODO: Fixture for #352
36
+ skip
37
+ @collections.each do |klass|
38
+ obj = klass.new
39
+ assert_operator(obj.method(:get).arity, :<=, 1,
40
+ "#{klass} should have at most 1 required parameter in get()")
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,44 @@
1
+ require "helpers/test_helper"
2
+
3
+ class UnitTestMonitoringCollections < MiniTest::Test
4
+ def setup
5
+ Fog.mock!
6
+ @client = Fog::Monitoring.new(provider: "google",
7
+ google_project: "foo")
8
+
9
+ # Exceptions that do not pass test_common_methods:
10
+ #
11
+ # TimeSeries API has no 'get' method
12
+ @common_method_exceptions = [Fog::Google::Monitoring::TimeseriesCollection]
13
+ # Enumerate all descendants of Fog::Collection
14
+ descendants = ObjectSpace.each_object(Fog::Collection.singleton_class).to_a
15
+
16
+ @collections = descendants.select { |d| d.name.match(/Fog::Google::Monitoring/) }
17
+ end
18
+
19
+ def teardown
20
+ Fog.unmock!
21
+ end
22
+
23
+ # This tests whether Fog::Compute::Google collections have common lifecycle methods
24
+ def test_common_methods
25
+ subjects = @collections - @common_method_exceptions
26
+
27
+ subjects.each do |klass|
28
+ obj = klass.new
29
+ assert obj.respond_to?(:all), "#{klass} should have an .all method"
30
+ assert obj.respond_to?(:get), "#{klass} should have a .get method"
31
+ assert obj.respond_to?(:each), "#{klass} should behave like Enumerable"
32
+ end
33
+ end
34
+
35
+ def test_collection_get_arguments
36
+ @collections.each do |klass|
37
+ obj = klass.new
38
+ if obj.respond_to?(:get)
39
+ assert_operator(obj.method(:get).arity, :<=, 1,
40
+ "#{klass} should have at most 1 required parameter in get()")
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,35 @@
1
+ require "helpers/test_helper"
2
+
3
+ class UnitTestPubsubCollections < MiniTest::Test
4
+ def setup
5
+ Fog.mock!
6
+ @client = Fog::Google::Pubsub.new(google_project: "foo")
7
+
8
+ # Enumerate all descendants of Fog::Collection
9
+ descendants = ObjectSpace.each_object(Fog::Collection.singleton_class)
10
+
11
+ @collections = descendants.select { |d| d.name.match(/Fog::Google::Pubsub/) }
12
+ end
13
+
14
+ def teardown
15
+ Fog.unmock!
16
+ end
17
+
18
+ def test_common_methods
19
+ # This tests whether Fog::Compute::Google collections have common lifecycle methods
20
+ @collections.each do |klass|
21
+ obj = klass.new
22
+ assert obj.respond_to?(:all), "#{klass} should have an .all method"
23
+ assert obj.respond_to?(:get), "#{klass} should have a .get method"
24
+ assert obj.respond_to?(:each), "#{klass} should behave like Enumerable"
25
+ end
26
+ end
27
+
28
+ def test_collection_get_arguments
29
+ @collections.each do |klass|
30
+ obj = klass.new
31
+ assert_operator(obj.method(:get).arity, :<=, 1,
32
+ "#{klass} should have at most 1 required parameter in get()")
33
+ end
34
+ end
35
+ end