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 95 96
|
<?php
/**
* @copyright Copyright 2012-2014 Rackspace US, Inc.
See COPYING for licensing information.
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache 2.0
* @version 1.5.9
* @author Glen Campbell <glen.campbell@rackspace.com>
* @author Jamie Hannaford <jamie.hannaford@rackspace.com>
*/
namespace OpenCloud\Tests\Compute\Resource;
use OpenCloud\Tests\Compute\ComputeTestCase;
class KeyPairTest extends ComputeTestCase
{
public function test_Service_Methods()
{
$this->assertInstanceOf(
'OpenCloud\Compute\Resource\KeyPair',
$this->service->keypair()
);
$this->assertInstanceOf(
self::COLLECTION_CLASS,
$this->service->listKeypairs()
);
}
public function test_Url()
{
$keypair = $this->service->keypair(array('name' => 'foo'));
$this->assertRegExp('#/os-keypairs/foo$#', (string) $keypair->getUrl());
}
public function test_Create()
{
$keypair = $this->service->keypair(array('name' => 'foo'));
$this->assertNotNull($keypair->create());
}
/**
* @expectedException OpenCloud\Common\Exceptions\UpdateError
*/
public function test_Update_Fails()
{
$this->service->keypair()->update();
}
public function test_Upload()
{
$path = __DIR__ . '/test.key';
$contents = file_get_contents($path);
$keypair = $this->service->keypair();
$keypair->upload(array('path' => $path));
$this->assertEquals($contents, $keypair->getPublicKey());
$keypair->upload(array('data' => $contents));
$this->assertEquals($contents, $keypair->getPublicKey());
}
/**
* @expectedException OpenCloud\Compute\Exception\KeyPairException
*/
public function test_Upload_Fails_IncorrectPath()
{
$this->service->keypair()->upload(array('path' => 'foo'));
}
/**
* @expectedException OpenCloud\Compute\Exception\KeyPairException
*/
public function test_Upload_Fails_NoKey()
{
$this->service->keypair()->upload();
}
/**
* @expectedException OpenCloud\Common\Exceptions\InvalidArgumentError
*/
public function test_Name_Validity()
{
$this->service->keypair()->setName('!!!');
}
/**
* @expectedException OpenCloud\Common\Exceptions\InvalidArgumentError
*/
public function test_Name_Validity_Create()
{
$this->service->keypair()->create(array('name' => '!!!'));
}
}
|