File: test_common_models.rb

package info (click to toggle)
ruby-fog-google 1.19.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,568 kB
  • sloc: ruby: 16,775; makefile: 3
file content (35 lines) | stat: -rw-r--r-- 1,204 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require "helpers/test_helper"

class UnitTestModels < MiniTest::Test
  def setup
    Fog.mock!
    @client = Fog::Compute.new(provider: "google",
                               google_project: "foo")

    # 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.select { |d| d.name.match(/Fog::Compute::Google/) } - 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