We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents d8f5a38 + 7ff77a2 commit 23563d0Copy full SHA for 23563d0
2 files changed
modules/terraform/workspace.go
@@ -1,8 +1,6 @@
1
package terraform
2
3
import (
4
- "fmt"
5
- "regexp"
6
"strings"
7
8
"github.com/gruntwork-io/terratest/modules/testing"
@@ -44,24 +42,13 @@ func WorkspaceSelectOrNewE(t testing.TestingT, options *Options, name string) (s
44
42
func isExistingWorkspace(out string, name string) bool {
45
43
workspaces := strings.Split(out, "\n")
46
for _, ws := range workspaces {
47
- if nameMatchesWorkspace(name, ws) {
+ if strings.HasSuffix(ws, name) {
48
return true
49
}
50
51
return false
52
53
54
-func nameMatchesWorkspace(name string, workspace string) bool {
55
- // Regex for matching workspace should match for strings with optional leading asterisk "*"
56
- // following optional white spaces following the workspace name.
57
- // E.g. for the given name "terratest", following strings will match:
58
- //
59
- // "* terratest"
60
- // " terratest"
61
- match, _ := regexp.MatchString(fmt.Sprintf("^\\*?\\s*%s$", name), workspace)
62
- return match
63
-}
64
-
65
// WorkspaceDelete removes the specified terraform workspace with the given options.
66
// It returns the name of the current workspace AFTER deletion, and the returned error (that can be nil).
67
// If the workspace to delete is the current one, then it tries to switch to the "default" workspace.
modules/terraform/workspace_test.go
@@ -108,31 +108,6 @@ func TestIsExistingWorkspace(t *testing.T) {
108
109
110
111
-func TestNameMatchesWorkspace(t *testing.T) {
112
- t.Parallel()
113
114
- testCases := []struct {
115
- name string
116
- workspace string
117
- expected bool
118
- }{
119
- {"default", " default", true},
120
- {"default", "* default", true},
121
- {"default", "", false},
122
- {"foo", " foobar", false},
123
- {"foo", "* foobar", false},
124
- {"foobar", " foo", false},
125
- {"foobar", "* foo", false},
126
- {"foo", " foo", true},
127
- {"foo", "* foo", true},
128
- }
129
130
- for _, testCase := range testCases {
131
- actual := nameMatchesWorkspace(testCase.name, testCase.workspace)
132
- assert.Equal(t, testCase.expected, actual, "Name: %q, Workspace: %q", testCase.name, testCase.workspace)
133
134
135
136
func TestWorkspaceDeleteE(t *testing.T) {
137
t.Parallel()
138
0 commit comments