-
Notifications
You must be signed in to change notification settings - Fork 3
test(cmd): fix preRun tests to call preRun directly #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ import ( | |
| "testing" | ||
|
|
||
| "github.com/kortex-hub/kortex-cli/pkg/instances" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func TestWorkspaceRemoveCmd(t *testing.T) { | ||
|
|
@@ -43,6 +44,35 @@ func TestWorkspaceRemoveCmd(t *testing.T) { | |
| func TestWorkspaceRemoveCmd_PreRun(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| t.Run("extracts id from args and creates manager", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| storageDir := t.TempDir() | ||
|
|
||
| c := &workspaceRemoveCmd{} | ||
| cmd := &cobra.Command{} | ||
| cmd.Flags().String("storage", storageDir, "test storage flag") | ||
|
|
||
| args := []string{"test-workspace-id"} | ||
|
|
||
| err := c.preRun(cmd, args) | ||
|
Comment on lines
+50
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exercise storage-path normalization with a relative path. This subtest passes an already-absolute 🤖 Prompt for AI Agents |
||
| if err != nil { | ||
| t.Fatalf("preRun() failed: %v", err) | ||
| } | ||
|
|
||
| if c.manager == nil { | ||
| t.Error("Expected manager to be created") | ||
| } | ||
|
|
||
| if c.id != "test-workspace-id" { | ||
| t.Errorf("Expected id to be 'test-workspace-id', got %s", c.id) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| func TestWorkspaceRemoveCmd_E2E(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| t.Run("requires ID argument", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
|
|
@@ -77,45 +107,6 @@ func TestWorkspaceRemoveCmd_PreRun(t *testing.T) { | |
| } | ||
| }) | ||
|
|
||
| t.Run("creates manager from storage flag", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| storageDir := t.TempDir() | ||
| sourcesDir := t.TempDir() | ||
|
|
||
| // Create a workspace first | ||
| manager, err := instances.NewManager(storageDir) | ||
| if err != nil { | ||
| t.Fatalf("Failed to create manager: %v", err) | ||
| } | ||
|
|
||
| instance, err := instances.NewInstance(instances.NewInstanceParams{ | ||
| SourceDir: sourcesDir, | ||
| ConfigDir: filepath.Join(sourcesDir, ".kortex"), | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("Failed to create instance: %v", err) | ||
| } | ||
|
|
||
| addedInstance, err := manager.Add(instance) | ||
| if err != nil { | ||
| t.Fatalf("Failed to add instance: %v", err) | ||
| } | ||
|
|
||
| // Now remove it | ||
| rootCmd := NewRootCmd() | ||
| rootCmd.SetArgs([]string{"workspace", "remove", addedInstance.GetID(), "--storage", storageDir}) | ||
|
|
||
| err = rootCmd.Execute() | ||
| if err != nil { | ||
| t.Fatalf("Expected no error, got %v", err) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| func TestWorkspaceRemoveCmd_E2E(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| t.Run("removes existing workspace by ID", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the test examples include parent-level
t.Parallel().Both new examples show
t.Parallel()only inside the subtest, but the repo rule requires it as the first line of each test function unlesst.Setenv()is involved. Since this file is the canonical guidance, the examples and bullet list should show that explicitly to avoid teaching the wrong pattern.As per coding guidelines, "All Go test functions must call
t.Parallel()as the first line of the test function, except for tests usingt.Setenv()which cannot uset.Parallel()on the parent test function due to Go framework restrictions".🤖 Prompt for AI Agents