forked from rackspace/php-opencloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerMetadataTest.php
More file actions
81 lines (79 loc) · 2.25 KB
/
ServerMetadataTest.php
File metadata and controls
81 lines (79 loc) · 2.25 KB
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
<?php
/**
* Unit Tests
*
* @copyright 2012-2013 Rackspace Hosting, Inc.
* See COPYING for licensing information
*
* @version 1.0.0
* @author Glen Campbell <glen.campbell@rackspace.com>
*/
require_once('stub_conn.inc');
require_once('servermetadata.inc');
require_once('compute.inc');
class ServerMetadataTest extends PHPUnit_Framework_TestCase
{
private
$server,
$metadata;
public function __construct() {
$conn = new StubConnection('http://example.com', 'SECRET');
$compute = new OpenCloud\Compute(
$conn,
'cloudServersOpenStack',
'DFW',
'publicURL'
);
$this->server = new OpenCloud\Compute\Server($compute, 'Identifier');
$this->metadata = new OpenCloud\Compute\ServerMetadata($this->server);
}
/**
* Tests
*/
public function test___construct() {
$this->assertEquals(
'OpenCloud\Compute\ServerMetadata',
get_class($this->metadata));
// test whole group
$metadata = $this->server->Metadata();
$this->assertEquals(
'bar',
$metadata->foo);
// now test individual property
$met = $this->server->metadata('foobar');
$met->foobar = 'BAZ';
$this->assertEquals('BAZ', $met->foobar);
}
public function testUrl() {
$this->assertEquals(
'https://dfw.servers.api.rackspacecloud.com/v2/9999/servers/9bfd203a-0695-xxxx-yyyy-66c4194c967b/metadata',
$this->metadata->Url());
$m2 = new OpenCloud\Compute\ServerMetadata($this->server, 'property');
$this->assertEquals(
'https://dfw.servers.api.rackspacecloud.com/v2/9999/servers/9bfd203a-0695-xxxx-yyyy-66c4194c967b/metadata/property',
$m2->Url());
}
/**
* @expectedException OpenCloud\Compute\MetadataKeyError
*/
public function test___set() {
$this->metadata->property = 'value';
$this->assertEquals('value', $this->metadata->property);
$m2 = new OpenCloud\Compute\ServerMetadata($this->server, 'property');
$m2->foo = 'bar'; // should cause exception
$this->assertEquals(NULL, $m2->foo);
}
public function testCreate() {
$this->metadata->foo = 'bar';
$this->metadata->Create();
$this->assertEquals('bar', $this->metadata->foo);
}
public function testUpdate() {
$this->metadata->foo = 'baz';
$this->metadata->Update();
$this->assertEquals('baz', $this->metadata->foo);
}
public function testDelete() {
$this->metadata->Delete();
}
}