-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Model unit tests + light cleanup
- Loading branch information
Showing
2 changed files
with
49 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require "helpers/test_helper" | ||
|
||
class UnitTestModels < MiniTest::Test | ||
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, | ||
Fog::Compute::Google::DiskType, | ||
Fog::Compute::Google::Operation, | ||
Fog::Compute::Google::Zone, | ||
Fog::Compute::Google::Snapshot, | ||
Fog::Compute::Google::Project ] | ||
# Enumerate all descendants of Fog::Model | ||
descendants = ObjectSpace.each_object(Fog::Model.singleton_class).to_a | ||
|
||
@models = descendants - common_ancestors - exceptions | ||
end | ||
|
||
def teardown | ||
Fog.unmock! | ||
end | ||
|
||
def test_common_methods | ||
# This tests whether Fog::Compute::Google models have common lifecycle methods | ||
@models.each do |klass| | ||
obj = klass.new | ||
assert obj.respond_to?(:save), "#{klass} should have a .save method" | ||
assert obj.respond_to?(:destroy), "#{klass} should have a .destroy method" | ||
end | ||
end | ||
end |