diff --git a/examples/sql/flags.rb b/examples/sql/flags.rb index 96e7d7351b..e8f6e51109 100644 --- a/examples/sql/flags.rb +++ b/examples/sql/flags.rb @@ -1,7 +1,11 @@ -def test - connection = Fog::Google::SQL.new +# All examples presume that you have a ~/.fog credentials file set up. +# More info on it can be found here: http://fog.io/about/getting_started.html - puts "Listing all Flags..." - puts "--------------------" - connection.flags -end +require "bundler" +Bundler.require(:default, :development) + +connection = Fog::Google::SQL.new + +puts "Listing all Flags..." +puts "--------------------" +connection.flags diff --git a/examples/sql/instances.rb b/examples/sql/instances.rb index 04e79e653e..5f30b14b02 100644 --- a/examples/sql/instances.rb +++ b/examples/sql/instances.rb @@ -1,34 +1,38 @@ -def test - connection = Fog::Google::SQL.new - - puts "Create a Instance..." - puts "--------------------" - instance = connection.instances.create(:name => Fog::Mock.random_letters(16), :tier => "D1") - instance.wait_for { ready? } - - puts "Get the Instance..." - puts "----------------------" - connection.instances.get(instance.name) - - puts "List all Instances..." - puts "---------------------" - connection.instances.all - - puts "Update the Instance..." - puts "----------------------" - instance.settings[:activation_policy] = "ALWAYS" - instance.update - instance.wait_for { ready? } - - puts "Reset the Instance SSL configuration..." - puts "---------------------------------------" - instance.reset_ssl_config - - puts "Restart the Instance..." - puts "-----------------------" - instance.restart - - puts "Delete the Instance..." - puts "----------------------" - instance.destroy -end +# All examples presume that you have a ~/.fog credentials file set up. +# More info on it can be found here: http://fog.io/about/getting_started.html + +require "bundler" +Bundler.require(:default, :development) + +connection = Fog::Google::SQL.new + +puts "Create a Instance..." +puts "--------------------" +instance = connection.instances.create(:name => Fog::Mock.random_letters(16), :tier => "db-n1-standard-1") +instance.wait_for { ready? } + +puts "Get the Instance..." +puts "----------------------" +connection.instances.get(instance.name) + +puts "List all Instances..." +puts "---------------------" +connection.instances.all + +puts "Update the Instance..." +puts "----------------------" +instance.settings[:activation_policy] = "ALWAYS" +instance.update +instance.wait_for { ready? } + +puts "Reset the Instance SSL configuration..." +puts "---------------------------------------" +instance.reset_ssl_config + +puts "Restart the Instance..." +puts "-----------------------" +instance.restart + +puts "Delete the Instance..." +puts "----------------------" +instance.destroy diff --git a/examples/sql/operations.rb b/examples/sql/operations.rb index 3bb47a4593..ab1e468620 100644 --- a/examples/sql/operations.rb +++ b/examples/sql/operations.rb @@ -1,20 +1,24 @@ -def test - connection = Fog::Google::SQL.new +# All examples presume that you have a ~/.fog credentials file set up. +# More info on it can be found here: http://fog.io/about/getting_started.html - puts "Create a Instance..." - puts "--------------------" - instance = connection.instances.create(:name => Fog::Mock.random_letters(16), :tier => "D1") - instance.wait_for { ready? } +require "bundler" +Bundler.require(:default, :development) - puts "Delete the Instance..." - puts "----------------------" - operation = instance.destroy +connection = Fog::Google::SQL.new - puts "Get the Operation..." - puts "--------------------" - connection.operations.get(operation.identity) +puts "Create a Instance..." +puts "--------------------" +instance = connection.instances.create(:name => Fog::Mock.random_letters(16), :tier => "D1") +instance.wait_for { ready? } - puts "Listing all Operations..." - puts "-------------------------" - connection.operations.all(instance.identity) -end +puts "Delete the Instance..." +puts "----------------------" +operation = instance.destroy + +puts "Get the Operation..." +puts "--------------------" +connection.operations.get(operation.identity) + +puts "Listing all Operations..." +puts "-------------------------" +connection.operations.all(instance.identity) diff --git a/examples/sql/ssl_certs.rb b/examples/sql/ssl_certs.rb index fa79367245..ce3679649c 100644 --- a/examples/sql/ssl_certs.rb +++ b/examples/sql/ssl_certs.rb @@ -1,28 +1,32 @@ -def test - connection = Fog::Google::SQL.new - - puts "Create a Instance..." - puts "--------------------" - instance = connection.instances.create(:name => Fog::Mock.random_letters(16), :tier => "D1") - instance.wait_for { ready? } - - puts "Create a SSL certificate..." - puts "---------------------------" - ssl_cert = connection.ssl_certs.create(:instance => instance.name, :common_name => Fog::Mock.random_letters(16)) - - puts "Get the SSL certificate..." - puts "--------------------------" - connection.ssl_certs.get(instance.name, ssl_cert.sha1_fingerprint) - - puts "List all SSL certificate..." - puts "---------------------------" - connection.ssl_certs.all(instance.name) - - puts "Delete the SSL certificate..." - puts "-----------------------------" - ssl_cert.destroy - - puts "Delete the Instance..." - puts "----------------------" - instance.destroy -end +# All examples presume that you have a ~/.fog credentials file set up. +# More info on it can be found here: http://fog.io/about/getting_started.html + +require "bundler" +Bundler.require(:default, :development) + +connection = Fog::Google::SQL.new + +puts "Create a Instance..." +puts "--------------------" +instance = connection.instances.create(:name => Fog::Mock.random_letters(16), :tier => "db-n1-standard-1") +instance.wait_for { ready? } + +puts "Create a SSL certificate..." +puts "---------------------------" +ssl_cert = connection.ssl_certs.create(:instance => instance.name, :common_name => Fog::Mock.random_letters(16)) + +puts "Get the SSL certificate..." +puts "--------------------------" +connection.ssl_certs.get(instance.name, ssl_cert.sha1_fingerprint) + +puts "List all SSL certificate..." +puts "---------------------------" +connection.ssl_certs.all(instance.name) + +puts "Delete the SSL certificate..." +puts "-----------------------------" +ssl_cert.destroy + +puts "Delete the Instance..." +puts "----------------------" +instance.destroy diff --git a/examples/sql/tiers.rb b/examples/sql/tiers.rb index f117f51e1b..4517bc7166 100644 --- a/examples/sql/tiers.rb +++ b/examples/sql/tiers.rb @@ -1,7 +1,11 @@ -def test - connection = Fog::Google::SQL.new +# All examples presume that you have a ~/.fog credentials file set up. +# More info on it can be found here: http://fog.io/about/getting_started.html - puts "Listing all Tiers..." - puts "--------------------" - connection.tiers -end +require "bundler" +Bundler.require(:default, :development) + +connection = Fog::Google::SQL.new + +puts "Listing all Tiers..." +puts "--------------------" +connection.tiers diff --git a/test/helpers/integration_test_helper.rb b/test/helpers/integration_test_helper.rb index dea2fc84fe..674d4a8adf 100644 --- a/test/helpers/integration_test_helper.rb +++ b/test/helpers/integration_test_helper.rb @@ -24,11 +24,8 @@ # The image was created like so: https://cloud.google.com/compute/docs/images#export_an_image_to_google_cloud_storage TEST_RAW_DISK_SOURCE = "http://storage.googleapis.com/fog-test-bucket/fog-test-raw-disk-source.image.tar.gz".freeze -TEST_SQL_TIER_FIRST = "D1".freeze -TEST_SQL_REGION_FIRST = "us-central".freeze - -TEST_SQL_TIER_SECOND = "db-n1-standard-1".freeze -TEST_SQL_REGION_SECOND = TEST_REGION +TEST_SQL_TIER = "db-n1-standard-1".freeze +TEST_SQL_REGION = TEST_REGION # Test certificate/key for SSL Proxy tests, generated via: # $ openssl genrsa -out example.key 2048 diff --git a/test/integration/factories/sql_v1_certs_factory.rb b/test/integration/factories/sql_certs_factory.rb similarity index 72% rename from test/integration/factories/sql_v1_certs_factory.rb rename to test/integration/factories/sql_certs_factory.rb index b29fcc6541..b7994506c2 100644 --- a/test/integration/factories/sql_v1_certs_factory.rb +++ b/test/integration/factories/sql_certs_factory.rb @@ -1,9 +1,9 @@ require "integration/factories/collection_factory" -require "integration/factories/sql_v1_instances_factory" +require "integration/factories/sql_instances_factory" -class SqlV1CertsFactory < CollectionFactory +class SqlCertsFactory < CollectionFactory def initialize(example) - @instances = SqlV1InstancesFactory.new(example) + @instances = SqlInstancesFactory.new(example) super(Fog::Google[:sql].ssl_certs, example) end diff --git a/test/integration/factories/sql_v1_instances_factory.rb b/test/integration/factories/sql_instances_factory.rb similarity index 74% rename from test/integration/factories/sql_v1_instances_factory.rb rename to test/integration/factories/sql_instances_factory.rb index 9d82cbaa15..faebbea811 100644 --- a/test/integration/factories/sql_v1_instances_factory.rb +++ b/test/integration/factories/sql_instances_factory.rb @@ -1,6 +1,6 @@ require "integration/factories/collection_factory" -class SqlV1InstancesFactory < CollectionFactory +class SqlInstancesFactory < CollectionFactory def initialize(example) super(Fog::Google[:sql].instances, example) end @@ -13,7 +13,7 @@ def params # Name has a time suffix due to SQL resources API objects having # a _very_ long life on the backend (n(days)) after deletion. { :name => "#{resource_name}-#{Time.now.to_i}", - :region => TEST_SQL_REGION_FIRST, - :tier => TEST_SQL_TIER_FIRST } + :region => TEST_SQL_REGION, + :tier => TEST_SQL_TIER } end end diff --git a/test/integration/factories/sql_v1_users_factory.rb b/test/integration/factories/sql_users_factory.rb similarity index 77% rename from test/integration/factories/sql_v1_users_factory.rb rename to test/integration/factories/sql_users_factory.rb index 21e8b08637..d00510489a 100644 --- a/test/integration/factories/sql_v1_users_factory.rb +++ b/test/integration/factories/sql_users_factory.rb @@ -1,9 +1,9 @@ require "integration/factories/collection_factory" -require "integration/factories/sql_v1_instances_factory" +require "integration/factories/sql_instances_factory" -class SqlV1UsersFactory < CollectionFactory +class SqlUsersFactory < CollectionFactory def initialize(example) - @instances = SqlV1InstancesFactory.new(example) + @instances = SqlInstancesFactory.new(example) super(Fog::Google[:sql].users, example) end diff --git a/test/integration/factories/sql_v2_instances_factory.rb b/test/integration/factories/sql_v2_instances_factory.rb deleted file mode 100644 index 3ed129e7c9..0000000000 --- a/test/integration/factories/sql_v2_instances_factory.rb +++ /dev/null @@ -1,19 +0,0 @@ -require "integration/factories/collection_factory" - -class SqlV2InstancesFactory < CollectionFactory - def initialize(example) - super(Fog::Google[:sql].instances, example) - end - - def cleanup - super - end - - def params - # Name has a time suffix due to SQL resources API objects having - # a _very_ long life on the backend (n(days)) after deletion. - { :name => "#{resource_name}-#{Time.now.to_i}", - :region => TEST_SQL_REGION_SECOND, - :tier => TEST_SQL_TIER_SECOND } - end -end diff --git a/test/integration/sql/sqlv1/test_coverage.rb b/test/integration/sql/sqlv1/test_coverage.rb deleted file mode 100644 index 5909322722..0000000000 --- a/test/integration/sql/sqlv1/test_coverage.rb +++ /dev/null @@ -1,6 +0,0 @@ -require "helpers/integration_test_helper" - -# This is a simple coverage helper that helps differentiate -# the tests when run in parallel so the final coverage report -# can be properly combined together from multiple runners -SimpleCov.command_name "test:sqlv1" if ENV["COVERAGE"] diff --git a/test/integration/sql/sqlv1/test_v1_instances.rb b/test/integration/sql/sqlv1/test_v1_instances.rb deleted file mode 100644 index 01e02c7b22..0000000000 --- a/test/integration/sql/sqlv1/test_v1_instances.rb +++ /dev/null @@ -1,31 +0,0 @@ -require "helpers/integration_test_helper" -require "integration/factories/sql_v1_instances_factory" - -class TestSQLV1Instances < FogIntegrationTest - include TestCollection - - def setup - @subject = Fog::Google[:sql].instances - @factory = SqlV1InstancesFactory.new(namespaced_name) - end - - def test_update - instance = @factory.create - - settings_version = instance.settings_version - labels = { - :foo => "bar" - } - instance.settings[:user_labels] = labels - instance.save - - updated = @subject.get(instance.name) - assert_equal(labels, updated.settings[:user_labels]) - assert_operator(updated.settings_version, :>, settings_version) - end - - def test_default_settings - instance = @factory.create - assert_equal([], instance.ssl_certs, "new instance should have 0 initial ssl certs") - end -end diff --git a/test/integration/sql/sqlv1/test_v1_certs.rb b/test/integration/sql/test_certs.rb similarity index 90% rename from test/integration/sql/sqlv1/test_v1_certs.rb rename to test/integration/sql/test_certs.rb index 0184311831..bbc9c115da 100644 --- a/test/integration/sql/sqlv1/test_v1_certs.rb +++ b/test/integration/sql/test_certs.rb @@ -1,12 +1,13 @@ require "helpers/integration_test_helper" -require "integration/factories/sql_v1_certs_factory" +require "integration/factories/sql_certs_factory" +require "pry" -class TestSQLV1Certs < FogIntegrationTest +class TestSQLCerts < FogIntegrationTest # This test doesn't include TestCollection as certs are not an independent resource. def setup @subject = Fog::Google[:sql].ssl_certs - @factory = SqlV1CertsFactory.new(namespaced_name) + @factory = SqlCertsFactory.new(namespaced_name) @client = Fog::Google::SQL.new end diff --git a/test/integration/sql/sqlv1/test_common_flags.rb b/test/integration/sql/test_common_flags.rb similarity index 100% rename from test/integration/sql/sqlv1/test_common_flags.rb rename to test/integration/sql/test_common_flags.rb diff --git a/test/integration/sql/sqlv1/test_common_tiers.rb b/test/integration/sql/test_common_tiers.rb similarity index 100% rename from test/integration/sql/sqlv1/test_common_tiers.rb rename to test/integration/sql/test_common_tiers.rb diff --git a/test/integration/sql/sqlv2/test_coverage.rb b/test/integration/sql/test_coverage.rb similarity index 80% rename from test/integration/sql/sqlv2/test_coverage.rb rename to test/integration/sql/test_coverage.rb index ca15ff85ab..75f3978515 100644 --- a/test/integration/sql/sqlv2/test_coverage.rb +++ b/test/integration/sql/test_coverage.rb @@ -3,4 +3,4 @@ # This is a simple coverage helper that helps differentiate # the tests when run in parallel so the final coverage report # can be properly combined together from multiple runners -SimpleCov.command_name "test:sqlv2" if ENV["COVERAGE"] +SimpleCov.command_name "test:sql" if ENV["COVERAGE"] diff --git a/test/integration/sql/sqlv2/test_v2_instances.rb b/test/integration/sql/test_instances.rb similarity index 80% rename from test/integration/sql/sqlv2/test_v2_instances.rb rename to test/integration/sql/test_instances.rb index 5da6a1c196..68542ef357 100644 --- a/test/integration/sql/sqlv2/test_v2_instances.rb +++ b/test/integration/sql/test_instances.rb @@ -1,5 +1,5 @@ require "helpers/integration_test_helper" -require "integration/factories/sql_v2_instances_factory" +require "integration/factories/sql_instances_factory" # Client helper is imported for `wait_until_complete` # TODO: Remove when fog-google#339 or fog-google#340 is resolved require "helpers/client_helper" @@ -12,13 +12,33 @@ class TestSQLV2Instances < FogIntegrationTest def setup @subject = Fog::Google[:sql].instances - @factory = SqlV2InstancesFactory.new(namespaced_name) + @factory = SqlInstancesFactory.new(namespaced_name) @backup_runs = Fog::Google[:sql].backup_runs # TODO: Remove after BackupRuns get save/reload - fog-google#339 # See https://github.com/fog/fog-google/issues/339 @client = Fog::Google::SQL.new end + def test_update + instance = @factory.create + + settings_version = instance.settings_version + labels = { + :foo => "bar" + } + instance.settings[:user_labels] = labels + instance.save + + updated = @subject.get(instance.name) + assert_equal(labels, updated.settings[:user_labels]) + assert_operator(updated.settings_version, :>, settings_version) + end + + def test_default_settings + instance = @factory.create + assert_equal([], instance.ssl_certs, "new instance should have 0 initial ssl certs") + end + def test_restore_backup_run instance = @factory.create diff --git a/test/integration/sql/sqlv1/test_v1_users.rb b/test/integration/sql/test_users.rb similarity index 81% rename from test/integration/sql/sqlv1/test_v1_users.rb rename to test/integration/sql/test_users.rb index 20ec42c753..7b6acdc27a 100644 --- a/test/integration/sql/sqlv1/test_v1_users.rb +++ b/test/integration/sql/test_users.rb @@ -1,8 +1,8 @@ require "helpers/integration_test_helper" -require "integration/factories/sql_v1_instances_factory" -require "integration/factories/sql_v1_users_factory" +require "integration/factories/sql_instances_factory" +require "integration/factories/sql_users_factory" -class TestSQLV1Users < FogIntegrationTest +class TestSQLUsers < FogIntegrationTest # This test doesn't include TestCollection as Users is not a # classical Fog model, as it's tied to a particular instance # I.e.: @@ -12,7 +12,7 @@ class TestSQLV1Users < FogIntegrationTest def setup @subject = Fog::Google[:sql].users - @factory = SqlV1UsersFactory.new(namespaced_name) + @factory = SqlUsersFactory.new(namespaced_name) end def teardown