Skip to content

Commit

Permalink
Fix image single result test not being able to run individually. (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored Jan 11, 2023
1 parent 77021d4 commit 0411229
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
3 changes: 3 additions & 0 deletions cmd/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/metal-stack/metalctl/cmd/completion"
"github.com/spf13/afero"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
Expand Down Expand Up @@ -71,6 +72,8 @@ func (c *test[R]) testCmd(t *testing.T) {
t.Run(fmt.Sprintf("%v", format.Args()), func(t *testing.T) {
mock, out, config := c.newMockConfig(t)

viper.Reset()

cmd := newRootCmd(config)
os.Args = append([]string{binaryName}, c.cmd(c.want)...)
os.Args = append(os.Args, format.Args()...)
Expand Down
14 changes: 7 additions & 7 deletions cmd/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func Test_ImageCmd_MultiResult(t *testing.T) {
image2,
},
wantTable: pointer.Pointer(`
ID NAME DESCRIPTION FEATURES EXPIRATION STATUS USEDBY
debian debian-name debian-description machine 3d supported 1
ID NAME DESCRIPTION FEATURES EXPIRATION STATUS USEDBY
debian debian-name debian-description machine 3d supported 1
ubuntu ubuntu-name ubuntu-description machine 3d supported 1
`),
wantWideTable: pointer.Pointer(`
Expand Down Expand Up @@ -129,12 +129,12 @@ func Test_ImageCmd_SingleResult(t *testing.T) {
},
want: image1,
wantTable: pointer.Pointer(`
ID NAME DESCRIPTION FEATURES EXPIRATION STATUS USEDBY
debian debian-name debian-description machine 3d supported 1
ID NAME DESCRIPTION FEATURES EXPIRATION STATUS USEDBY
debian debian-name debian-description machine 3d supported
`),
wantWideTable: pointer.Pointer(`
ID NAME DESCRIPTION FEATURES EXPIRATION STATUS USEDBY
debian debian-name debian-description machine 3d supported abc-def
ID NAME DESCRIPTION FEATURES EXPIRATION STATUS USEDBY
debian debian-name debian-description machine 3d supported
`),
template: pointer.Pointer("{{ .id }} {{ .name }}"),
wantTemplate: pointer.Pointer(`
Expand All @@ -143,7 +143,7 @@ debian debian-name
wantMarkdown: pointer.Pointer(`
| ID | NAME | DESCRIPTION | FEATURES | EXPIRATION | STATUS | USEDBY |
|--------|-------------|--------------------|----------|------------|-----------|--------|
| debian | debian-name | debian-description | machine | 3d | supported | 1 |
| debian | debian-name | debian-description | machine | 3d | supported | |
`),
},
{
Expand Down
8 changes: 3 additions & 5 deletions cmd/tableprinters/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ import (

func (t *TablePrinter) ImageTable(data []*models.V1ImageResponse, wide bool) ([]string, [][]string, error) {
var (
rows [][]string
rows [][]string
header = []string{"ID", "Name", "Description", "Features", "Expiration", "Status", "UsedBy"}
showUsage = viper.GetBool("show-usage")
)

showUsage := viper.GetBool("show-usage")

header := []string{"ID", "Name", "Description", "Features", "Expiration", "Status", "UsedBy"}

for _, image := range data {
id := pointer.SafeDeref(image.ID)
features := strings.Join(image.Features, ",")
Expand Down

0 comments on commit 0411229

Please sign in to comment.