File: test_collection.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 (60 lines) | stat: -rw-r--r-- 2,150 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
module TestCollection
  # Anything that includes TestCollection must, during setup, assign @subject and @factory, where
  #   @subject is the collection under test, (e.g. Fog::Compute[:google].servers)
  #   @factory is a CollectionFactory

  def test_lifecycle
    one = @subject.new(@factory.params)
    one.save
    two = @subject.create(@factory.params)

    # XXX HACK compares identities
    # should be replaced with simple includes? when `==` is properly implemented in fog-core; see fog/fog-core#148
    assert_includes @subject.all.map(&:identity), one.identity
    assert_includes @subject.all.map(&:identity), two.identity

    assert_equal one.identity, @subject.get(one.identity).identity
    assert_equal two.identity, @subject.get(two.identity).identity

    # Some factories that have scoped parameters (zone, region) have a special
    # `get` method defined in the factory to pass the correct parameters in
    if @factory.respond_to?(:get)
      assert_equal one.identity, @factory.get(one.identity).identity
      assert_equal two.identity, @factory.get(two.identity).identity
    end

    # Some factories that have scoped parameters (zone, region) have a special
    # `all` method defined in the factory to pass the correct parameters in
    if @factory.respond_to?(:all)
      subject_list = @subject.all
      scoped_subject_list = @factory.all

      # Assert that whatever .all(scope) returns is a subset of .all
      assert(scoped_subject_list.all? { |x| subject_list.include? x },
             "Output of @factory.all must be a subset of @subject.all")
    end

    one.destroy
    two.destroy

    Fog.wait_for { !@subject.all.map(&:identity).include? one.identity }
    Fog.wait_for { !@subject.all.map(&:identity).include? two.identity }
  end

  def test_get_returns_nil_if_resource_does_not_exist
    assert_nil @factory.get("fog-test-fake-identity") if @factory.respond_to?(:get)
    assert_nil @subject.get("fog-test-fake-identity")
  end

  def test_enumerable
    assert_respond_to @subject, :each
  end

  def test_nil_get
    assert_nil @subject.get(nil)
  end

  def teardown
    @factory.cleanup
  end
end