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

feat: S3Compatible storage adapter #76

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
Test for S3Compatible plus changes to accomodate vhost or path-style
  • Loading branch information
haymaker committed Jun 5, 2023
commit 4cc792173fc8f1ad31d2a7b8cdf8338afdf07715
55 changes: 55 additions & 0 deletions tests/Storage/Device/S3CompatibleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace Utopia\Tests\Storage\Device;

use Utopia\Storage\Device\S3Compatible;
use Utopia\Tests\Storage\S3Base;

class S3CompatibleTest extends S3Base
{
protected function init(): void
{
$root = '/root';
$endpoint = $_SERVER['S3COMPATIBLE_ENDPOINT'] ?? '';
$vhost = $_SERVER['S3COMPATIBLE_VHOST'] === 'true';
$this->vhost = $vhost;
$key = $_SERVER['S3COMPATIBLE_ACCESS_KEY'] ?? '';
$secret = $_SERVER['S3COMPATIBLE_SECRET'] ?? '';
$bucket = $_SERVER['S3COMPATIBLE_BUCKET'] ?? 'appwrite-test-bucket';
$region = $_SERVER['S3COMPATIBLE_REGION'] ?? '';

if ($vhost) {
$this->root = $root;
} else {
$this->root = $bucket.$root;
}

$this->object = new S3Compatible($endpoint, $root, $key, $secret, $bucket, $vhost, $region);
}

/**
* @return string
*/
public function getAdapterName(): string
{
return $this->object->getName();
}

/**
* @return string
*/
public function getAdapterType(): string
{
return $this->object->getType();
}

/**
* @return string
*/
public function getAdapterDescription(): string
{
return $this->object->getDescription();
}
}
15 changes: 13 additions & 2 deletions tests/Storage/S3Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ abstract protected function getAdapterDescription(): string;
*/
protected $root = '/root';

/**
* @var bool
*/
protected $vhost = true;

public function setUp(): void
{
$this->init();
Expand Down Expand Up @@ -138,12 +143,18 @@ public function testXMLUpload()

public function testDeletePath()
{
if ($this->vhost) {
$dpParam = 'bucket';
} else {
$dpParam = '';
}

// Test Single Object
$path = $this->object->getPath('text-for-delete-path.txt');
$path = str_ireplace($this->object->getRoot(), $this->object->getRoot().DIRECTORY_SEPARATOR.'bucket', $path);
$this->assertEquals(true, $this->object->write($path, 'Hello World', 'text/plain'));
$this->assertEquals(true, $this->object->exists($path));
$this->assertEquals(true, $this->object->deletePath('bucket'));
$this->assertEquals(true, $this->object->deletePath($dpParam));
$this->assertEquals(false, $this->object->exists($path));

// Test Multiple Objects
Expand All @@ -157,7 +168,7 @@ public function testDeletePath()
$this->assertEquals(true, $this->object->write($path2, 'Hello World', 'text/plain'));
$this->assertEquals(true, $this->object->exists($path2));

$this->assertEquals(true, $this->object->deletePath('bucket'));
$this->assertEquals(true, $this->object->deletePath($dpParam));
$this->assertEquals(false, $this->object->exists($path));
$this->assertEquals(false, $this->object->exists($path2));
}
Expand Down