Skip to content

Commit

Permalink
Add more unit tests
Browse files Browse the repository at this point in the history
+ test fixtures for fog#352
  • Loading branch information
Temikus committed Jul 20, 2018
1 parent 77125ea commit aaa65b2
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 6 deletions.
16 changes: 13 additions & 3 deletions test/unit/compute/test_common_collections.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
require "helpers/test_helper"
require "pry"

class UnitTestCollections < MiniTest::Test
def setup
Fog.mock!

@client = Fog::Compute.new(:provider => "Google", :google_project => "foo")

# Top-level ancestors we do not dest
common_ancestors = [Fog::Collection, Fog::Association, Fog::PagedCollection]
# Projects do not have a "list" method in compute API
exceptions = [Fog::Compute::Google::Projects]
# Enumerate all descendants of Fog::Collection
descendants = ObjectSpace.each_object(Fog::Collection.singleton_class).to_a

@collections = descendants - common_ancestors - exceptions
@collections = descendants.select {|d| d.name.match /Fog::Compute::Google/ } - exceptions
end

def teardown
Expand All @@ -28,4 +28,14 @@ def test_common_methods
assert obj.respond_to?(:each), "#{klass} should behave like Enumerable"
end
end

def test_collection_get_arguments
# TODO: Fixture for #352
skip
@collections.each do |klass|
obj = klass.new
assert_operator(obj.method(:get).arity, :<=, 1,
"#{klass} should have at most 1 required parameter in get()")
end
end
end
4 changes: 1 addition & 3 deletions test/unit/compute/test_common_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ def setup
Fog.mock!
@client = Fog::Compute.new(:provider => "Google", :google_project => "foo")

# Top-level ancestors we do not test
common_ancestors = [Fog::Model, Fog::Compute::Server]
# Do not test models that do not have a create method in API
exceptions = [ Fog::Compute::Google::MachineType,
Fog::Compute::Google::Region,
Expand All @@ -18,7 +16,7 @@ def setup
# Enumerate all descendants of Fog::Model
descendants = ObjectSpace.each_object(Fog::Model.singleton_class).to_a

@models = descendants - common_ancestors - exceptions
@models = descendants.select {|d| d.name.match /Fog::Compute::Google/ } - exceptions
end

def teardown
Expand Down
40 changes: 40 additions & 0 deletions test/unit/dns/test_common_collections.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require "helpers/test_helper"
require "pry"

class UnitTestDNSCollections < MiniTest::Test
def setup
Fog.mock!
@client = Fog::DNS.new(provider: "google")

# DNS Projects API does not support 'list', so 'all' method is not possible
exceptions = [Fog::DNS::Google::Projects]
# Enumerate all descendants of Fog::Collection
descendants = ObjectSpace.each_object(Fog::Collection.singleton_class)

@collections = descendants.select { |x| x.name.match /Fog::DNS::Google/ } - exceptions
end

def teardown
Fog.unmock!
end

def test_common_methods
# This tests whether Fog::Compute::Google collections have common lifecycle methods
@collections.each do |klass|
obj = klass.new
assert obj.respond_to?(:all), "#{klass} should have an .all method"
assert obj.respond_to?(:get), "#{klass} should have a .get method"
assert obj.respond_to?(:each), "#{klass} should behave like Enumerable"
end
end

def test_collection_get_arguments
# TODO: Fixture for #352
skip
@collections.each do |klass|
obj = klass.new
assert_operator(obj.method(:get).arity, :<=, 1,
"#{klass} should have at most 1 required parameter in get()")
end
end
end
40 changes: 40 additions & 0 deletions test/unit/monitoring/test_comon_collections.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require "helpers/test_helper"
require "pry"

class UnitTestMonitoringCollections < MiniTest::Test
def setup
Fog.mock!
@client = Fog::Monitoring.new(provider: "google")

# TimeSeries API has no 'get' method
exceptions = [Fog::Google::Monitoring::TimeseriesCollection]
# Enumerate all descendants of Fog::Collection
descendants = ObjectSpace.each_object(Fog::Collection.singleton_class).to_a

@collections = descendants.select { |x| x.name.match /Fog::Google::Monitoring/ } - exceptions
end

def teardown
Fog.unmock!
end

def test_common_methods
# This tests whether Fog::Compute::Google collections have common lifecycle methods
@collections.each do |klass|
obj = klass.new
assert obj.respond_to?(:all), "#{klass} should have an .all method"
assert obj.respond_to?(:get), "#{klass} should have a .get method"
assert obj.respond_to?(:each), "#{klass} should behave like Enumerable"
end
end

def test_collection_get_arguments
# TODO: Fixture for #352
skip
@collections.each do |klass|
obj = klass.new
assert_operator(obj.method(:get).arity, :<=, 1,
"#{klass} should have at most 1 required parameter in get()")
end
end
end
38 changes: 38 additions & 0 deletions test/unit/pubsub/test_common_collections.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require "helpers/test_helper"
require "pry"

class UnitTestPubsubCollections < MiniTest::Test
def setup
Fog.mock!
@client = Fog::Google::Pubsub.new

exceptions = []
# Enumerate all descendants of Fog::Collection
descendants = ObjectSpace.each_object(Fog::Collection.singleton_class)

@collections = descendants.select { |x| x.name.match /Fog::Google::Pubsub/ } - exceptions
end

def teardown
Fog.unmock!
end

def test_common_methods
# This tests whether Fog::Compute::Google collections have common lifecycle methods
@collections.each do |klass|
obj = klass.new
assert obj.respond_to?(:all), "#{klass} should have an .all method"
assert obj.respond_to?(:get), "#{klass} should have a .get method"
assert obj.respond_to?(:each), "#{klass} should behave like Enumerable"
end
end

def test_collection_get_arguments
# TODO: Fixture for #352
@collections.each do |klass|
obj = klass.new
assert_operator(obj.method(:get).arity, :<=, 1,
"#{klass} should have at most 1 required parameter in get()")
end
end
end
43 changes: 43 additions & 0 deletions test/unit/sql/test_common_collections.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require "helpers/test_helper"
require "pry"

class UnitTestSQLCollections < MiniTest::Test
def setup
Fog.mock!
@client = Fog::Google::SQL.new

# SQL Users API doesn't have a get method
# SQL Flags API has only a 'list' method
exceptions = [Fog::Google::SQL::Users,
Fog::Google::SQL::Tiers,
Fog::Google::SQL::Flags]
# Enumerate all descendants of Fog::Collection
descendants = ObjectSpace.each_object(Fog::Collection.singleton_class)

@collections = descendants.select { |x| x.name.match /Fog::Google::SQL/ } - exceptions
end

def teardown
Fog.unmock!
end

def test_common_methods
# This tests whether Fog::Compute::Google collections have common lifecycle methods
@collections.each do |klass|
obj = klass.new
assert obj.respond_to?(:all), "#{klass} should have an .all method"
assert obj.respond_to?(:get), "#{klass} should have a .get method"
assert obj.respond_to?(:each), "#{klass} should behave like Enumerable"
end
end

def test_collection_get_arguments
# TODO: Fixture for #352
skip
@collections.each do |klass|
obj = klass.new
assert_operator(obj.method(:get).arity, :<=, 1,
"#{klass} should have at most 1 required parameter in get()")
end
end
end
38 changes: 38 additions & 0 deletions test/unit/storage/test_common_json_collections.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require "helpers/test_helper"
require "pry"

class UnitTestStorageJSONCollections < MiniTest::Test
def setup
Fog.mock!
@client = Fog::Storage.new(provider: "google")

# Enumerate all descendants of Fog::Collection
descendants = ObjectSpace.each_object(Fog::Collection.singleton_class)

@collections = descendants.select {
|x| x.name.match /Fog::Storage::GoogleJSON/
}
end

def teardown
Fog.unmock!
end

def test_common_methods
# This tests whether Fog::Compute::Google collections have common lifecycle methods
@collections.each do |klass|
obj = klass.new
assert obj.respond_to?(:all), "#{klass} should have an .all method"
assert obj.respond_to?(:get), "#{klass} should have a .get method"
assert obj.respond_to?(:each), "#{klass} should behave like Enumerable"
end
end

def test_collection_get_arguments
@collections.each do |klass|
obj = klass.new
assert_operator(obj.method(:get).arity, :<=, 1,
"#{klass} should have at most 1 required parameter in get()")
end
end
end
40 changes: 40 additions & 0 deletions test/unit/storage/test_common_xml_collections.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require "helpers/test_helper"
require "pry"

class UnitTestStorageXMLCollections < MiniTest::Test
def setup
Fog.mock!
@client = Fog::Storage.new(provider: "google",
google_storage_access_key_id: "",
google_storage_secret_access_key: "")

# Enumerate all descendants of Fog::Collection
descendants = ObjectSpace.each_object(Fog::Collection.singleton_class)

@collections = descendants.select {
|x| x.name.match /Fog::Storage::GoogleXML/
}
end

def teardown
Fog.unmock!
end

def test_common_methods
# This tests whether Fog::Compute::Google collections have common lifecycle methods
@collections.each do |klass|
obj = klass.new
assert obj.respond_to?(:all), "#{klass} should have an .all method"
assert obj.respond_to?(:get), "#{klass} should have a .get method"
assert obj.respond_to?(:each), "#{klass} should behave like Enumerable"
end
end

def test_collection_get_arguments
@collections.each do |klass|
obj = klass.new
assert_operator(obj.method(:get).arity, :<=, 1,
"#{klass} should have at most 1 required parameter in get()")
end
end
end

0 comments on commit aaa65b2

Please sign in to comment.