Skip to content

Commit

Permalink
commands: fix RunServerlessStatus displaying credentials (#1439)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew Starr-Bochicchio <[email protected]>
  • Loading branch information
alexandear and andrewsomething authored Oct 12, 2023
1 parent d40bd09 commit 3ccc688
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
10 changes: 5 additions & 5 deletions commands/serverless.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,17 +392,17 @@ func RunServerlessStatus(c *CmdConfig) error {
credentials, _ := c.Doit.GetBool(c.NS, "credentials")
if credentials {
type showCreds struct {
Auth string `json:auth`
APIHost string `json:apihost`
Namespace string `json:namespace`
Path string `json:path`
Auth string `json:"auth"`
APIHost string `json:"apihost"`
Namespace string `json:"namespace"`
Path string `json:"path"`
}
toShow := showCreds{Auth: auth, APIHost: creds.APIHost, Namespace: creds.Namespace, Path: sls.CredentialsPath()}
credsOutput, err := json.MarshalIndent(toShow, "", " ")
if err != nil {
return err
}
fmt.Println(string(credsOutput))
fmt.Fprintln(c.Out, string(credsOutput))
return nil
}

Expand Down
27 changes: 27 additions & 0 deletions commands/serverless_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,33 @@ func TestServerlessStatusWhenConnected(t *testing.T) {
})
}

func TestServerlessStatusDisplayCredentials(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
buf := &bytes.Buffer{}
config.Out = buf
config.Doit.Set(config.NS, "credentials", true)

tm.serverless.EXPECT().CheckServerlessStatus().MinTimes(1).Return(nil)
tm.serverless.EXPECT().ReadCredentials().Return(do.ServerlessCredentials{
APIHost: "https://api.example.com",
Namespace: "hello",
Credentials: map[string]map[string]do.ServerlessCredential{
"https://api.example.com": {
"hello": do.ServerlessCredential{
Auth: "here-are-some-credentials",
},
},
},
}, nil)
tm.serverless.EXPECT().GetNamespaceFromCluster("https://api.example.com", "here-are-some-credentials").Return("hello", nil)
tm.serverless.EXPECT().CredentialsPath().Return("/path")

err := RunServerlessStatus(config)
require.NoError(t, err)
assert.JSONEq(t, `{"apihost":"https://api.example.com","auth":"here-are-some-credentials","namespace":"hello","path":"/path"}`, buf.String())
})
}

func TestServerlessStatusWithLanguages(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
buf := &bytes.Buffer{}
Expand Down

0 comments on commit 3ccc688

Please sign in to comment.