Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ require (
github.com/spf13/viper v1.21.0
github.com/stretchr/testify v1.11.1
github.com/superfly/client-signals/go v0.4.4
github.com/superfly/fly-go v0.9.2
github.com/superfly/fly-go v0.9.3
github.com/superfly/graphql v0.2.6
github.com/superfly/lfsc-go v0.1.1
github.com/superfly/macaroon v0.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,8 @@ github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/superfly/client-signals/go v0.4.4 h1:btAouksYdwOkVCIqI/JI09bt17A6iIVuwVJGWndfmc8=
github.com/superfly/client-signals/go v0.4.4/go.mod h1:FTpkC1/boj2Lez8w98k9Zs9ihtvz8a1VeGXDtaq7asY=
github.com/superfly/fly-go v0.9.2 h1:eGleZZi3FeRt1CcG/qVbWnKoh+AbF9ut7dSr0AuiUxs=
github.com/superfly/fly-go v0.9.2/go.mod h1:TOdS0mlGgPUvOlISm2SyaJPt3nWfCQwO8lD45DBvPbE=
github.com/superfly/fly-go v0.9.3 h1:+ndPRF0q4m7UanKT0SA8f89XLtkKyo3OurRfbSEEW7g=
github.com/superfly/fly-go v0.9.3/go.mod h1:XwR9oVL8t2N/0gVWkgA+SIw46hWIt79I+bLP2WXDmFI=
github.com/superfly/graphql v0.2.6 h1:zppbodNerWecoXEdjkhrqaNaSjGqobhXNlViHFuZzb4=
github.com/superfly/graphql v0.2.6/go.mod h1:CVfDl31srm8HnJ9udwLu6hFNUW/P6GUM2dKcG1YQ8jc=
github.com/superfly/lfsc-go v0.1.1 h1:dGjLgt81D09cG+aR9lJZIdmonjZSR5zYCi7s54+ZU2Q=
Expand Down
3 changes: 2 additions & 1 deletion internal/command/platform/regions.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ func runRegions(ctx context.Context) error {
rows = append(rows, []string{
region.Name,
region.Code,
lo.Ternary(region.MPGAvailable, io.ColorScheme().SuccessIcon(), ""),
})
}
}

return render.Table(out, "", rows, "Name", "Code")
return render.Table(out, "", rows, "Name", "Code", "MPG")
}
89 changes: 89 additions & 0 deletions internal/command/platform/regions_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package platform

import (
"bytes"
"context"
"encoding/json"
"strings"
"testing"

"github.com/stretchr/testify/require"
fly "github.com/superfly/fly-go"
"github.com/superfly/fly-go/flaps"
"github.com/superfly/flyctl/internal/config"
"github.com/superfly/flyctl/internal/flapsutil"
"github.com/superfly/flyctl/internal/mock"
"github.com/superfly/flyctl/iostreams"
)

func regionsTestContext(jsonOutput bool) (context.Context, *bytes.Buffer) {
ios, _, out, _ := iostreams.Test()

ctx := context.Background()
ctx = iostreams.NewContext(ctx, ios)
ctx = config.NewContext(ctx, &config.Config{JSONOutput: jsonOutput})
ctx = flapsutil.NewContextWithClient(ctx, &mock.FlapsClient{
GetRegionsFunc: func(ctx context.Context) (*flaps.RegionData, error) {
return &flaps.RegionData{
Regions: []fly.Region{
{
Code: "iad",
Name: "Ashburn, Virginia (US)",
GeoRegion: "north_america",
MPGAvailable: true,
},
{
Code: "arn",
Name: "Stockholm, Sweden",
GeoRegion: "europe",
},
{
Code: "atl",
Name: "Atlanta, Georgia (US)",
GeoRegion: "north_america",
Deprecated: true,
},
},
}, nil
},
})

return ctx, out
}

func TestRunRegionsTable(t *testing.T) {
ctx, out := regionsTestContext(false)

require.NoError(t, runRegions(ctx))

output := out.String()
require.Contains(t, output, "MPG")
require.NotContains(t, output, "Atlanta")

for _, line := range strings.Split(output, "\n") {
switch {
case strings.Contains(line, "iad"):
require.Contains(t, line, "✓")
case strings.Contains(line, "arn"):
require.NotContains(t, line, "✓")
}
}
}

func TestRunRegionsJSON(t *testing.T) {
ctx, out := regionsTestContext(true)

require.NoError(t, runRegions(ctx))

var regions []map[string]any
require.NoError(t, json.Unmarshal(out.Bytes(), &regions))
require.Len(t, regions, 2)

byCode := map[string]map[string]any{}
for _, r := range regions {
byCode[r["code"].(string)] = r
}

require.Equal(t, true, byCode["iad"]["mpg_available"])
require.Equal(t, false, byCode["arn"]["mpg_available"])
}