|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright 2021 Google LLC |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +namespace Google\Cloud\Samples\Storage\Tests; |
| 19 | + |
| 20 | +use Google\Cloud\Storage\StorageClient; |
| 21 | +use Google\Cloud\TestUtils\TestTrait; |
| 22 | +use PHPUnit\Framework\TestCase; |
| 23 | + |
| 24 | +/** |
| 25 | + * Unit tests for Turbo Replication(RPO) |
| 26 | + */ |
| 27 | +class TurboReplicationTest extends TestCase |
| 28 | +{ |
| 29 | + use TestTrait; |
| 30 | + |
| 31 | + private static $storage; |
| 32 | + private static $bucketName; |
| 33 | + private static $bucket; |
| 34 | + |
| 35 | + public static function setUpBeforeClass(): void |
| 36 | + { |
| 37 | + self::$storage = new StorageClient(); |
| 38 | + self::$bucketName = uniqid('samples-turbo-replication-'); |
| 39 | + } |
| 40 | + |
| 41 | + public static function tearDownAfterClass(): void |
| 42 | + { |
| 43 | + self::$bucket->delete(); |
| 44 | + } |
| 45 | + |
| 46 | + public function testCreateBucketWithTurboReplication() |
| 47 | + { |
| 48 | + $output = self::runFunctionSnippet('create_bucket_turbo_replication', [ |
| 49 | + self::$bucketName, |
| 50 | + 'asia1' |
| 51 | + ]); |
| 52 | + |
| 53 | + $this->assertStringContainsString( |
| 54 | + sprintf( |
| 55 | + 'Bucket with Turbo Replication set to \'ASYNC_TURBO\' created: %s', |
| 56 | + self::$bucketName |
| 57 | + ), |
| 58 | + $output |
| 59 | + ); |
| 60 | + |
| 61 | + self::$bucket = self::$storage->bucket(self::$bucketName); |
| 62 | + $this->assertEquals('ASYNC_TURBO', self::$bucket->info()['rpo']); |
| 63 | + } |
| 64 | + |
| 65 | + /** @depends testCreateBucketWithTurboReplication */ |
| 66 | + public function testGetTurboReplicationStatus() |
| 67 | + { |
| 68 | + $output = self::runFunctionSnippet('get_turbo_replication_status', [ |
| 69 | + self::$bucketName, |
| 70 | + ]); |
| 71 | + |
| 72 | + $this->assertEquals( |
| 73 | + sprintf( |
| 74 | + 'The bucket\'s RPO value is: %s.' . PHP_EOL, |
| 75 | + 'ASYNC_TURBO' |
| 76 | + ), |
| 77 | + $output |
| 78 | + ); |
| 79 | + } |
| 80 | + |
| 81 | + /** @depends testCreateBucketWithTurboReplication */ |
| 82 | + public function testSetTurboReplicationStatusDefault() |
| 83 | + { |
| 84 | + $output = self::runFunctionSnippet('set_turbo_replication_default', [ |
| 85 | + self::$bucketName, |
| 86 | + ]); |
| 87 | + |
| 88 | + $this->assertEquals( |
| 89 | + sprintf( |
| 90 | + 'Turbo Replication has been set to DEFAULT for %s.' . PHP_EOL, |
| 91 | + self::$bucketName |
| 92 | + ), |
| 93 | + $output |
| 94 | + ); |
| 95 | + |
| 96 | + self::$bucket->reload(); |
| 97 | + $this->assertEquals('DEFAULT', self::$bucket->info()['rpo']); |
| 98 | + } |
| 99 | + |
| 100 | + /** @depends testCreateBucketWithTurboReplication */ |
| 101 | + public function testSetTurboReplicationStatusAsyncTurbo() |
| 102 | + { |
| 103 | + $output = self::runFunctionSnippet('set_turbo_replication_async_turbo', [ |
| 104 | + self::$bucketName, |
| 105 | + ]); |
| 106 | + |
| 107 | + $this->assertEquals( |
| 108 | + sprintf( |
| 109 | + 'Turbo Replication has been set to ASYNC_TURBO for %s.' . PHP_EOL, |
| 110 | + self::$bucketName |
| 111 | + ), |
| 112 | + $output |
| 113 | + ); |
| 114 | + |
| 115 | + self::$bucket->reload(); |
| 116 | + $this->assertEquals('ASYNC_TURBO', self::$bucket->info()['rpo']); |
| 117 | + } |
| 118 | +} |
0 commit comments