-
Notifications
You must be signed in to change notification settings - Fork 41
feat!: config management and error handling #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
bd49464
feat: handler error when load config cli
mabdh 92e6d5b
feat(cli): add server init config
mabdh 61a0156
fix: lint
mabdh eaa3776
feat(proto): add support proton commit in makefile
mabdh 760f076
fix: missing header in create user cli
mabdh 0531f0b
fix: refactor cmd utils
mabdh 0bb6b7d
feat(cmd): add test for error handling
mabdh 415cff3
fix(cmd): default server config
mabdh 4734057
fix(cmd): make cmd.Config as a source of truth
mabdh e343fa7
refactor(config): rename serverConfigfileFromFlag
mabdh a30bfaa
fix: move sample server config and update
mabdh 84ccf2c
refactor: rename .shield.yaml to config.yaml
mabdh 0ef99b4
fix: .gitignore
mabdh 40c9b97
fix: add missing config.yaml
mabdh 9076555
docs: add docs in pkg/file
mabdh 619900f
docs: add more docs in pkg
mabdh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| package cmd_test | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "errors" | ||
| "testing" | ||
|
|
||
| "github.com/MakeNowJust/heredoc" | ||
| "github.com/odpf/shield/cmd" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| var expectedActionUsageHelp = heredoc.Doc(` | ||
|
|
||
| USAGE | ||
| shield action [flags] | ||
|
|
||
| CORE COMMANDS | ||
| create Create an action | ||
| edit Edit an action | ||
| list List all actions | ||
| view View an action | ||
|
|
||
| FLAGS | ||
| -h, --host string Shield API service to connect to | ||
|
|
||
| INHERITED FLAGS | ||
| --help Show help for command | ||
|
|
||
| EXAMPLES | ||
| $ shield action create | ||
| $ shield action edit | ||
| $ shield action view | ||
| $ shield action list | ||
|
|
||
| `) | ||
|
|
||
| func TestClientAction(t *testing.T) { | ||
| t.Run("without config file", func(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| cliConfig *cmd.Config | ||
| subCommands []string | ||
| want string | ||
| err error | ||
| }{ | ||
| { | ||
| name: "`action` only should show usage help", | ||
| want: expectedActionUsageHelp, | ||
| err: nil, | ||
| }, | ||
| { | ||
| name: "`action` list only should throw error host not found", | ||
| want: "", | ||
| subCommands: []string{"list"}, | ||
| err: cmd.ErrClientConfigHostNotFound, | ||
| }, | ||
| { | ||
| name: "`action` list with host flag should pass", | ||
| want: "", | ||
| subCommands: []string{"list", "-h", "test"}, | ||
| err: context.DeadlineExceeded, | ||
| }, | ||
| { | ||
| name: "`action` create only should throw error host not found", | ||
| want: "", | ||
| subCommands: []string{"create"}, | ||
| err: cmd.ErrClientConfigHostNotFound, | ||
| }, | ||
| { | ||
| name: "`action` create with host flag should throw error missing required flag", | ||
| want: "", | ||
| subCommands: []string{"create", "-h", "test"}, | ||
| err: errors.New("required flag(s) \"file\", \"header\" not set"), | ||
| }, | ||
| { | ||
| name: "`action` edit without host should throw error host not found", | ||
| want: "", | ||
| subCommands: []string{"edit", "123"}, | ||
| err: cmd.ErrClientConfigHostNotFound, | ||
| }, | ||
| { | ||
| name: "`action` edit with host flag should throw error missing required flag", | ||
| want: "", | ||
| subCommands: []string{"edit", "123", "-h", "test"}, | ||
| err: errors.New("required flag(s) \"file\" not set"), | ||
| }, | ||
| { | ||
| name: "`action` view without host should throw error host not found", | ||
| want: "", | ||
| subCommands: []string{"view", "123"}, | ||
| err: cmd.ErrClientConfigHostNotFound, | ||
| }, | ||
| { | ||
| name: "`action` view with host flag should pass", | ||
| want: "", | ||
| subCommands: []string{"view", "123", "-h", "test"}, | ||
| err: context.DeadlineExceeded, | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| cli := cmd.New(tt.cliConfig) | ||
|
|
||
| buf := new(bytes.Buffer) | ||
| cli.SetOutput(buf) | ||
| args := append([]string{"action"}, tt.subCommands...) | ||
| cli.SetArgs(args) | ||
|
|
||
| err := cli.Execute() | ||
| got := buf.String() | ||
|
|
||
| assert.Equal(t, tt.err, err) | ||
| assert.Equal(t, tt.want, got) | ||
| }) | ||
| } | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.