Skip to content

Commit 6418a00

Browse files
committed
SecurityGroup tests
1 parent 3526638 commit 6418a00

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

src/Networking/v2/Extensions/SecurityGroups/Api.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class Api extends AbstractApi
88
{
9-
private $pathPrefix = '/v2.0/';
9+
private $pathPrefix = 'v2.0';
1010

1111
public function __construct()
1212
{
@@ -23,7 +23,7 @@ public function getSecurityGroups()
2323
{
2424
return [
2525
'method' => 'GET',
26-
'path' => $this->pathPrefix . 'security-groups',
26+
'path' => $this->pathPrefix . '/security-groups',
2727
'params' => [],
2828
];
2929
}
@@ -37,7 +37,7 @@ public function postSecurityGroups()
3737
{
3838
return [
3939
'method' => 'POST',
40-
'path' => $this->pathPrefix . 'security-groups',
40+
'path' => $this->pathPrefix . '/security-groups',
4141
'jsonKey' => 'security_group',
4242
'params' => [
4343
'description' => $this->params->descriptionJson(),
@@ -55,7 +55,7 @@ public function putSecurityGroups()
5555
{
5656
return [
5757
'method' => 'PUT',
58-
'path' => $this->pathPrefix . 'security-groups/{id}',
58+
'path' => $this->pathPrefix . '/security-groups/{id}',
5959
'jsonKey' => 'security_group',
6060
'params' => [
6161
'id' => $this->params->idPath(),
@@ -75,7 +75,7 @@ public function getSecurityGroup()
7575
{
7676
return [
7777
'method' => 'GET',
78-
'path' => $this->pathPrefix . 'security-groups/{id}',
78+
'path' => $this->pathPrefix . '/security-groups/{id}',
7979
'params' => [
8080
'id' => $this->params->idPath(),
8181
],
@@ -92,7 +92,7 @@ public function deleteSecurityGroup()
9292
{
9393
return [
9494
'method' => 'DELETE',
95-
'path' => $this->pathPrefix . 'security-groups/{id}',
95+
'path' => $this->pathPrefix . '/security-groups/{id}',
9696
'params' => [
9797
'id' => $this->params->idPath(),
9898
],
@@ -108,7 +108,7 @@ public function getSecurityRules()
108108
{
109109
return [
110110
'method' => 'GET',
111-
'path' => $this->pathPrefix . 'security-group-rules',
111+
'path' => $this->pathPrefix . '/security-group-rules',
112112
'params' => [],
113113
];
114114
}
@@ -122,7 +122,7 @@ public function postSecurityRules()
122122
{
123123
return [
124124
'method' => 'POST',
125-
'path' => $this->pathPrefix . 'security-group-rules',
125+
'path' => $this->pathPrefix . '/security-group-rules',
126126
'jsonKey' => 'security_group_rule',
127127
'params' => [
128128
'direction' => $this->params->directionJson(),
@@ -147,7 +147,7 @@ public function deleteSecurityRule()
147147
{
148148
return [
149149
'method' => 'DELETE',
150-
'path' => $this->pathPrefix . 'security-group-rules/{id}',
150+
'path' => $this->pathPrefix . '/security-group-rules/{id}',
151151
'params' => [
152152
'id' => $this->params->idPath(),
153153
],
@@ -164,7 +164,7 @@ public function getSecurityRule()
164164
{
165165
return [
166166
'method' => 'GET',
167-
'path' => $this->pathPrefix . 'security-group-rules/{id}',
167+
'path' => $this->pathPrefix . '/security-group-rules/{id}',
168168
'params' => [
169169
'id' => $this->params->idPath(),
170170
],

tests/unit/Networking/v2/Extensions/SecurityGroups/Models/SecurityGroupRuleTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ public function setUp()
2424

2525
public function test_it_deletes()
2626
{
27-
$this->setupMock('DELETE', 'security-group-rules/id', null, [], new Response(202));
27+
$this->setupMock('DELETE', '/v2.0/security-group-rules/id', null, [], new Response(202));
2828

2929
$this->securityGroupRule->delete();
3030
}
3131

3232
public function test_it_retrieves()
3333
{
34-
$this->setupMock('GET', 'security-group-rules/id', null, [], 'SecurityGroupRule');
34+
$this->setupMock('GET', '/v2.0/security-group-rules/id', null, [], 'SecurityGroupRule');
3535

3636
$this->securityGroupRule->retrieve();
3737
}

tests/unit/Networking/v2/Extensions/SecurityGroups/Models/SecurityGroupTest.php

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,44 @@ public function setUp()
2424

2525
public function test_it_deletes()
2626
{
27-
$this->setupMock('DELETE', 'security-groups/id', null, [], new Response(202));
27+
$this->setupMock('DELETE', 'v2.0/security-groups/id', null, [], new Response(202));
2828

2929
$this->securityGroup->delete();
3030
}
3131

3232
public function test_it_retrieves()
3333
{
34-
$this->setupMock('GET', 'security-groups/id', null, [], 'SecurityGroup');
34+
$this->setupMock('GET', 'v2.0/security-groups/id', null, [], 'SecurityGroup');
3535

3636
$this->securityGroup->retrieve();
3737
}
38-
}
38+
39+
public function test_it_updates()
40+
{
41+
$this->setupMock('PUT', 'v2.0/security-groups/id', null, [], 'SecurityGroup');
42+
43+
$this->securityGroup->update();
44+
}
45+
46+
public function test_it_creates()
47+
{
48+
$opts = [
49+
'name' => 'bar',
50+
'description' => 'foo',
51+
];
52+
53+
$expectedJson = json_encode(
54+
[
55+
'security_group' => [
56+
'name' => $opts['name'],
57+
'description' => $opts['description'],
58+
],
59+
],
60+
JSON_UNESCAPED_SLASHES
61+
);
62+
63+
$this->setupMock('POST', 'v2.0/security-groups', $expectedJson, ['Content-Type' => 'application/json'], 'SecurityGroup');
64+
65+
$this->assertInstanceOf(SecurityGroup::class, $this->securityGroup->create($opts));
66+
}
67+
}

0 commit comments

Comments
 (0)