vcloud-core 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,87 +1,82 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Vcloud
4
- module Core
5
- describe EdgeGatewayInterface do
6
-
7
- before(:each) do
8
- @valid_ext_id = "12345678-70ac-487e-9c1e-124716764274"
9
- @gateway_interface_hash = {
10
- :Name=>"EXTERNAL_NETWORK",
11
- :Network=>{
12
- :type=>"application/vnd.vmware.admin.network+xml",
13
- :name=>"EXTERNAL_NETWORK",
14
- :href=>"https://example.com/api/admin/network/#{@valid_ext_id}"
15
- },
16
- :InterfaceType=>"uplink",
17
- :SubnetParticipation=>{
18
- :Gateway=>"192.2.0.1",
19
- :Netmask=>"255.255.255.0",
20
- :IpAddress=>"192.2.0.66"
21
- },
22
- :UseForDefaultRoute=>"true"
23
- }
24
- @interface = EdgeGatewayInterface.new(@gateway_interface_hash)
25
- end
26
-
27
- context "Instance public interface" do
28
- subject { EdgeGatewayInterface.new(@gateway_interface_hash) }
29
- it { should respond_to(:name) }
30
- it { should respond_to(:network_id) }
31
- it { should respond_to(:network_name) }
32
- it { should respond_to(:network_href) }
33
- end
34
-
35
- context "#initialize" do
3
+ describe Vcloud::Core::EdgeGatewayInterface do
4
+
5
+ before(:each) do
6
+ @valid_ext_id = "12345678-70ac-487e-9c1e-124716764274"
7
+ @gateway_interface_hash = {
8
+ :Name=>"EXTERNAL_NETWORK",
9
+ :Network=>{
10
+ :type=>"application/vnd.vmware.admin.network+xml",
11
+ :name=>"EXTERNAL_NETWORK",
12
+ :href=>"https://example.com/api/admin/network/#{@valid_ext_id}"
13
+ },
14
+ :InterfaceType=>"uplink",
15
+ :SubnetParticipation=>{
16
+ :Gateway=>"192.2.0.1",
17
+ :Netmask=>"255.255.255.0",
18
+ :IpAddress=>"192.2.0.66"
19
+ },
20
+ :UseForDefaultRoute=>"true"
21
+ }
22
+ @interface = Vcloud::Core::EdgeGatewayInterface.new(@gateway_interface_hash)
23
+ end
36
24
 
37
- it "should be constructable from just a Fog vCloud GatewayInterfaceType hash" do
38
- obj = EdgeGatewayInterface.new(@gateway_interface_hash)
39
- expect(obj.class).to be(Vcloud::Core::EdgeGatewayInterface)
40
- end
25
+ context "Instance public interface" do
26
+ subject { Vcloud::Core::EdgeGatewayInterface.new(@gateway_interface_hash) }
27
+ it { should respond_to(:name) }
28
+ it { should respond_to(:network_id) }
29
+ it { should respond_to(:network_name) }
30
+ it { should respond_to(:network_href) }
31
+ end
41
32
 
42
- it "should raise an error if passed a nil value" do
43
- expect { EdgeGatewayInterface.new(nil) }.
44
- to raise_error(StandardError, /^EdgeGatewayInterface:/)
45
- end
33
+ context "#initialize" do
46
34
 
47
- it "should raise an error if a :Name is not passed" do
48
- expect { EdgeGatewayInterface.new({}) }.
49
- to raise_error(StandardError, /^EdgeGatewayInterface:/)
50
- end
35
+ it "should be constructable from just a Fog vCloud GatewayInterfaceType hash" do
36
+ obj = Vcloud::Core::EdgeGatewayInterface.new(@gateway_interface_hash)
37
+ expect(obj.class).to be(Vcloud::Core::EdgeGatewayInterface)
38
+ end
51
39
 
52
- it "should raise an error if a :Network is not passed" do
53
- expect { EdgeGatewayInterface.new({Name: 'test-interface'}) }.
54
- to raise_error(StandardError, /^EdgeGatewayInterface:/)
55
- end
40
+ it "should raise an error if passed a nil value" do
41
+ expect { Vcloud::Core::EdgeGatewayInterface.new(nil) }.
42
+ to raise_error(StandardError, /^EdgeGatewayInterface:/)
43
+ end
56
44
 
57
- end
45
+ it "should raise an error if a :Name is not passed" do
46
+ expect { Vcloud::Core::EdgeGatewayInterface.new({}) }.
47
+ to raise_error(StandardError, /^EdgeGatewayInterface:/)
48
+ end
58
49
 
59
- context "#name" do
60
- it "should return the name of the interface" do
61
- expect(@interface.name).to eq('EXTERNAL_NETWORK')
62
- end
63
- end
50
+ it "should raise an error if a :Network is not passed" do
51
+ expect { Vcloud::Core::EdgeGatewayInterface.new({Name: 'test-interface'}) }.
52
+ to raise_error(StandardError, /^EdgeGatewayInterface:/)
53
+ end
64
54
 
65
- context "#network_id" do
66
- it "should return the id of the network the interface is connected to" do
67
- expect(@interface.network_id).to eq(@valid_ext_id)
68
- end
69
- end
55
+ end
70
56
 
71
- context "#network_name" do
72
- it "should return the name of the network the interface is connected to" do
73
- expect(@interface.network_name).to eq('EXTERNAL_NETWORK')
74
- end
75
- end
57
+ context "#name" do
58
+ it "should return the name of the interface" do
59
+ expect(@interface.name).to eq('EXTERNAL_NETWORK')
60
+ end
61
+ end
76
62
 
77
- context "#network_href" do
78
- it "should return the href of the network the interface is connected to" do
79
- expect(@interface.network_href).to eq("https://example.com/api/admin/network/#{@valid_ext_id}")
80
- end
81
- end
63
+ context "#network_id" do
64
+ it "should return the id of the network the interface is connected to" do
65
+ expect(@interface.network_id).to eq(@valid_ext_id)
66
+ end
67
+ end
82
68
 
69
+ context "#network_name" do
70
+ it "should return the name of the network the interface is connected to" do
71
+ expect(@interface.network_name).to eq('EXTERNAL_NETWORK')
83
72
  end
73
+ end
84
74
 
75
+ context "#network_href" do
76
+ it "should return the href of the network the interface is connected to" do
77
+ expect(@interface.network_href).to eq("https://example.com/api/admin/network/#{@valid_ext_id}")
78
+ end
85
79
  end
86
80
 
87
81
  end
82
+
@@ -1,163 +1,157 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Vcloud
4
- module Core
5
- describe EdgeGateway do
6
-
7
- before(:each) do
8
- @edgegw_id = '12345678-1234-1234-1234-000000111454'
9
- @mock_fog_interface = StubFogInterface.new
10
- allow(Vcloud::Core::Fog::ServiceInterface).to receive(:new).and_return(@mock_fog_interface)
11
- end
3
+ describe Vcloud::Core::EdgeGateway do
12
4
 
13
- context "Class public interface" do
14
- it { expect(EdgeGateway).to respond_to(:get_ids_by_name) }
15
- it { expect(EdgeGateway).to respond_to(:get_by_name) }
16
- end
5
+ before(:each) do
6
+ @edgegw_id = '12345678-1234-1234-1234-000000111454'
7
+ @mock_fog_interface = StubFogInterface.new
8
+ allow(Vcloud::Core::Fog::ServiceInterface).to receive(:new).and_return(@mock_fog_interface)
9
+ end
17
10
 
18
- context "Instance public interface" do
19
- subject { EdgeGateway.new(@edgegw_id) }
20
- it { should respond_to(:id) }
21
- it { should respond_to(:name) }
22
- it { should respond_to(:href) }
23
- it { should respond_to(:vcloud_gateway_interface_by_id) }
24
- end
11
+ context "Class public interface" do
12
+ it { expect(Vcloud::Core::EdgeGateway).to respond_to(:get_ids_by_name) }
13
+ it { expect(Vcloud::Core::EdgeGateway).to respond_to(:get_by_name) }
14
+ end
25
15
 
26
- context "#initialize" do
16
+ context "Instance public interface" do
17
+ subject { Vcloud::Core::EdgeGateway.new(@edgegw_id) }
18
+ it { should respond_to(:id) }
19
+ it { should respond_to(:name) }
20
+ it { should respond_to(:href) }
21
+ it { should respond_to(:vcloud_gateway_interface_by_id) }
22
+ end
27
23
 
28
- it "should be constructable from just an id reference" do
29
- obj = EdgeGateway.new(@edgegw_id)
30
- expect(obj.class).to be(Vcloud::Core::EdgeGateway)
31
- end
24
+ context "#initialize" do
32
25
 
33
- it "should store the id specified" do
34
- obj = EdgeGateway.new(@edgegw_id)
35
- expect(obj.id).to eq(@edgegw_id)
36
- end
26
+ it "should be constructable from just an id reference" do
27
+ obj = Vcloud::Core::EdgeGateway.new(@edgegw_id)
28
+ expect(obj.class).to be(Vcloud::Core::EdgeGateway)
29
+ end
37
30
 
38
- it "should raise error if id is not in correct format" do
39
- bogus_id = '123123-bogus-id-123445'
40
- expect{ EdgeGateway.new(bogus_id) }.to raise_error("EdgeGateway id : #{bogus_id} is not in correct format" )
41
- end
31
+ it "should store the id specified" do
32
+ obj = Vcloud::Core::EdgeGateway.new(@edgegw_id)
33
+ expect(obj.id).to eq(@edgegw_id)
34
+ end
42
35
 
43
- end
36
+ it "should raise error if id is not in correct format" do
37
+ bogus_id = '123123-bogus-id-123445'
38
+ expect{ Vcloud::Core::EdgeGateway.new(bogus_id) }.to raise_error("EdgeGateway id : #{bogus_id} is not in correct format" )
39
+ end
44
40
 
45
- context "#get_by_name" do
41
+ end
46
42
 
47
- it "should return a EdgeGateway object if name exists" do
48
- q_results = [
49
- { :name => 'edgegw-test-1', :href => "/#{@edgegw_id}" }
50
- ]
51
- mock_query = double(:query_runner)
52
- expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_query)
53
- expect(mock_query).to receive(:run).with('edgeGateway', :filter => "name==edgegw-test-1").and_return(q_results)
54
- @obj = EdgeGateway.get_by_name('edgegw-test-1')
55
- expect(@obj.class).to be(Vcloud::Core::EdgeGateway)
56
- end
57
-
58
- it "should return an object with the correct id if name exists" do
59
- q_results = [
60
- { :name => 'edgegw-test-1', :href => "/#{@edgegw_id}" }
43
+ context "#get_by_name" do
44
+
45
+ it "should return a Vcloud::Core::EdgeGateway object if name exists" do
46
+ q_results = [
47
+ { :name => 'edgegw-test-1', :href => "/#{@edgegw_id}" }
48
+ ]
49
+ mock_query = double(:query_runner)
50
+ expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_query)
51
+ expect(mock_query).to receive(:run).with('edgeGateway', :filter => "name==edgegw-test-1").and_return(q_results)
52
+ @obj = Vcloud::Core::EdgeGateway.get_by_name('edgegw-test-1')
53
+ expect(@obj.class).to be(Vcloud::Core::EdgeGateway)
54
+ end
55
+
56
+ it "should return an object with the correct id if name exists" do
57
+ q_results = [
58
+ { :name => 'edgegw-test-1', :href => "/#{@edgegw_id}" }
59
+ ]
60
+ mock_query = double(:query_runner)
61
+ expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_query)
62
+ expect(mock_query).to receive(:run).with('edgeGateway', :filter => "name==edgegw-test-1").and_return(q_results)
63
+ @obj = Vcloud::Core::EdgeGateway.get_by_name('edgegw-test-1')
64
+ expect(@obj.id).to eq(@edgegw_id)
65
+ end
66
+
67
+ it "should raise an error if no edgegw with that name exists" do
68
+ q_results = [ ]
69
+ mock_query = double(:query_runner)
70
+ expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_query)
71
+ expect(mock_query).to receive(:run).with('edgeGateway', :filter => "name==edgegw-test-1").and_return(q_results)
72
+ expect{ Vcloud::Core::EdgeGateway.get_by_name('edgegw-test-1') }.to raise_exception(RuntimeError, "edgeGateway edgegw-test-1 not found")
73
+ end
74
+
75
+ end
76
+
77
+ context "Interface related tests" do
78
+
79
+ before(:each) do
80
+ @valid_ext_id = "12345678-70ac-487e-9c1e-124716764274"
81
+ @valid_int_id = "12345678-70ac-487e-9c1e-552f1f0a91dc"
82
+ edge_gateway_hash = {
83
+ :Configuration=>
84
+ {:GatewayBackingConfig=>"compact",
85
+ :GatewayInterfaces=>
86
+ {:GatewayInterface=>
87
+ [{:Name=>"EXTERNAL_NETWORK",
88
+ :Network=>
89
+ {:type=>"application/vnd.vmware.admin.network+xml",
90
+ :name=>"EXTERNAL_NETWORK",
91
+ :href=>
92
+ "https://example.com/api/admin/network/#{@valid_ext_id}"},
93
+ :InterfaceType=>"uplink",
94
+ :SubnetParticipation=>
95
+ {:Gateway=>"192.2.0.1",
96
+ :Netmask=>"255.255.255.0",
97
+ :IpAddress=>"192.2.0.66"},
98
+ :UseForDefaultRoute=>"true"},
99
+ {:Name=>"INTERNAL_NETWORK",
100
+ :Network=>
101
+ {:type=>"application/vnd.vmware.admin.network+xml",
102
+ :name=>"INTERNAL_NETWORK",
103
+ :href=>
104
+ "https://example.com/api/admin/network/#{@valid_int_id}"},
105
+ :InterfaceType=>"internal",
106
+ :SubnetParticipation=>
107
+ {:Gateway=>"192.168.1.1",
108
+ :Netmask=>"255.255.255.0",
109
+ :IpAddress=>"192.168.1.55"},
110
+ :UseForDefaultRoute=>"false"
111
+ },
61
112
  ]
62
- mock_query = double(:query_runner)
63
- expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_query)
64
- expect(mock_query).to receive(:run).with('edgeGateway', :filter => "name==edgegw-test-1").and_return(q_results)
65
- @obj = EdgeGateway.get_by_name('edgegw-test-1')
66
- expect(@obj.id).to eq(@edgegw_id)
67
- end
68
-
69
- it "should raise an error if no edgegw with that name exists" do
70
- q_results = [ ]
71
- mock_query = double(:query_runner)
72
- expect(Vcloud::Core::QueryRunner).to receive(:new).and_return(mock_query)
73
- expect(mock_query).to receive(:run).with('edgeGateway', :filter => "name==edgegw-test-1").and_return(q_results)
74
- expect{ EdgeGateway.get_by_name('edgegw-test-1') }.to raise_exception(RuntimeError, "edgeGateway edgegw-test-1 not found")
75
- end
113
+ }
114
+ }
115
+ }
116
+ expect(@mock_fog_interface).to receive(:get_edge_gateway).
117
+ and_return(edge_gateway_hash)
118
+ @edgegw = Vcloud::Core::EdgeGateway.new(@edgegw_id)
119
+ end
120
+
121
+ context "#vcloud_gateway_interface_by_id" do
76
122
 
123
+ it "should return nil if the network id is not found" do
124
+ expect(@edgegw.vcloud_gateway_interface_by_id(
125
+ '12345678-1234-1234-1234-123456789012')).
126
+ to be_nil
77
127
  end
78
128
 
79
- context "Interface related tests" do
80
-
81
- before(:each) do
82
- @valid_ext_id = "12345678-70ac-487e-9c1e-124716764274"
83
- @valid_int_id = "12345678-70ac-487e-9c1e-552f1f0a91dc"
84
- edge_gateway_hash = {
85
- :Configuration=>
86
- {:GatewayBackingConfig=>"compact",
87
- :GatewayInterfaces=>
88
- {:GatewayInterface=>
89
- [{:Name=>"EXTERNAL_NETWORK",
90
- :Network=>
91
- {:type=>"application/vnd.vmware.admin.network+xml",
92
- :name=>"EXTERNAL_NETWORK",
93
- :href=>
94
- "https://example.com/api/admin/network/#{@valid_ext_id}"},
95
- :InterfaceType=>"uplink",
96
- :SubnetParticipation=>
97
- {:Gateway=>"192.2.0.1",
98
- :Netmask=>"255.255.255.0",
99
- :IpAddress=>"192.2.0.66"},
100
- :UseForDefaultRoute=>"true"},
101
- {:Name=>"INTERNAL_NETWORK",
102
- :Network=>
103
- {:type=>"application/vnd.vmware.admin.network+xml",
104
- :name=>"INTERNAL_NETWORK",
105
- :href=>
106
- "https://example.com/api/admin/network/#{@valid_int_id}"},
107
- :InterfaceType=>"internal",
108
- :SubnetParticipation=>
109
- {:Gateway=>"192.168.1.1",
110
- :Netmask=>"255.255.255.0",
111
- :IpAddress=>"192.168.1.55"},
112
- :UseForDefaultRoute=>"false"
113
- },
114
- ]
115
- }
116
- }
117
- }
118
- expect(@mock_fog_interface).to receive(:get_edge_gateway).
119
- and_return(edge_gateway_hash)
120
- @edgegw = EdgeGateway.new(@edgegw_id)
121
- end
122
-
123
- context "#vcloud_gateway_interface_by_id" do
124
-
125
- it "should return nil if the network id is not found" do
126
- expect(@edgegw.vcloud_gateway_interface_by_id(
127
- '12345678-1234-1234-1234-123456789012')).
128
- to be_nil
129
- end
130
-
131
- it "should return a vcloud network hash if the network id is found" do
132
- expect(@edgegw.vcloud_gateway_interface_by_id(@valid_int_id)).
133
- to eq(
134
- {:Name=>"INTERNAL_NETWORK",
135
- :Network=>
136
- {:type=>"application/vnd.vmware.admin.network+xml",
137
- :name=>"INTERNAL_NETWORK",
138
- :href=>
139
- "https://example.com/api/admin/network/#{@valid_int_id}"},
140
- :InterfaceType=>"internal",
141
- :SubnetParticipation=>
142
- {:Gateway=>"192.168.1.1",
143
- :Netmask=>"255.255.255.0",
144
- :IpAddress=>"192.168.1.55"},
145
- :UseForDefaultRoute=>"false"
146
- },
147
- )
148
- end
149
- end
150
-
151
- context "#interfaces" do
152
-
153
- it "should return an array of EdgeGatewayInterface objects" do
154
- interfaces_list = @edgegw.interfaces
155
- expect(interfaces_list.class).to be(Array)
156
- expect(interfaces_list.first.class).to be(Vcloud::Core::EdgeGatewayInterface)
157
- end
158
-
159
- end
129
+ it "should return a vcloud network hash if the network id is found" do
130
+ expect(@edgegw.vcloud_gateway_interface_by_id(@valid_int_id)).
131
+ to eq(
132
+ {:Name=>"INTERNAL_NETWORK",
133
+ :Network=>
134
+ {:type=>"application/vnd.vmware.admin.network+xml",
135
+ :name=>"INTERNAL_NETWORK",
136
+ :href=>
137
+ "https://example.com/api/admin/network/#{@valid_int_id}"},
138
+ :InterfaceType=>"internal",
139
+ :SubnetParticipation=>
140
+ {:Gateway=>"192.168.1.1",
141
+ :Netmask=>"255.255.255.0",
142
+ :IpAddress=>"192.168.1.55"},
143
+ :UseForDefaultRoute=>"false"
144
+ },
145
+ )
146
+ end
147
+ end
148
+
149
+ context "#interfaces" do
160
150
 
151
+ it "should return an array of Vcloud::Core::EdgeGatewayInterface objects" do
152
+ interfaces_list = @edgegw.interfaces
153
+ expect(interfaces_list.class).to be(Array)
154
+ expect(interfaces_list.first.class).to be(Vcloud::Core::EdgeGatewayInterface)
161
155
  end
162
156
 
163
157
  end