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

fix: updates context describe to be consistent with context destroy #143

Merged
merged 3 commits into from
Nov 5, 2021
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
24 changes: 17 additions & 7 deletions packages/cli/internal/pkg/cli/context_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package cli

import (
"fmt"

"github.com/aws/amazon-genomics-cli/internal/pkg/cli/clierror"
"github.com/aws/amazon-genomics-cli/internal/pkg/cli/context"
"github.com/aws/amazon-genomics-cli/internal/pkg/cli/format"
Expand All @@ -28,7 +30,17 @@ func newDescribeContextOpts(vars describeContextVars) (*describeContextOpts, err
}, nil
}

func (o *describeContextOpts) Validate() error {
func (o *describeContextOpts) Validate(args []string) error {
if len(args) == 0 && o.ContextName == "" {
return fmt.Errorf("a context must be provided")
} else if len(args) == 1 && o.ContextName != "" {
return fmt.Errorf("either the '-c' flag or a context must be provided, but not both")
}

if len(args) == 1 {
o.ContextName = args[0]
}

return nil
}

Expand Down Expand Up @@ -69,19 +81,16 @@ func BuildContextDescribeCommand() *cobra.Command {
` + DescribeOutput(types.Context{}),
Example: `
/code agc context describe myCtx`,
Args: cobra.ExactArgs(1),
Args: cobra.ArbitraryArgs,
RunE: runCmdE(func(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
vars.ContextName = args[0]
}
opts, err := newDescribeContextOpts(vars)
if err != nil {
return err
}
log.Info().Msgf("Describing context '%s'", opts.ContextName)
if err := opts.Validate(); err != nil {
if err := opts.Validate(args); err != nil {
return err
}
log.Info().Msgf("Describing context '%s'", opts.ContextName)
ctx, err := opts.Execute()
if err != nil {
return clierror.New("context describe", vars, err)
Expand All @@ -90,5 +99,6 @@ func BuildContextDescribeCommand() *cobra.Command {
return nil
}),
}
cmd.Flags().StringVarP(&vars.ContextName, contextFlag, contextFlagShort, "", deployContextDescription)
return cmd
}
49 changes: 49 additions & 0 deletions packages/cli/internal/pkg/cli/context_describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,52 @@ func TestDescribeContextOpts_Execute(t *testing.T) {
})
}
}

func TestDescribeContextOpts_Validate(t *testing.T) {
testCases := map[string]struct {
contextName string
expectedContext string
contextNameArgs []string
expectedErr error
}{
"valid single context name": {
contextName: testContextName1,
expectedContext: testContextName1,
expectedErr: nil,
},
"valid single context arg": {
contextNameArgs: []string{testContextName2},
expectedContext: testContextName2,
expectedErr: nil,
},
"both context and context arg throws error": {
contextName: testContextName1,
contextNameArgs: []string{testContextName2},
expectedErr: fmt.Errorf("either the '-c' flag or a context must be provided, but not both"),
},
"no contexts supplied": {
expectedErr: fmt.Errorf("a context must be provided"),
},
}

for name, tt := range testCases {
t.Run(name, func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockCtxManager := contextmocks.NewMockContextManager(ctrl)
opts := &describeContextOpts{
ctxManager: mockCtxManager,
describeContextVars: describeContextVars{tt.contextName},
}

err := opts.Validate(tt.contextNameArgs)

if tt.expectedErr != nil {
assert.EqualError(t, err, tt.expectedErr.Error())
} else {
require.NoError(t, err)
assert.Equal(t, tt.expectedContext, opts.ContextName)
}
})
}
}
2 changes: 1 addition & 1 deletion site/content/en/docs/Tutorials/walkthrough.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ agc context deploy --all
Contexts have read-write access to a context specific prefix in the S3 bucket Amazon Genomics CLI creates during account activation. You can check this for the `myContext` context with:

```shell
agc context describe -c myContext
agc context describe myContext
```

You should see something like:
Expand Down