File: address_tests.rb

package info (click to toggle)
ruby-fog-openstack 1.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,784 kB
  • sloc: ruby: 47,937; makefile: 5; sh: 4
file content (94 lines) | stat: -rw-r--r-- 2,621 bytes parent folder | download
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
require "test_helper"

require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))

# With Minitest the use of class variable is one way of providing before(:all)
# Meanwhile using class variable using @@<name> triggers a cascade of messages
# such as "warning: class variable access from toplevel" which pollute the tests
# output. The latter has been avoided using class_variable_set/get and class
# methods to wrap them.
describe "Fog::OpenStack::Compute | address requests" do
  def self.compute
    class_variable_get(:@@compute)
  end

  def self.server_id
    class_variable_get(:@@server_id)
  end

  def self.data
    class_variable_get(:@@data)
  end

  class_variable_set(:@@compute, Fog::OpenStack::Compute.new)
  class_variable_set(:@@server_id,
                     compute.create_server("test_server",
                                           get_image_ref,
                                           get_flavor_ref).body['server']['id'])
  class_variable_set(:@@data, compute.allocate_address.body)

  compute.servers.get(server_id).wait_for { ready? }

  def compute
    self.class.compute
  end

  Minitest.after_run do
    compute.delete_server(server_id)
  end

  describe "success" do
    def address_id
      self.class.data['floating_ip']['id']
    end

    def address_ip
      self.class.data['floating_ip']['ip']
    end

    def address_format
      {
        "instance_id" => NilClass,
        "ip"          => String,
        "fixed_ip"    => NilClass,
        "id"          => Integer,
        "pool"        => String
      }
    end

    def address_pools_format
      {"name" => String}
    end

    it "#allocate_address" do
      self.class.data.must_match_schema("floating_ip" => address_format)
    end

    it "#list_all_addresses" do
      compute.list_all_addresses.body.
        must_match_schema("floating_ips" => [address_format])
    end

    it "#get_address(address_id)" do
      compute.get_address(address_id).body.
        must_match_schema("floating_ip" => address_format)
    end

    it "#list_address_pools" do
      compute.list_address_pools.body.
        must_match_schema("floating_ip_pools" => [address_pools_format])
    end

    it "#associate_address(server_id, ip_address)" do
      compute.associate_address(self.class.server_id, address_ip).body.must_equal ""
    end

    it "#disassociate_address(server_id, ip_address)" do
      compute.disassociate_address(self.class.server_id, address_ip).body.must_equal ""
    end

    it "#release_address(ip_address)" do
      compute.release_address(address_id).status.must_equal 202
    end
  end
end