Skip to content

Commit e4a5df9

Browse files
authored
image list show image type remove id (#24)
The header shows IMAGE TYPE (not ID) The rows contain image_type values (ubuntu-22.04-cuda-12.0, pytorch-2.0) from the mock server — not UUID-style IDs
1 parent 2fbf4a0 commit e4a5df9

2 files changed

Lines changed: 49 additions & 3 deletions

File tree

internal/verda-cli/cmd/images/images.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,16 @@ func runImages(cmd *cobra.Command, f cmdutil.Factory, ioStreams cmdutil.IOStream
106106
}
107107

108108
_, _ = fmt.Fprintf(ioStreams.Out, " %d image(s) found\n\n", len(images))
109-
_, _ = fmt.Fprintf(ioStreams.Out, " %-38s %-45s %-12s %s\n", "ID", "NAME", "CATEGORY", "DETAILS")
110-
_, _ = fmt.Fprintf(ioStreams.Out, " %-38s %-45s %-12s %s\n", "--", "----", "--------", "-------")
109+
_, _ = fmt.Fprintf(ioStreams.Out, " %-38s %-45s %-12s %s\n", "IMAGE TYPE", "NAME", "CATEGORY", "DETAILS")
110+
_, _ = fmt.Fprintf(ioStreams.Out, " %-38s %-45s %-12s %s\n", "----------", "----", "--------", "-------")
111111
for i := range images {
112112
details := strings.Join(images[i].Details, ", ")
113113
def := ""
114114
if images[i].IsDefault {
115115
def = " *"
116116
}
117117
_, _ = fmt.Fprintf(ioStreams.Out, " %-38s %-45s %-12s %s%s\n",
118-
images[i].ID, images[i].Name, images[i].Category, details, def)
118+
images[i].ImageType, images[i].Name, images[i].Category, details, def)
119119
}
120120
return nil
121121
}

internal/verda-cli/cmd/images/images_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
package images
22

33
import (
4+
"bytes"
5+
"strings"
46
"testing"
57

8+
"github.com/spf13/cobra"
69
"github.com/verda-cloud/verdacloud-sdk-go/pkg/verda"
10+
"github.com/verda-cloud/verdacloud-sdk-go/pkg/verda/testutil"
11+
12+
cmdutil "github/verda-cloud/verda-cli/internal/verda-cli/cmd/util"
713
)
814

915
func TestFilterExcludesClusterImages(t *testing.T) {
@@ -67,3 +73,43 @@ func TestFilterEmptyList(t *testing.T) {
6773
t.Fatalf("expected 0 images, got %d", len(filtered))
6874
}
6975
}
76+
77+
func TestOutputShowsImageTypeNotID(t *testing.T) {
78+
t.Parallel()
79+
80+
mockServer := testutil.NewMockServer()
81+
defer mockServer.Close()
82+
83+
client := verda.NewTestClient(mockServer)
84+
85+
var buf bytes.Buffer
86+
ioStreams := cmdutil.IOStreams{Out: &buf, ErrOut: &buf}
87+
f := cmdutil.NewTestFactory(nil)
88+
f.ClientOverride = client
89+
90+
root := &cobra.Command{Use: "verda", SilenceUsage: true, SilenceErrors: true}
91+
root.AddCommand(NewCmdImages(f, ioStreams))
92+
root.SetArgs([]string{"images"})
93+
94+
if err := root.Execute(); err != nil {
95+
t.Fatalf("unexpected error: %v", err)
96+
}
97+
98+
out := buf.String()
99+
100+
// Header should say IMAGE TYPE, not ID.
101+
if !strings.Contains(out, "IMAGE TYPE") {
102+
t.Errorf("expected header to contain IMAGE TYPE, got:\n%s", out)
103+
}
104+
if strings.Contains(out, " ID ") {
105+
t.Errorf("header should not contain ID column, got:\n%s", out)
106+
}
107+
108+
// Rows should contain image_type values from mock server, not UUIDs.
109+
if !strings.Contains(out, "ubuntu-22.04-cuda-12.0") {
110+
t.Errorf("expected image_type 'ubuntu-22.04-cuda-12.0' in output, got:\n%s", out)
111+
}
112+
if !strings.Contains(out, "pytorch-2.0") {
113+
t.Errorf("expected image_type 'pytorch-2.0' in output, got:\n%s", out)
114+
}
115+
}

0 commit comments

Comments
 (0)