diff --git a/commands/serverless.go b/commands/serverless.go index acd15682a..1290f015b 100644 --- a/commands/serverless.go +++ b/commands/serverless.go @@ -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 } diff --git a/commands/serverless_test.go b/commands/serverless_test.go index ee0125b17..168841248 100644 --- a/commands/serverless_test.go +++ b/commands/serverless_test.go @@ -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{} diff --git a/do/serverless.go b/do/serverless.go index 493674fd0..52ca94a20 100644 --- a/do/serverless.go +++ b/do/serverless.go @@ -777,6 +777,9 @@ func (s *serverlessService) GetHostInfo(APIHost string) (ServerlessHostInfo, err } defer resp.Body.Close() body, err := io.ReadAll(resp.Body) + if err != nil { + return ServerlessHostInfo{}, err + } var result ServerlessHostInfo err = json.Unmarshal(body, &result) return result, err diff --git a/internal/apps/builder/cnb.go b/internal/apps/builder/cnb.go index e9bbfcc64..2f334c514 100644 --- a/internal/apps/builder/cnb.go +++ b/internal/apps/builder/cnb.go @@ -231,6 +231,9 @@ func (b *CNBComponentBuilder) buildStaticSiteImage(ctx context.Context) error { return err } assetsPath, err = filepath.Rel(workspacePath, assetsPath) + if err != nil { + return err + } if assetsPath == "." { assetsPath = "./" } else {