Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Sorts credentials alphabetically before prompting
Browse files Browse the repository at this point in the history
Signed-off-by: Urvashi Reddy <[email protected]>
  • Loading branch information
Ryan Moran authored and Urvashi Reddy committed Feb 8, 2019
1 parent 38f033f commit 16daf8a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 8 additions & 0 deletions cmd/duffle/credential_generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"io/ioutil"
"path/filepath"
"sort"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -114,7 +115,14 @@ func genCredentialSet(name string, creds map[string]bundle.Location, fn credenti
return cs, fmt.Errorf("credentialset name '%s' cannot contain the following characters: './\\'", name)
}

var credentialNames []string
for name := range creds {
credentialNames = append(credentialNames, name)
}

sort.Strings(credentialNames)

for _, name := range credentialNames {
c, err := fn(name)
if err != nil {
return cs, err
Expand Down
13 changes: 10 additions & 3 deletions cmd/duffle/credential_generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,28 @@ func TestGenCredentialSet(t *testing.T) {
EnvironmentVariable: "SECOND_VAR",
Path: "/second/path",
},
"third": {
Path: "/third/path",
},
}
is := assert.New(t)
creds, err := genCredentialSet(name, credlocs, genEmptyCredentials)
is.NoError(err)
is.Equal(creds.Name, name)
is.Len(creds.Credentials, 2)
is.Len(creds.Credentials, 3)

found := map[string]bool{"first": false, "second": false}
found := map[string]bool{"first": false, "second": false, "third": false}

var assignmentOrder []string
for _, cred := range creds.Credentials {
assignmentOrder = append(assignmentOrder, cred.Name)
found[cred.Name] = true
is.Equal(cred.Source.Value, "EMPTY")
}

is.Len(found, 2)
is.Equal([]string{"first", "second", "third"}, assignmentOrder)

is.Len(found, 3)
for k, v := range found {
is.True(v, "%q not found", k)
}
Expand Down

0 comments on commit 16daf8a

Please sign in to comment.