diff --git a/test/unit/compute/test_common_collections.rb b/test/unit/compute/test_common_collections.rb index a07e9e08b6..74e1d6e5ca 100644 --- a/test/unit/compute/test_common_collections.rb +++ b/test/unit/compute/test_common_collections.rb @@ -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 @@ -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 diff --git a/test/unit/compute/test_common_models.rb b/test/unit/compute/test_common_models.rb index d830538475..f5fbc5afdc 100644 --- a/test/unit/compute/test_common_models.rb +++ b/test/unit/compute/test_common_models.rb @@ -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, @@ -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 diff --git a/test/unit/dns/test_common_collections.rb b/test/unit/dns/test_common_collections.rb new file mode 100644 index 0000000000..236d927747 --- /dev/null +++ b/test/unit/dns/test_common_collections.rb @@ -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 diff --git a/test/unit/monitoring/test_comon_collections.rb b/test/unit/monitoring/test_comon_collections.rb new file mode 100644 index 0000000000..581a618000 --- /dev/null +++ b/test/unit/monitoring/test_comon_collections.rb @@ -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 diff --git a/test/unit/pubsub/test_common_collections.rb b/test/unit/pubsub/test_common_collections.rb new file mode 100644 index 0000000000..071c354b55 --- /dev/null +++ b/test/unit/pubsub/test_common_collections.rb @@ -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 diff --git a/test/unit/sql/test_common_collections.rb b/test/unit/sql/test_common_collections.rb new file mode 100644 index 0000000000..7326b732c7 --- /dev/null +++ b/test/unit/sql/test_common_collections.rb @@ -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 diff --git a/test/unit/storage/test_common_json_collections.rb b/test/unit/storage/test_common_json_collections.rb new file mode 100644 index 0000000000..567ea375d7 --- /dev/null +++ b/test/unit/storage/test_common_json_collections.rb @@ -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 diff --git a/test/unit/storage/test_common_xml_collections.rb b/test/unit/storage/test_common_xml_collections.rb new file mode 100644 index 0000000000..94a0db2105 --- /dev/null +++ b/test/unit/storage/test_common_xml_collections.rb @@ -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