From 6014d3870604711d5942e30979637fdd3c6270eb Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 4 Apr 2023 13:22:52 -0700 Subject: [PATCH] feat: add flags to CloudFunction delete function --- src/TestUtils/GcloudWrapper/CloudFunction.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/TestUtils/GcloudWrapper/CloudFunction.php b/src/TestUtils/GcloudWrapper/CloudFunction.php index 9674939..a34181c 100644 --- a/src/TestUtils/GcloudWrapper/CloudFunction.php +++ b/src/TestUtils/GcloudWrapper/CloudFunction.php @@ -181,20 +181,29 @@ public function deploy(array $flags = [], string $trigger = self::DEFAULT_TRIGGE /** * Delete the deployed function. * + * @param array $flags optional flags to inject into the deploy command * @param int $retries optional The number of retries upon failure * * @return bool true if the function is succesfully deleted, otherwise false */ - public function delete($retries = 3) + public function delete(array $flags = [], $retries = 3) { if (!$this->deployed) { $this->errorLog('Nothing to delete: function not deployed during test'); return false; } - + + $flattenedFlags = []; + foreach ($flags as $name => $value) { + $flattenedFlags[] = empty($value) ? $name : "$name=$value"; + } + $args = [ + 'delete', + $this->functionName + ] + $flattenedFlags; try { - $cmd = $this->gcloudCommand(['delete', $this->functionName]); + $cmd = $this->gcloudCommand($args); $this->runWithRetry($cmd, $retries); $this->deployed = false; } catch (ProcessFailedException $e) {