Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: put nonprod environments before prod when listing #721

Merged
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 CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This document describes how to set up a development environment and submit your

From the repository root run:

`git remote add upstream git@github.com:aws/amazon-ecs-cli`
`git remote add upstream git@github.com:aws/amazon-ecs-cli-v2`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄 thanks for fixing this!


`git fetch upstream`

Expand Down
4 changes: 4 additions & 0 deletions internal/pkg/store/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package store
import (
"encoding/json"
"fmt"
"sort"

"github.com/aws/amazon-ecs-cli-v2/internal/pkg/archer"
"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -92,6 +93,9 @@ func (s *Store) ListEnvironments(projectName string) ([]*archer.Environment, err

environments = append(environments, &env)
}
// non-prod env before prod env. sort by alphabetically if same
sort.SliceStable(environments, func(i, j int) bool { return environments[i].Name < environments[i].Name })
sort.SliceStable(environments, func(i, j int) bool { return !environments[i].Prod })
return environments, nil
}

Expand Down
12 changes: 6 additions & 6 deletions internal/pkg/store/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (
)

func TestStore_ListEnvironments(t *testing.T) {
testEnvironment := archer.Environment{Name: "test", AccountID: "12345", Project: "chicken", Region: "us-west-2s"}
testEnvironment := archer.Environment{Name: "test", AccountID: "12345", Project: "chicken", Region: "us-west-2s", Prod: false}
testEnvironmentString, err := marshal(testEnvironment)
testEnvironmentPath := fmt.Sprintf(fmtEnvParamPath, testEnvironment.Project, testEnvironment.Name)
require.NoError(t, err, "Marshal environment should not fail")

prodEnvironment := archer.Environment{Name: "prod", AccountID: "12345", Project: "chicken", Region: "us-west-2s"}
prodEnvironment := archer.Environment{Name: "prod", AccountID: "12345", Project: "chicken", Region: "us-west-2s", Prod: true}
prodEnvironmentString, err := marshal(prodEnvironment)
prodEnvironmentPath := fmt.Sprintf(fmtEnvParamPath, prodEnvironment.Project, prodEnvironment.Name)
require.NoError(t, err, "Marshal environment should not fail")
Expand All @@ -42,12 +42,12 @@ func TestStore_ListEnvironments(t *testing.T) {
return &ssm.GetParametersByPathOutput{
Parameters: []*ssm.Parameter{
{
Name: aws.String(testEnvironmentPath),
Value: aws.String(testEnvironmentString),
Name: aws.String(prodEnvironmentPath), // <- return prod before test on purpose to test sorting by Prod
Value: aws.String(prodEnvironmentString),
},
{
Name: aws.String(prodEnvironmentPath),
Value: aws.String(prodEnvironmentString),
Name: aws.String(testEnvironmentPath),
Value: aws.String(testEnvironmentString),
},
},
}, nil
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/store/store_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func Test_SSM_Project_Integration(t *testing.T) {
func Test_SSM_Environment_Integration(t *testing.T) {
s, _ := store.New()
projectToCreate := archer.Project{Name: randStringBytes(10), Version: "1.0"}
testEnvironment := archer.Environment{Name: "test", Project: projectToCreate.Name, Region: "us-west-2", AccountID: " 1234"}
prodEnvironment := archer.Environment{Name: "prod", Project: projectToCreate.Name, Region: "us-west-2", AccountID: " 1234"}
testEnvironment := archer.Environment{Name: "test", Project: projectToCreate.Name, Region: "us-west-2", AccountID: " 1234", Prod: false}
prodEnvironment := archer.Environment{Name: "prod", Project: projectToCreate.Name, Region: "us-west-2", AccountID: " 1234", Prod: true}

t.Run("Create, Get and List Environments", func(t *testing.T) {
// Create our first project
Expand Down