File: security_group_rule_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 (71 lines) | stat: -rw-r--r-- 2,354 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
require 'test_helper'

describe "Fog::OpenStack::Network | security_grouprule requests" do
  before do
    @security_group_rule_format = {
      "id"                => String,
      "remote_group_id"   => Fog::Nullable::String,
      "direction"         => String,
      "remote_ip_prefix"  => Fog::Nullable::String,
      "protocol"          => Fog::Nullable::String,
      "ethertype"         => String,
      "port_range_max"    => Fog::Nullable::Integer,
      "port_range_min"    => Fog::Nullable::Integer,
      "security_group_id" => String,
      "tenant_id"         => String
    }
  end

  describe "success" do
    before do
      attributes          = {:name => "my_security_group", :description => "tests group"}
      security_group      = network.create_security_group(attributes).body["security_group"]
      @sec_group_id       = security_group["id"]
      @sec_group_rule_id  = nil

      attributes = {
        :remote_ip_prefix => "0.0.0.0/0",
        :protocol         => "tcp",
        :port_range_min   => 22,
        :port_range_max   => 22
      }
      @security_group_rule = network.create_security_group_rule(
        @sec_group_id, 'ingress', attributes
      ).body["security_group_rule"]
      @sec_group_rule_id = @security_group_rule["id"]
    end

    it "#create_security_group_rule(@sec_group_id, 'ingress', attributes)" do
      @security_group_rule.must_match_schema(@security_group_rule_format)
    end

    it "#get_security_group_rule(@sec_group_rule_id)" do
      network.get_security_group_rule(@sec_group_rule_id).
        body["security_group_rule"].must_match_schema(@security_group_rule_format)
    end

    it "#list_security_group_rules" do
      network.list_security_group_rules.body.must_match_schema(
        "security_group_rules" => [@security_group_rule_format]
      )
    end

    it "#delete_security_group_rule(@sec_group_rule_id)" do
      network.delete_security_group_rule(@sec_group_rule_id).status.must_equal 204
    end
  end

  describe "failure" do
    it "#get_security_group_rule(0)" do
      proc do
        network.get_security_group_rule(0)
      end.must_raise Fog::OpenStack::Network::NotFound
    end

    it "#delete_security_group_rule(0)" do
      proc do
        network.delete_security_group_rule(0)
      end.must_raise Fog::OpenStack::Network::NotFound
    end
  end
end