|
| 1 | +package zone |
| 2 | + |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/UpCloudLtd/upcloud-cli/internal/commands" |
| 8 | + "github.com/UpCloudLtd/upcloud-cli/internal/config" |
| 9 | + smock "github.com/UpCloudLtd/upcloud-cli/internal/mock" |
| 10 | + "github.com/UpCloudLtd/upcloud-cli/internal/output" |
| 11 | + |
| 12 | + "github.com/UpCloudLtd/upcloud-go-api/v4/upcloud" |
| 13 | + "github.com/gemalto/flume" |
| 14 | + "github.com/jedib0t/go-pretty/v6/text" |
| 15 | + "github.com/stretchr/testify/assert" |
| 16 | +) |
| 17 | + |
| 18 | +func TestZoneListHumanOutput(t *testing.T) { |
| 19 | + text.DisableColors() |
| 20 | + zones := upcloud.Zones{ |
| 21 | + Zones: []upcloud.Zone{ |
| 22 | + {ID: "fi-hel1", Description: "Helsinki #1", Public: 1}, |
| 23 | + {ID: "de-fra1", Description: "Frankfurt #1", Public: 1}, |
| 24 | + }, |
| 25 | + } |
| 26 | + |
| 27 | + mService := smock.Service{} |
| 28 | + mService.On("GetZones").Return(&zones, nil) |
| 29 | + |
| 30 | + conf := config.New() |
| 31 | + // force human output |
| 32 | + conf.Viper().Set(config.KeyOutput, config.ValueOutputHuman) |
| 33 | + |
| 34 | + command := commands.BuildCommand(ListCommand(), nil, conf) |
| 35 | + |
| 36 | + res, err := command.(commands.NoArgumentCommand).ExecuteWithoutArguments(commands.NewExecutor(conf, &mService, flume.New("test"))) |
| 37 | + |
| 38 | + assert.Nil(t, err) |
| 39 | + |
| 40 | + buf := bytes.NewBuffer(nil) |
| 41 | + err = output.Render(buf, conf, res) |
| 42 | + assert.NoError(t, err) |
| 43 | + assert.Regexp(t, "ID\\s+Description\\s+Public", buf.String()) |
| 44 | + assert.Regexp(t, "fi-hel1\\s+Helsinki #1\\s+yes", buf.String()) |
| 45 | +} |
0 commit comments