Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeleteContainer command and mocks #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This is a work in progress, in it's current state is still unusable.

*ComputeClient* - Client for Compute Service (Nova)

*StorageClient* - Client for Storage Service (Swift) <- Development hasn't started yet.
*StorageClient* - Client for Storage Service (Swift) <- Development has started

*OpenstackClient* - One client to rule them all!

Expand Down
2 changes: 1 addition & 1 deletion src/Guzzle/Openstack/Storage/Command/CreateContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function setName($name)
*
* @param int $tenantId
*
* @return CreateUser
* @return CreateContainer
*/
public function setTenantId($tenantId)
{
Expand Down
76 changes: 76 additions & 0 deletions src/Guzzle/Openstack/Storage/Command/DeleteContainer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* DeleteContainer.php
*
* PHP Version 5
*
* @category Guzzle
* @package Openstack\Storage\Command
* @author Patrick van Kouteren <[email protected]>
* @license MIT See the LICENSE file that was distributed with this source code.
* @link https://www.cloudvps.com
*/
namespace Guzzle\Openstack\Storage\Command;

use Guzzle\Openstack\Common\Command\AbstractJsonCommand;
use Guzzle\Common\Exception\UnexpectedValueException;

/**
* Delete a container
*
* http://docs.openstack.org/api/openstack-object-storage/1.0/content/delete-container.html
*
* @guzzle name doc="Name of the new container" required="true"
* @guzzle tenantId doc="Tenant id of the new user" required="true"
*/
class DeleteContainer extends AbstractJsonCommand
{

/**
* Maximum number of bytes of the container name according to the manual.
* http://docs.openstack.org/trunk/openstack-object-storage/developer/content/create-container.html
*/
const MAX_NAME_BYTES = 256;

/**
* Set the user name
*
* @param string $name
*
* @return DeleteContainer
*
* @throws \Guzzle\Common\Exception\UnexpectedValueException
*/
public function setName($name)
{
// Slashes are removed
$name = str_replace('/', '', $name);
$bytes = mb_strlen($name, 'latin1');
if ($bytes <= self::MAX_NAME_BYTES) {
return $this->set('name', $name);
} else {
throw new UnexpectedValueException(
"Container name may be max " . self::MAX_NAME_BYTES . " bytes!");
}
}

/**
* Set the tenant id
*
* @param int $tenantId
*
* @return DeleteContainer
*/
public function setTenantId($tenantId)
{
return $this->set('tenantId', $tenantId);
}

protected function build()
{
$this->request = $this->client->delete(
'AUTH_' . $this->get('tenantId') . '/' . $this->get('name')
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* DeleteContainerTest.php
*
* PHP Version 5
*
* @category Guzzle
* @package Openstack\Tests\Storage\Command
* @author Patrick van Kouteren <[email protected]>
* @license MIT See the LICENSE file that was distributed with this source code.
* @link https://www.cloudvps.com
*
*/

namespace Guzzle\Openstack\Tests\Storage\Command;

/**
* Create Container command unit test
*/
class DeleteContainerTest extends
\Guzzle\Openstack\Tests\Storage\Common\StorageTestCase
{

public function testDeleteContainer()
{
$this->setMockResponse($this->client, 'storage/DeleteContainer');
$command = $this->client->getCommand('DeleteContainer');
$command->setTenantId('tenant2');
$command->setName('container1');
$command->prepare();

//Check method and resource
$this->assertEquals(
'http://192.168.4.100:8080/v1/AUTH_tenant2/container1',
$command->getRequest()->getUrl()
);
$this->assertEquals('DELETE', $command->getRequest()->getMethod());

//Check for authentication header
$this->assertTrue($command->getRequest()->hasHeader('X-Auth-Token'));

$this->client->execute($command);
// There's no actual result, so we have to look at the response code and
// check the body is empty.
$result = $command->getResponse();

$this->assertEquals(204, $result->getStatusCode());
$this->assertEquals(0, $result->getContentLength());
}

}
5 changes: 5 additions & 0 deletions tests/mock/storage/DeleteContainer
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
HTTP/1.1 204 No Content
Content-Length: 0
Content-Type: text/html; charset=UTF-8
X-Trans-Id: tx3fa3857f266f44319d9b8f4bf7ce7fc8
Date: Mon, 07 Nov 2011 20:42:58 GMT
4 changes: 4 additions & 0 deletions tests/mock/storage/DeleteContainerNotEmpty
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
HTTP/1.1 409 Conflict
Content-Type: application/json; charset=UTF-8
Content-Length: 0
Date: Sat, 07 Jan 2012 01:50:36 GMT
4 changes: 4 additions & 0 deletions tests/mock/storage/DeleteContainerNotFound
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
HTTP/1.1 404 Not Found
Content-Type: application/json; charset=UTF-8
Content-Length: 0
Date: Sat, 07 Jan 2012 01:50:36 GMT