Skip to content

Commit 521624e

Browse files
committed
chore: deflake tests
1 parent 3a978a3 commit 521624e

4 files changed

Lines changed: 8 additions & 9 deletions

File tree

cmd/cloudx/client/command_helper.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type (
4545
projectID, workspaceID uuid.UUID
4646
configLocation string
4747
noConfirm, isQuiet bool
48+
workspaceFromConfig bool
4849
VerboseErrWriter io.Writer
4950
Stdin *bufio.Reader
5051
openBrowserHook func(string) error
@@ -231,6 +232,7 @@ func (h *CommandHelper) determineWorkspaceID(ctx context.Context, config *Config
231232
workspace = ws
232233
} else if config.SelectedWorkspace != uuid.Nil {
233234
h.workspaceID = config.SelectedWorkspace
235+
h.workspaceFromConfig = true
234236
return nil
235237
}
236238
workspace = strings.TrimSpace(workspace)
@@ -261,9 +263,11 @@ func (h *CommandHelper) determineProjectID(ctx context.Context, config *Config)
261263
if h.projectOverride != nil {
262264
return fmt.Errorf("project API key is set but project flag is also set, please remove one")
263265
}
264-
if h.workspaceID != uuid.Nil {
266+
if h.workspaceID != uuid.Nil && !h.workspaceFromConfig {
265267
return fmt.Errorf("project API key is set but workspace is also set, please remove one")
266268
}
269+
// Clear workspace from config since project API key takes precedence.
270+
h.workspaceID = uuid.Nil
267271
pjs, err := h.ListProjects(ctx, nil)
268272
if err != nil {
269273
return err

cmd/cloudx/client/command_helper_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ func TestCommandHelper(t *testing.T) {
372372
assert.Equal(t, tc.project.Id, actual.Id)
373373
assertValidProject(t, tc.project)
374374

375-
actual, err = authenticated.GetProject(ctx, tc.project.Slug[0:4], tc.project.WorkspaceId.Get())
375+
actual, err = authenticated.GetProject(ctx, tc.project.Slug[:len(tc.project.Slug)-1], tc.project.WorkspaceId.Get())
376376
require.NoError(t, err)
377377
assert.Equal(t, tc.project.Id, actual.Id)
378378
})

cmd/cloudx/relationtuples/relationtuples_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func TestCRUD(t *testing.T) {
165165
func createLegacyNamespace(t *testing.T, project, rawNamespace string) {
166166
t.Helper()
167167
_, _, err := defaultCmd.Exec(nil, "patch", "permission-config", "--project", project,
168-
"--add", `/namespaces/-=`+rawNamespace)
168+
"--replace", `/namespaces=[`+rawNamespace+`]`)
169169
if err != nil {
170170
t.Fatal(err)
171171
}

cmd/root.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"context"
88
"fmt"
99
"os"
10-
"sync"
1110

1211
"github.com/pkg/errors"
1312
"github.com/spf13/cobra"
@@ -19,8 +18,6 @@ import (
1918
"github.com/ory/x/cmdx"
2019
)
2120

22-
var commandTemplatingOnce sync.Once
23-
2421
func NewRootCmd() *cobra.Command {
2522
c := &cobra.Command{
2623
Use: "ory",
@@ -51,9 +48,7 @@ func NewRootCmd() *cobra.Command {
5148
cloudx.NewIsCmd(),
5249
versionCmd,
5350
)
54-
commandTemplatingOnce.Do(func() {
55-
cmdx.EnableUsageTemplating(c)
56-
})
51+
cmdx.EnableUsageTemplating(c)
5752

5853
return c
5954
}

0 commit comments

Comments
 (0)