fog-google 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +5 -5
  2. data/.codecov.yml +2 -0
  3. data/.rubocop.yml +4 -1
  4. data/CHANGELOG.md +51 -0
  5. data/CONTRIBUTING.md +85 -17
  6. data/CONTRIBUTORS.md +6 -4
  7. data/Gemfile +6 -0
  8. data/MIGRATING.md +1 -11
  9. data/README.md +15 -4
  10. data/ci/credentials.yml.template +2 -0
  11. data/ci/docker-image/Dockerfile +1 -3
  12. data/ci/pipeline.yml +117 -12
  13. data/ci/tasks/run-int.sh +3 -2
  14. data/ci/tasks/run-int.yml +1 -1
  15. data/examples/create_instance.rb +40 -25
  16. data/examples/get_list_images.rb +1 -1
  17. data/examples/load-balance.rb +1 -1
  18. data/examples/metadata.rb +1 -1
  19. data/examples/network.rb +1 -1
  20. data/fog-google.gemspec +8 -6
  21. data/lib/fog/compute/google/models/address.rb +1 -1
  22. data/lib/fog/compute/google/models/backend_service.rb +1 -1
  23. data/lib/fog/compute/google/models/disk.rb +2 -2
  24. data/lib/fog/compute/google/models/firewall.rb +23 -3
  25. data/lib/fog/compute/google/models/forwarding_rule.rb +1 -1
  26. data/lib/fog/compute/google/models/global_address.rb +1 -1
  27. data/lib/fog/compute/google/models/global_forwarding_rule.rb +1 -1
  28. data/lib/fog/compute/google/models/http_health_check.rb +2 -2
  29. data/lib/fog/compute/google/models/image.rb +1 -1
  30. data/lib/fog/compute/google/models/instance_group_manager.rb +1 -1
  31. data/lib/fog/compute/google/models/instance_template.rb +1 -1
  32. data/lib/fog/compute/google/models/route.rb +1 -1
  33. data/lib/fog/compute/google/models/server.rb +59 -5
  34. data/lib/fog/compute/google/models/servers.rb +1 -1
  35. data/lib/fog/compute/google/models/ssl_certificate.rb +1 -1
  36. data/lib/fog/compute/google/models/subnetwork.rb +1 -1
  37. data/lib/fog/compute/google/models/target_http_proxy.rb +1 -1
  38. data/lib/fog/compute/google/models/target_https_proxy.rb +14 -1
  39. data/lib/fog/compute/google/models/target_instance.rb +1 -1
  40. data/lib/fog/compute/google/models/target_pool.rb +1 -1
  41. data/lib/fog/compute/google/models/url_map.rb +1 -1
  42. data/lib/fog/compute/google/requests/insert_server.rb +1 -1
  43. data/lib/fog/dns/google/models/record.rb +1 -1
  44. data/lib/fog/google/models/sql/instance.rb +1 -1
  45. data/lib/fog/google/models/sql/user.rb +1 -1
  46. data/lib/fog/google/version.rb +1 -1
  47. data/lib/fog/storage/google_json.rb +4 -1
  48. data/lib/fog/storage/google_json/mock.rb +3 -0
  49. data/lib/fog/storage/google_json/models/file.rb +2 -2
  50. data/lib/fog/storage/google_json/models/files.rb +2 -2
  51. data/lib/fog/storage/google_json/real.rb +3 -0
  52. data/lib/fog/storage/google_json/requests/get_object_http_url.rb +6 -7
  53. data/lib/fog/storage/google_json/requests/get_object_https_url.rb +6 -7
  54. data/lib/fog/storage/google_json/requests/get_object_url.rb +4 -4
  55. data/lib/fog/storage/google_json/utils.rb +7 -1
  56. data/lib/fog/storage/google_xml/models/file.rb +2 -2
  57. data/lib/fog/storage/google_xml/models/files.rb +4 -4
  58. data/lib/fog/storage/google_xml/requests/get_object_http_url.rb +8 -7
  59. data/lib/fog/storage/google_xml/requests/get_object_https_url.rb +7 -7
  60. data/lib/fog/storage/google_xml/requests/get_object_url.rb +5 -4
  61. data/lib/fog/storage/google_xml/utils.rb +7 -1
  62. data/tasks/test.rake +45 -23
  63. data/test/helpers/integration_test_helper.rb +67 -0
  64. data/test/helpers/test_helper.rb +14 -10
  65. data/test/integration/compute/core_compute/test_coverage.rb +6 -0
  66. data/test/integration/compute/{test_disk_types.rb → core_compute/test_disk_types.rb} +0 -0
  67. data/test/integration/compute/{disks/test_compute_disk_models.rb → core_compute/test_disks.rb} +0 -0
  68. data/test/integration/compute/{test_images.rb → core_compute/test_images.rb} +0 -0
  69. data/test/integration/compute/core_compute/test_machine_types.rb +42 -0
  70. data/test/integration/compute/core_compute/test_operations.rb +27 -0
  71. data/test/integration/compute/core_compute/test_projects.rb +19 -0
  72. data/test/integration/compute/{test_regions.rb → core_compute/test_regions.rb} +0 -0
  73. data/test/integration/compute/core_compute/test_servers.rb +109 -0
  74. data/test/integration/compute/{test_snapshots.rb → core_compute/test_snapshots.rb} +0 -0
  75. data/test/integration/compute/core_compute/test_zones.rb +35 -0
  76. data/test/integration/compute/core_networking/test_addresses.rb +84 -0
  77. data/test/integration/compute/core_networking/test_coverage.rb +6 -0
  78. data/test/integration/compute/core_networking/test_firewalls.rb +11 -0
  79. data/test/integration/compute/core_networking/test_networks.rb +41 -0
  80. data/test/integration/compute/core_networking/test_routes.rb +26 -0
  81. data/test/integration/compute/core_networking/test_subnetworks.rb +11 -0
  82. data/test/integration/compute/instance_groups/test_coverage.rb +6 -0
  83. data/test/integration/compute/{test_instance_group_managers.rb → instance_groups/test_instance_group_managers.rb} +0 -0
  84. data/test/integration/compute/instance_groups/test_instance_groups.rb +11 -0
  85. data/test/integration/compute/{test_instance_templates.rb → instance_groups/test_instance_templates.rb} +0 -0
  86. data/test/integration/compute/{test_backend_services.rb → loadbalancing/test_backend_services.rb} +0 -0
  87. data/test/integration/compute/loadbalancing/test_coverage.rb +6 -0
  88. data/test/integration/compute/{test_forwarding_rules.rb → loadbalancing/test_forwarding_rules.rb} +0 -0
  89. data/test/integration/compute/loadbalancing/test_global_addresses.rb +11 -0
  90. data/test/integration/compute/{test_global_forwarding_rules.rb → loadbalancing/test_global_forwarding_rules.rb} +0 -0
  91. data/test/integration/compute/{test_http_health_checks.rb → loadbalancing/test_http_health_checks.rb} +0 -0
  92. data/test/integration/compute/loadbalancing/test_ssl_certificates.rb +11 -0
  93. data/test/integration/compute/{test_target_http_proxies.rb → loadbalancing/test_target_http_proxies.rb} +0 -0
  94. data/test/integration/compute/loadbalancing/test_target_https_proxies.rb +11 -0
  95. data/test/integration/compute/{test_target_instances.rb → loadbalancing/test_target_instances.rb} +0 -0
  96. data/test/integration/compute/loadbalancing/test_target_pools.rb +55 -0
  97. data/test/integration/compute/{test_url_maps.rb → loadbalancing/test_url_maps.rb} +0 -0
  98. data/test/integration/factories/addresses_factory.rb +16 -0
  99. data/test/integration/factories/collection_factory.rb +24 -3
  100. data/test/integration/factories/disks_factory.rb +1 -0
  101. data/test/integration/factories/firewalls_factory.rb +13 -0
  102. data/test/integration/factories/global_addresses_factory.rb +15 -0
  103. data/test/integration/factories/instance_groups_factory.rb +16 -0
  104. data/test/integration/factories/instance_template_factory.rb +1 -0
  105. data/test/integration/factories/networks_factory.rb +16 -0
  106. data/test/integration/factories/ssl_certificates_factory.rb +13 -0
  107. data/test/integration/factories/subnetworks_factory.rb +22 -0
  108. data/test/integration/factories/target_https_proxies_factory.rb +26 -0
  109. data/test/integration/factories/target_pools_factory.rb +2 -2
  110. data/test/integration/monitoring/test_coverage.rb +6 -0
  111. data/test/integration/monitoring/test_timeseries.rb +1 -1
  112. data/test/integration/pubsub/test_coverage.rb +6 -0
  113. data/test/integration/sql/{test_common_flags.rb → sqlv1/test_common_flags.rb} +0 -0
  114. data/test/integration/sql/{test_common_tiers.rb → sqlv1/test_common_tiers.rb} +0 -0
  115. data/test/integration/sql/sqlv1/test_coverage.rb +6 -0
  116. data/test/integration/sql/{test_v1_certs.rb → sqlv1/test_v1_certs.rb} +0 -0
  117. data/test/integration/sql/{test_v1_instances.rb → sqlv1/test_v1_instances.rb} +0 -0
  118. data/test/integration/sql/{test_v1_users.rb → sqlv1/test_v1_users.rb} +0 -0
  119. data/test/integration/sql/sqlv2/test_coverage.rb +6 -0
  120. data/test/integration/sql/{test_v2_instances.rb → sqlv2/test_v2_instances.rb} +0 -0
  121. data/test/integration/storage/test_coverage.rb +6 -0
  122. data/test/unit/storage/test_json_requests.rb +45 -0
  123. data/test/unit/storage/test_xml_requests.rb +20 -0
  124. metadata +115 -92
  125. data/test/integration/compute/addresses/addresses_shared.rb +0 -59
  126. data/test/integration/compute/addresses/test_compute_address_models.rb +0 -105
  127. data/test/integration/compute/addresses/test_compute_address_requests.rb +0 -52
  128. data/test/integration/compute/disks/test_compute_disk_requests.rb +0 -92
  129. data/test/integration/compute/test_compute_addresses_collection.rb +0 -75
  130. data/test/integration/compute/test_compute_networks_collection.rb +0 -69
  131. data/test/integration/compute/test_servers.rb +0 -54
  132. data/test/integration/compute/test_target_pools.rb +0 -38
@@ -5,12 +5,19 @@ require "helpers/test_collection"
5
5
  # XXX not sure if this will work on Travis CI or not
6
6
  Fog.credential = :test
7
7
 
8
+ # Enable test debugging, providing additional information in some methods
9
+ DEBUG = ENV['FOG_TEST_DEBUG'] || false
10
+
8
11
  # Helpers
9
12
 
13
+ TEST_PROJECT = Fog.credentials[:google_project]
14
+
10
15
  TEST_ZONE = "us-central1-f".freeze
11
16
  TEST_REGION = "us-central1".freeze
12
17
  TEST_SIZE_GB = 10
13
18
  TEST_MACHINE_TYPE = "n1-standard-1".freeze
19
+ TEST_IMAGE = "debian-9-stretch-v20180611".freeze
20
+
14
21
  # XXX This depends on a public image in gs://fog-test-bucket; there may be a better way to do this
15
22
  # The image was created like so: https://cloud.google.com/compute/docs/images#export_an_image_to_google_cloud_storage
16
23
  TEST_RAW_DISK_SOURCE = "http://storage.googleapis.com/fog-test-bucket/fog-test-raw-disk-source.image.tar.gz".freeze
@@ -21,6 +28,66 @@ TEST_SQL_REGION_FIRST = "us-central".freeze
21
28
  TEST_SQL_TIER_SECOND = "db-n1-standard-1".freeze
22
29
  TEST_SQL_REGION_SECOND = TEST_REGION
23
30
 
31
+ # Test certificate/key for SSL Proxy tests, generated via:
32
+ # $ openssl genrsa -out example.key 2048
33
+ # $ openssl req -new -key example.key -out example.csr
34
+ # ...
35
+ # Common Name (eg, fully qualified host name) []:example.com
36
+ # Email Address []:admin@example.com
37
+ # ...
38
+ # $ openssl x509 -req -in example.csr -signkey example.key -out example.crt
39
+
40
+ TEST_PEM_CERTIFICATE = <<CERT
41
+ -----BEGIN CERTIFICATE-----
42
+ MIIC7DCCAdQCCQCDSZQ3PYJW6zANBgkqhkiG9w0BAQUFADA4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6gwgIbN3d1fEV9cM
78
+ ATtjjsFC+toFrP8BZ1wj3DY8Q4OsOmXng1V4bw4Y5xsT6SxXh7E0gU2L8MCjUdri
79
+ WUUu++yRRcUpWUGRRMYx6cN529HPNbAPm5Y8QfUCgYAGpCHShS1cgU9ilIZ2cGAI
80
+ XJ3Od1Jr6176shyl/tEJF6ytS6A0UUVBQNOyNy/WiwLndy9r6/BQ5TIMfGW/KmNr
81
+ FnftZ2ndY4lDdkKbP8bCEXVFZpwPBV8RLlSGJ0krReb5r7DpQPYbV7FKpX/FZGPQ
82
+ VUWTjaS5Kj5iEsD5+mH/OQKBgQCKhftc8/V/0eDwHz7RTikQfeMc0Yv530CmWGWN
83
+ d3z0h0sMhEIcpgf8UjZfjJ+YnuqOghX2XRbTEnZxuLsVS49rJX37bl/8CrLWZ74/
84
+ YiyNZoyu82NmHbH10bCG1ZjE/SmWKAmDUrb8TdZXcBTQWM+Hv1b3fu4fPe/6KoFR
85
+ 9Nn0cQKBgQC8BViTyfPTSuTEb8z7uzLEQk13MH+LTHFngFevWoq3OStEsmsIYK1K
86
+ GcF1N9ZzPH024uwdcLjjwpul/avUHqzfp5ZILuI83Z/OqYYLiCQ0BbAQno7Cp5Be
87
+ wLjafhPTSAIS0jijglJ7uzaSbFUW11fw1/EIqIFNe0R0Xf9lsyPxFA==
88
+ -----END RSA PRIVATE KEY-----
89
+ KEY
90
+
24
91
  class FogIntegrationTest < MiniTest::Test
25
92
  def namespaced_name
26
93
  "#{self.class}_#{name}"
@@ -1,19 +1,23 @@
1
- # The next line was added to squelch a warning message in Ruby 1.9.
2
- # It ensures we're using the gem, not the built-in Minitest
3
- # See https://github.com/seattlerb/minitest/#install
4
- gem "minitest"
5
-
6
- require "minitest/autorun"
7
-
1
+ # Configure simplecov for coverage tests
2
+ # Note: needs to be done _before_ requiring minitest!
8
3
  if ENV["COVERAGE"]
9
- require "coveralls"
10
4
  require "simplecov"
11
5
 
6
+ require 'codecov'
7
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
8
+
12
9
  SimpleCov.start do
13
10
  add_filter "/test/"
14
11
  end
15
12
  end
16
13
 
17
- require File.join(File.dirname(__FILE__), "../../lib/fog/google")
14
+ # The next line was added to squelch a warning message in Ruby 1.9.
15
+ # It ensures we're using the gem, not the built-in Minitest
16
+ # See https://github.com/seattlerb/minitest/#install
17
+ gem "minitest"
18
+ require "minitest/autorun"
19
+ # Custom formatters
20
+ require "minitest/reporters"
21
+ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
18
22
 
19
- Coveralls.wear! if ENV["COVERAGE"]
23
+ require File.join(File.dirname(__FILE__), "../../lib/fog/google")
@@ -0,0 +1,6 @@
1
+ require "helpers/integration_test_helper"
2
+
3
+ # This is a simple coverage helper that helps differentiate
4
+ # the tests when run in parallel so the final coverage report
5
+ # can be properly combined together from multiple runners
6
+ SimpleCov.command_name "test:compute-core_compute" if ENV["COVERAGE"]
@@ -0,0 +1,42 @@
1
+ require "helpers/integration_test_helper"
2
+
3
+ class TestMachineTypes < FogIntegrationTest
4
+ # List of machine types - not a complete sampling since beefier ones do not
5
+ # exist in all zones (list last updated June 2018)
6
+ NAMES = %w(f1-micro g1-small n1-highcpu-16 n1-highcpu-2 n1-highcpu-4
7
+ n1-highcpu-8 n1-highmem-16 n1-highmem-2 n1-highmem-32 n1-highmem-4
8
+ n1-highmem-8 n1-standard-1 n1-standard-16 n1-standard-2
9
+ n1-standard-32 n1-standard-4 n1-standard-8 ).freeze
10
+
11
+ # Testing in one random zone per region (list last updated May 2018)
12
+ ZONES = %w(asia-east1-a asia-northeast1-b asia-south1-c asia-southeast1-a
13
+ australia-southeast1-b europe-west1-c europe-west2-a europe-west3-b
14
+ europe-west4-c northamerica-northeast1-a southamerica-east1-b
15
+ us-central1-c us-east1-b us-east4-a us-west1-c).freeze
16
+
17
+ def setup
18
+ @subject = Fog::Compute[:google].machine_types
19
+ end
20
+
21
+ def test_all
22
+ assert_operator(@subject.all.size, :>=, NAMES.size * ZONES.size,
23
+ "Number of all machine types should be greater or equal to test zones * machine_types")
24
+ end
25
+
26
+ def test_get
27
+ # This tests only in last zone since not all zones contain all machine types
28
+ NAMES.each do |name|
29
+ ZONES.each do |zone|
30
+ refute_nil @subject.get(name, zone)
31
+ end
32
+ end
33
+ end
34
+
35
+ def test_bad_get
36
+ assert_nil @subject.get("bad-name", ZONES.first)
37
+ end
38
+
39
+ def test_enumerable
40
+ assert_respond_to @subject, :each
41
+ end
42
+ end
@@ -0,0 +1,27 @@
1
+ require "helpers/integration_test_helper"
2
+
3
+ class TestRoutes < FogIntegrationTest
4
+ def setup
5
+ @subject = Fog::Compute[:google].operations
6
+ end
7
+
8
+ def test_all
9
+ # TODO: what if this test runs first on a brand new project?
10
+ assert_operator(@subject.all.size, :>=, 2,
11
+ "There should be at least 2 operations in the project")
12
+ end
13
+
14
+ def test_get
15
+ @subject.all do |operation|
16
+ refute_nil @subject.get(operation.name)
17
+ end
18
+ end
19
+
20
+ def test_bad_get
21
+ assert_nil @subject.get("bad-name")
22
+ end
23
+
24
+ def test_enumerable
25
+ assert_respond_to @subject, :each
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ require "helpers/integration_test_helper"
2
+
3
+ class TestProjects < FogIntegrationTest
4
+ def setup
5
+ @subject = Fog::Compute[:google].projects
6
+ end
7
+
8
+ def test_get
9
+ assert @subject.get(TEST_PROJECT)
10
+ end
11
+
12
+ def test_bad_get
13
+ assert_nil @subject.get("bad-name")
14
+ end
15
+
16
+ def test_enumerable
17
+ assert_respond_to @subject, :each
18
+ end
19
+ end
@@ -0,0 +1,109 @@
1
+ require "helpers/integration_test_helper"
2
+ require "integration/factories/servers_factory"
3
+ require "integration/factories/disks_factory"
4
+ require "resolv"
5
+
6
+ class TestServers < FogIntegrationTest
7
+ include TestCollection
8
+
9
+ # Cleanup is handled by TestCollection
10
+ def setup
11
+ @subject = Fog::Compute[:google].servers
12
+ @factory = ServersFactory.new(namespaced_name)
13
+ @servers = ServersFactory.new(namespaced_name)
14
+ @disks = DisksFactory.new(namespaced_name)
15
+ end
16
+
17
+ def teardown
18
+ # Clean up the server resources used in testing
19
+ @servers.cleanup
20
+ super
21
+ end
22
+
23
+ def test_set_metadata
24
+ server = @factory.create
25
+ server.wait_for { ready? }
26
+ server.set_metadata({ "foo" => "bar", "baz" => "foo" }, false)
27
+ assert_equal [{ :key => "foo", :value => "bar" },
28
+ { :key => "baz", :value => "foo" }], server.metadata[:items]
29
+ end
30
+
31
+ def test_bootstrap
32
+ key = "ssh-rsa IAMNOTAREALSSHKEYAMA== user@host.subdomain.example.com"
33
+ user = "username"
34
+
35
+ File.stub :read, key do
36
+ # XXX Small hack - name is set this way so it will be cleaned up by CollectionFactory
37
+ # Bootstrap is special so this is something that needs to be done only for this method
38
+ # Public_key_path is set to avoid stubbing out File.exist?
39
+ server = @subject.bootstrap(:name => "#{CollectionFactory.new(nil,namespaced_name).resource_name}",
40
+ :username => user,
41
+ :public_key_path => "foo")
42
+ boot_disk = server.disks.detect { |disk| disk[:boot] }
43
+
44
+ assert_equal("RUNNING", server.status, "Bootstrapped server should be running")
45
+ assert_equal(key, server.public_key, "Bootstrapped server should have a public key set")
46
+ assert_equal(user, server.username, "Bootstrapped server should have user set to #{user}")
47
+ assert(boot_disk[:auto_delete], "Bootstrapped server should have disk set to autodelete")
48
+
49
+ network_adapter = server.network_interfaces.detect { |x| x.has_key?(:access_configs) }
50
+
51
+ refute_nil(network_adapter[:access_configs].detect { |x| x[:nat_ip] },
52
+ "Bootstrapped server should have an external ip by default")
53
+ end
54
+ end
55
+
56
+ def test_bootstrap_fail
57
+ # Pretend the ssh key does not exist
58
+ File.stub :exist?, nil do
59
+ assert_raises(Fog::Errors::Error) {
60
+ # XXX Small hack - name is set this way so it will be cleaned up by CollectionFactory
61
+ # Bootstrap is special so this is something that needs to be done only for this method
62
+ @subject.bootstrap(:name => "#{CollectionFactory.new(nil,namespaced_name).resource_name}",
63
+ :public_key_path => nil)
64
+ }
65
+ end
66
+ end
67
+
68
+ def test_image_name
69
+ server = @factory.create
70
+ assert_equal(TEST_IMAGE, server.image_name.split("/")[-1])
71
+ end
72
+
73
+ def test_ip_address_methods
74
+ # Create a server with ephemeral external IP address
75
+ server = @factory.create(:network_interfaces => [{ :network => "global/networks/default",
76
+ :access_configs => [{
77
+ :name => "External NAT",
78
+ :type => "ONE_TO_ONE_NAT"
79
+ }] }])
80
+ assert_match(Resolv::IPv4::Regex, server.public_ip_address,
81
+ "Server.public_ip_address should return a valid IP address")
82
+ refute_empty(server.public_ip_addresses)
83
+ assert_match(Resolv::IPv4::Regex, server.public_ip_addresses.pop)
84
+
85
+ assert_match(Resolv::IPv4::Regex, server.private_ip_address,
86
+ "Server.public_ip_address should return a valid IP address")
87
+ refute_empty(server.private_ip_addresses)
88
+ assert_match(Resolv::IPv4::Regex, server.private_ip_addresses.pop)
89
+ end
90
+
91
+ def test_start_stop_reboot
92
+ server = @factory.create
93
+
94
+ server.stop
95
+ server.wait_for { stopped? }
96
+
97
+ assert server.stopped?
98
+
99
+ server.start
100
+ server.wait_for { ready? }
101
+
102
+ assert server.ready?
103
+
104
+ server.reboot
105
+ server.wait_for { ready? }
106
+
107
+ assert server.ready?
108
+ end
109
+ end
@@ -0,0 +1,35 @@
1
+ require "helpers/integration_test_helper"
2
+
3
+ class TestZones < FogIntegrationTest
4
+ # Testing one random zone per region (list last updated May 2018)
5
+ ZONES = %w(asia-east1-a asia-northeast1-b asia-south1-c asia-southeast1-a
6
+ australia-southeast1-b europe-west1-c europe-west2-a europe-west3-b
7
+ europe-west4-c northamerica-northeast1-a southamerica-east1-b
8
+ us-central1-c us-east1-b us-east4-a us-west1-c).freeze
9
+
10
+ def setup
11
+ @subject = Fog::Compute[:google].zones
12
+ end
13
+
14
+ def test_all
15
+ assert_operator(@subject.all.size, :>=, ZONES.size,
16
+ "Number of all zones should be greater than test zones")
17
+ end
18
+
19
+ def test_get
20
+ # This tests only in last zone since not all zones contain all machine types
21
+ ZONES.each do |name|
22
+ zone = @subject.get(name)
23
+ refute_nil(zone, "zones.get() should not return nil")
24
+ assert(zone.up?, "zones.up? should return up, unless there's an outage")
25
+ end
26
+ end
27
+
28
+ def test_bad_get
29
+ assert_nil @subject.get("bad-name")
30
+ end
31
+
32
+ def test_enumerable
33
+ assert_respond_to @subject, :each
34
+ end
35
+ end
@@ -0,0 +1,84 @@
1
+ require "helpers/integration_test_helper"
2
+ require "integration/factories/addresses_factory"
3
+ require "integration/factories/servers_factory"
4
+
5
+ class TestAddresses < FogIntegrationTest
6
+ include TestCollection
7
+
8
+ def setup
9
+ @subject = Fog::Compute[:google].addresses
10
+ @servers = ServersFactory.new(namespaced_name)
11
+ @factory = AddressesFactory.new(namespaced_name)
12
+ end
13
+
14
+ def teardown
15
+ # Clean up the server resources used in testing
16
+ @servers.cleanup
17
+ super
18
+ end
19
+
20
+ def test_run_instance
21
+ address = @factory.create
22
+ server = @servers.create(:external_ip => address.address)
23
+
24
+ assert_equal(
25
+ address.address,
26
+ server.network_interfaces[0][:access_configs][0][:nat_ip],
27
+ "Created server should have the correct address after initialization"
28
+ )
29
+
30
+ assert_equal(
31
+ "IN_USE",
32
+ @subject.get(address.name, TEST_REGION).status,
33
+ "Address should now be in use"
34
+ )
35
+ end
36
+
37
+ def test_bad_get
38
+ assert_nil @subject.get("bad-name", TEST_REGION)
39
+ end
40
+
41
+ def test_valid_range
42
+ address = @factory.create
43
+
44
+ octet = /\d{,2}|1\d{2}|2[0-4]\d|25[0-5]/
45
+ re = /\A#{octet}\.#{octet}\.#{octet}\.#{octet}\z/
46
+
47
+ assert_match(re, address.address,
48
+ "Adress should be a valid ipv4 address")
49
+ end
50
+
51
+ def test_addresses_get_address_by_ip
52
+ address = @factory.create
53
+ found = @subject.get_by_ip_address(address.address)
54
+
55
+ assert_equal(address.name, found.name, "address should have same name")
56
+ assert_equal(address.address, found.address, "addresses should match")
57
+ end
58
+
59
+ def test_addresses_get_address_by_name
60
+ address = @factory.create
61
+ found = @subject.get_by_name(address.name)
62
+
63
+ assert_equal(address.name, found.name, "address should have same name")
64
+ assert_equal(address.address, found.address, "addresses should match")
65
+ end
66
+
67
+ def test_addresses_get_by_ip_address_or_name
68
+ # Ensure we find the same addresses through both codepaths
69
+ address = @factory.create
70
+ with_name = @subject.get_by_ip_address_or_name(address.name)
71
+ with_ip = @subject.get_by_ip_address_or_name(address.address)
72
+
73
+ assert_equal(address.name, with_name.name, "address should have same name")
74
+ assert_equal(address.address, with_name.address, "addresses should match")
75
+
76
+ assert_equal(address.name, with_ip.name, "address should have same name")
77
+ assert_equal(address.address, with_ip.address, "addresses should match")
78
+ end
79
+
80
+ def test_addresses_in_use
81
+ address = @factory.create
82
+ assert_equal(false, address.in_use?, "example address should not be in use")
83
+ end
84
+ end