Skip to content

Commit

Permalink
Drop support for deprecated SQLv1
Browse files Browse the repository at this point in the history
- Restructured tests and removed v1-specific ones
- Updated test factories
- Updated examples
  • Loading branch information
Temikus committed Mar 26, 2020
1 parent 87b51f7 commit d689d77
Show file tree
Hide file tree
Showing 18 changed files with 152 additions and 170 deletions.
16 changes: 10 additions & 6 deletions examples/sql/flags.rb
Original file line number Diff line number Diff line change
@@ -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
72 changes: 38 additions & 34 deletions examples/sql/instances.rb
Original file line number Diff line number Diff line change
@@ -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
36 changes: 20 additions & 16 deletions examples/sql/operations.rb
Original file line number Diff line number Diff line change
@@ -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)
60 changes: 32 additions & 28 deletions examples/sql/ssl_certs.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 10 additions & 6 deletions examples/sql/tiers.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 2 additions & 5 deletions test/helpers/integration_test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -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

Expand Down
19 changes: 0 additions & 19 deletions test/integration/factories/sql_v2_instances_factory.rb

This file was deleted.

6 changes: 0 additions & 6 deletions test/integration/sql/sqlv1/test_coverage.rb

This file was deleted.

31 changes: 0 additions & 31 deletions test/integration/sql/sqlv1/test_v1_instances.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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

Expand Down
Loading

0 comments on commit d689d77

Please sign in to comment.