Skip to content

Commit e98788b

Browse files
authored
fix: honor create dry-run with explicit types (#326)
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
1 parent 75e987b commit e98788b

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

pkg/cmd/gpucreate/gpucreate.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ func NewCmdGPUCreate(t *terminal.Terminal, gpuCreateStore GPUCreateStore) *cobra
179179
return breverrors.WrapAndTrace(err)
180180
}
181181

182+
if dryRun {
183+
return runDryRun(t, gpuCreateStore, types, &filters)
184+
}
185+
182186
// If no types provided, use search filters (or defaults) to find suitable GPUs
183187
if len(types) == 0 {
184-
if dryRun {
185-
return runDryRun(t, gpuCreateStore, &filters)
186-
}
187-
188188
types, err = getFilteredInstanceTypes(gpuCreateStore, &filters)
189189
if err != nil {
190190
return breverrors.WrapAndTrace(err)
@@ -369,7 +369,12 @@ func getFilteredInstanceTypes(s GPUCreateStore, filters *searchFilterFlags) ([]I
369369
}
370370

371371
// runDryRun shows the instance types that would be used without creating anything
372-
func runDryRun(t *terminal.Terminal, s GPUCreateStore, filters *searchFilterFlags) error {
372+
func runDryRun(t *terminal.Terminal, s GPUCreateStore, specs []InstanceSpec, filters *searchFilterFlags) error {
373+
if len(specs) > 0 {
374+
t.Print(formatInstanceSpecs(specs))
375+
return nil
376+
}
377+
373378
filtered, _, err := searchInstances(s, filters)
374379
if err != nil {
375380
return breverrors.WrapAndTrace(err)

pkg/cmd/gpucreate/gpucreate_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/brevdev/brev-cli/pkg/cmd/gpusearch"
88
"github.com/brevdev/brev-cli/pkg/entity"
99
"github.com/brevdev/brev-cli/pkg/store"
10+
"github.com/brevdev/brev-cli/pkg/terminal"
1011
"github.com/stretchr/testify/assert"
1112
)
1213

@@ -300,6 +301,18 @@ func TestMockGPUCreateStoreTypeSpecificError(t *testing.T) {
300301
assert.NotNil(t, ws)
301302
}
302303

304+
func TestCreateDryRunWithExplicitTypesDoesNotProvision(t *testing.T) {
305+
mock := NewMockGPUCreateStore()
306+
term := terminal.New()
307+
308+
cmd := NewCmdGPUCreate(term, mock)
309+
cmd.SetArgs([]string{"dry-run-test", "--type", "g5.xlarge", "--dry-run"})
310+
311+
err := cmd.Execute()
312+
assert.NoError(t, err)
313+
assert.Empty(t, mock.CreatedWorkspaces)
314+
}
315+
303316
func TestGetFilteredInstanceTypesDefaults(t *testing.T) {
304317
mock := NewMockGPUCreateStore()
305318

0 commit comments

Comments
 (0)