17
17
18
18
namespace Google \Cloud \Samples \Spanner ;
19
19
20
+ use Google \Cloud \Spanner \InstanceConfiguration ;
20
21
use Google \Cloud \Spanner \SpannerClient ;
21
22
use Google \Cloud \Spanner \Instance ;
22
23
use Google \Cloud \TestUtils \EventuallyConsistentTestTrait ;
@@ -85,6 +86,15 @@ class spannerTest extends TestCase
85
86
/** @var $lastUpdateData int */
86
87
protected static $ lastUpdateDataTimestamp ;
87
88
89
+ /** @var string $baseConfigId */
90
+ protected static $ baseConfigId ;
91
+
92
+ /** @var string $customInstanceConfigId */
93
+ protected static $ customInstanceConfigId ;
94
+
95
+ /** @var InstanceConfiguration $customInstanceConfig */
96
+ protected static $ customInstanceConfig ;
97
+
88
98
public static function setUpBeforeClass (): void
89
99
{
90
100
self ::checkProjectEnvVars ();
@@ -113,6 +123,9 @@ public static function setUpBeforeClass(): void
113
123
self ::$ defaultLeader = 'us-central1 ' ;
114
124
self ::$ updatedDefaultLeader = 'us-east4 ' ;
115
125
self ::$ multiInstance = $ spanner ->instance (self ::$ multiInstanceId );
126
+ self ::$ baseConfigId = 'nam7 ' ;
127
+ self ::$ customInstanceConfigId = 'custom- ' . time () . rand ();
128
+ self ::$ customInstanceConfig = $ spanner ->instanceConfiguration (self ::$ customInstanceConfigId );
116
129
}
117
130
118
131
public function testCreateInstance ()
@@ -133,6 +146,64 @@ public function testCreateInstanceWithProcessingUnits()
133
146
$ this ->assertStringContainsString ('Created instance test- ' , $ output );
134
147
}
135
148
149
+ public function testCreateInstanceConfig ()
150
+ {
151
+ $ output = $ this ->runFunctionSnippet ('create_instance_config ' , [
152
+ self ::$ customInstanceConfigId , self ::$ baseConfigId
153
+ ]);
154
+
155
+ $ this ->assertStringContainsString (sprintf ('Created instance configuration %s ' , self ::$ customInstanceConfigId ), $ output );
156
+ }
157
+
158
+ /**
159
+ * @depends testCreateInstanceConfig
160
+ */
161
+ public function testUpdateInstanceConfig ()
162
+ {
163
+ $ output = $ this ->runFunctionSnippet ('update_instance_config ' , [
164
+ self ::$ customInstanceConfigId
165
+ ]);
166
+
167
+ $ this ->assertStringContainsString (sprintf ('Updated instance configuration %s ' , self ::$ customInstanceConfigId ), $ output );
168
+ }
169
+
170
+ /**
171
+ * @depends testUpdateInstanceConfig
172
+ */
173
+ public function testDeleteInstanceConfig ()
174
+ {
175
+ $ output = $ this ->runFunctionSnippet ('delete_instance_config ' , [
176
+ self ::$ customInstanceConfigId
177
+ ]);
178
+ $ this ->assertStringContainsString (sprintf ('Deleted instance configuration %s ' , self ::$ customInstanceConfigId ), $ output );
179
+ }
180
+
181
+ /**
182
+ * @depends testUpdateInstanceConfig
183
+ */
184
+ public function testListInstanceConfigOperations ()
185
+ {
186
+ $ output = $ this ->runFunctionSnippet ('list_instance_config_operations ' , [
187
+ self ::$ customInstanceConfigId
188
+ ]);
189
+
190
+ $ this ->assertStringContainsString (
191
+ sprintf (
192
+ 'Instance config operation for %s of type %s has status done. ' ,
193
+ self ::$ customInstanceConfigId ,
194
+ 'type.googleapis.com/google.spanner.admin.instance.v1.CreateInstanceConfigMetadata '
195
+ ),
196
+ $ output );
197
+
198
+ $ this ->assertStringContainsString (
199
+ sprintf (
200
+ 'Instance config operation for %s of type %s has status done. ' ,
201
+ self ::$ customInstanceConfigId ,
202
+ 'type.googleapis.com/google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata '
203
+ ),
204
+ $ output );
205
+ }
206
+
136
207
/**
137
208
* @depends testCreateInstance
138
209
*/
@@ -902,5 +973,8 @@ public static function tearDownAfterClass(): void
902
973
$ database ->drop ();
903
974
self ::$ instance ->delete ();
904
975
self ::$ lowCostInstance ->delete ();
976
+ if (self ::$ customInstanceConfig ->exists ()) {
977
+ self ::$ customInstanceConfig ->delete ();
978
+ }
905
979
}
906
980
}
0 commit comments