Skip to content

Commit

Permalink
fix: updates context describe to be consistent with context destroy (a…
Browse files Browse the repository at this point in the history
…ws#143)

* fix: updates context describe to be consistent with context destroy
  • Loading branch information
elliot-smith authored and tneely committed Nov 11, 2021
1 parent 8c8c6be commit 57c2e47
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 8 deletions.
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

0 comments on commit 57c2e47

Please sign in to comment.