diff --git a/docs/atlascli/command/atlas-alerts-settings-list.txt b/docs/atlascli/command/atlas-alerts-settings-list.txt index 07497a19e3..3921094e7f 100644 --- a/docs/atlascli/command/atlas-alerts-settings-list.txt +++ b/docs/atlascli/command/atlas-alerts-settings-list.txt @@ -37,6 +37,10 @@ Options - Type - Required - Description + * - -c, --compact + - + - false + - Flag that enables the compact array response structure for a json output. The --compact option returns array objects as top-level responses and allows backward compatibility for scripts based on previous CLI versions. Omitting the --compact option for a json output returns array objects within a 'results' sub-array. You must specify --output json to use this option. * - -h, --help - - false diff --git a/docs/atlascli/command/atlas-dbusers-list.txt b/docs/atlascli/command/atlas-dbusers-list.txt index 0846862a80..ae95051c97 100644 --- a/docs/atlascli/command/atlas-dbusers-list.txt +++ b/docs/atlascli/command/atlas-dbusers-list.txt @@ -37,6 +37,10 @@ Options - Type - Required - Description + * - -c, --compact + - + - false + - Flag that enables the compact array response structure for a json output. The --compact option returns array objects as top-level responses and allows backward compatibility for scripts based on previous CLI versions. Omitting the --compact option for a json output returns array objects within a 'results' sub-array. You must specify --output json to use this option. * - -h, --help - - false diff --git a/docs/atlascli/command/atlas-organizations-apiKeys-list.txt b/docs/atlascli/command/atlas-organizations-apiKeys-list.txt index 4a49cb86e3..51637479c1 100644 --- a/docs/atlascli/command/atlas-organizations-apiKeys-list.txt +++ b/docs/atlascli/command/atlas-organizations-apiKeys-list.txt @@ -37,6 +37,10 @@ Options - Type - Required - Description + * - -c, --compact + - + - false + - Flag that enables the compact array response structure for a json output. The --compact option returns array objects as top-level responses and allows backward compatibility for scripts based on previous CLI versions. Omitting the --compact option for a json output returns array objects within a 'results' sub-array. You must specify --output json to use this option. * - -h, --help - - false diff --git a/docs/atlascli/command/atlas-processes-list.txt b/docs/atlascli/command/atlas-processes-list.txt index fd9c756670..be3160085f 100644 --- a/docs/atlascli/command/atlas-processes-list.txt +++ b/docs/atlascli/command/atlas-processes-list.txt @@ -37,6 +37,10 @@ Options - Type - Required - Description + * - -c, --compact + - + - false + - Flag that enables the compact array response structure for a json output. The --compact option returns array objects as top-level responses and allows backward compatibility for scripts based on previous CLI versions. Omitting the --compact option for a json output returns array objects within a 'results' sub-array. You must specify --output json to use this option. * - -h, --help - - false diff --git a/docs/atlascli/command/atlas-projects-apiKeys-list.txt b/docs/atlascli/command/atlas-projects-apiKeys-list.txt index 0a692e5956..36d079888c 100644 --- a/docs/atlascli/command/atlas-projects-apiKeys-list.txt +++ b/docs/atlascli/command/atlas-projects-apiKeys-list.txt @@ -37,6 +37,10 @@ Options - Type - Required - Description + * - -c, --compact + - + - false + - Flag that enables the compact array response structure for a json output. The --compact option returns array objects as top-level responses and allows backward compatibility for scripts based on previous CLI versions. Omitting the --compact option for a json output returns array objects within a 'results' sub-array. You must specify --output json to use this option. * - -h, --help - - false diff --git a/docs/atlascli/command/atlas-projects-users-list.txt b/docs/atlascli/command/atlas-projects-users-list.txt index 5f8eed4a9e..32b34cc926 100644 --- a/docs/atlascli/command/atlas-projects-users-list.txt +++ b/docs/atlascli/command/atlas-projects-users-list.txt @@ -37,6 +37,10 @@ Options - Type - Required - Description + * - -c, --compact + - + - false + - Flag that enables the compact array response structure for a json output. The --compact option returns array objects as top-level responses and allows backward compatibility for scripts based on previous CLI versions. Omitting the --compact option for a json output returns array objects within a 'results' sub-array. You must specify --output json to use this option. * - -h, --help - - false diff --git a/docs/atlascli/command/atlas-teams-list.txt b/docs/atlascli/command/atlas-teams-list.txt index bcdfb03e79..d5ad37b016 100644 --- a/docs/atlascli/command/atlas-teams-list.txt +++ b/docs/atlascli/command/atlas-teams-list.txt @@ -37,6 +37,10 @@ Options - Type - Required - Description + * - -c, --compact + - + - false + - Flag that enables the compact array response structure for a json output. The --compact option returns array objects as top-level responses and allows backward compatibility for scripts based on previous CLI versions. Omitting the --compact option for a json output returns array objects within a 'results' sub-array. You must specify --output json to use this option. * - -h, --help - - false diff --git a/docs/atlascli/command/atlas-teams-users-list.txt b/docs/atlascli/command/atlas-teams-users-list.txt index 321c689e59..994b1fd8e9 100644 --- a/docs/atlascli/command/atlas-teams-users-list.txt +++ b/docs/atlascli/command/atlas-teams-users-list.txt @@ -37,6 +37,10 @@ Options - Type - Required - Description + * - -c, --compact + - + - false + - Flag that enables the compact array response structure for a json output. The --compact option returns array objects as top-level responses and allows backward compatibility for scripts based on previous CLI versions. Omitting the --compact option for a json output returns array objects within a 'results' sub-array. You must specify --output json to use this option. * - -h, --help - - false diff --git a/docs/mongocli/command/mongocli-atlas-dbusers-list.txt b/docs/mongocli/command/mongocli-atlas-dbusers-list.txt index 99419a3f12..ecba954d20 100644 --- a/docs/mongocli/command/mongocli-atlas-dbusers-list.txt +++ b/docs/mongocli/command/mongocli-atlas-dbusers-list.txt @@ -37,6 +37,10 @@ Options - Type - Required - Description + * - -c, --compact + - + - false + - Flag that enables the compact array response structure for a json output. The --compact option returns array objects as top-level responses and allows backward compatibility for scripts based on previous CLI versions. Omitting the --compact option for a json output returns array objects within a 'results' sub-array. You must specify --output json to use this option. * - -h, --help - - false diff --git a/docs/mongocli/command/mongocli-atlas-processes-list.txt b/docs/mongocli/command/mongocli-atlas-processes-list.txt index f0bc89e233..0732f253cd 100644 --- a/docs/mongocli/command/mongocli-atlas-processes-list.txt +++ b/docs/mongocli/command/mongocli-atlas-processes-list.txt @@ -37,6 +37,10 @@ Options - Type - Required - Description + * - -c, --compact + - + - false + - Flag that enables the compact array response structure for a json output. The --compact option returns array objects as top-level responses and allows backward compatibility for scripts based on previous CLI versions. Omitting the --compact option for a json output returns array objects within a 'results' sub-array. You must specify --output json to use this option. * - -h, --help - - false diff --git a/internal/cli/atlas/alerts/settings/list.go b/internal/cli/atlas/alerts/settings/list.go index d058a2e440..0cc5d52fad 100644 --- a/internal/cli/atlas/alerts/settings/list.go +++ b/internal/cli/atlas/alerts/settings/list.go @@ -32,7 +32,8 @@ type ListOpts struct { cli.GlobalOpts cli.OutputOpts cli.ListOpts - store store.AlertConfigurationLister + CompactResponse bool + store store.AlertConfigurationLister } func (opts *ListOpts) initStore(ctx context.Context) func() error { @@ -58,6 +59,10 @@ func (opts *ListOpts) Run() error { return err } + if opts.CompactResponse { + return opts.PrintForCompactResultsResponse(r) + } + return opts.Print(r) } @@ -90,6 +95,7 @@ func ListBuilder() *cobra.Command { cmd.Flags().StringVar(&opts.ProjectID, flag.ProjectID, "", usage.ProjectID) cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut) + cmd.Flags().BoolVarP(&opts.CompactResponse, flag.CompactResponse, flag.CompactResponseShort, false, usage.CompactResponse) _ = cmd.RegisterFlagCompletionFunc(flag.Output, opts.AutoCompleteOutputFlag()) return cmd diff --git a/internal/cli/atlas/dbusers/list.go b/internal/cli/atlas/dbusers/list.go index 263e020806..0c3303a989 100644 --- a/internal/cli/atlas/dbusers/list.go +++ b/internal/cli/atlas/dbusers/list.go @@ -35,7 +35,8 @@ type ListOpts struct { cli.GlobalOpts cli.OutputOpts cli.ListOpts - store store.DatabaseUserLister + CompactResponse bool + store store.DatabaseUserLister } func (opts *ListOpts) initStore(ctx context.Context) func() error { @@ -53,6 +54,10 @@ func (opts *ListOpts) Run() error { return err } + if opts.CompactResponse { + return opts.PrintForCompactResultsResponse(r) + } + return opts.Print(r) } @@ -84,6 +89,7 @@ func ListBuilder() *cobra.Command { cmd.Flags().StringVar(&opts.ProjectID, flag.ProjectID, "", usage.ProjectID) cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut) + cmd.Flags().BoolVarP(&opts.CompactResponse, flag.CompactResponse, flag.CompactResponseShort, false, usage.CompactResponse) _ = cmd.RegisterFlagCompletionFunc(flag.Output, opts.AutoCompleteOutputFlag()) return cmd diff --git a/internal/cli/atlas/organizations/apikeys/list.go b/internal/cli/atlas/organizations/apikeys/list.go index 7b08fc2663..97b6228ea5 100644 --- a/internal/cli/atlas/organizations/apikeys/list.go +++ b/internal/cli/atlas/organizations/apikeys/list.go @@ -35,7 +35,8 @@ type ListOpts struct { cli.GlobalOpts cli.OutputOpts cli.ListOpts - store store.OrganizationAPIKeyLister + CompactResponse bool + store store.OrganizationAPIKeyLister } func (opts *ListOpts) initStore(ctx context.Context) func() error { @@ -53,6 +54,10 @@ func (opts *ListOpts) Run() error { return err } + if opts.CompactResponse { + return opts.PrintForCompactResultsResponse(r) + } + return opts.Print(r) } @@ -84,6 +89,7 @@ func ListBuilder() *cobra.Command { cmd.Flags().StringVar(&opts.OrgID, flag.OrgID, "", usage.OrgID) cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut) + cmd.Flags().BoolVarP(&opts.CompactResponse, flag.CompactResponse, flag.CompactResponseShort, false, usage.CompactResponse) _ = cmd.RegisterFlagCompletionFunc(flag.Output, opts.AutoCompleteOutputFlag()) return cmd diff --git a/internal/cli/atlas/processes/list.go b/internal/cli/atlas/processes/list.go index 30bfc00eec..f6580eff4c 100644 --- a/internal/cli/atlas/processes/list.go +++ b/internal/cli/atlas/processes/list.go @@ -37,7 +37,8 @@ type ListOpts struct { cli.GlobalOpts cli.OutputOpts cli.ListOpts - store store.ProcessLister + CompactResponse bool + store store.ProcessLister } func (opts *ListOpts) initStore(ctx context.Context) func() error { @@ -55,6 +56,10 @@ func (opts *ListOpts) Run() error { return err } + if opts.CompactResponse { + return opts.PrintForCompactResultsResponse(r) + } + return opts.Print(r) } @@ -100,6 +105,7 @@ func ListBuilder() *cobra.Command { cmd.Flags().StringVar(&opts.ProjectID, flag.ProjectID, "", usage.ProjectID) cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut) + cmd.Flags().BoolVarP(&opts.CompactResponse, flag.CompactResponse, flag.CompactResponseShort, false, usage.CompactResponse) _ = cmd.RegisterFlagCompletionFunc(flag.Output, opts.AutoCompleteOutputFlag()) return cmd diff --git a/internal/cli/atlas/projects/apikeys/list.go b/internal/cli/atlas/projects/apikeys/list.go index aab218c693..e784baf619 100644 --- a/internal/cli/atlas/projects/apikeys/list.go +++ b/internal/cli/atlas/projects/apikeys/list.go @@ -35,7 +35,8 @@ type ListOpts struct { cli.GlobalOpts cli.OutputOpts cli.ListOpts - store store.ProjectAPIKeyLister + CompactResponse bool + store store.ProjectAPIKeyLister } func (opts *ListOpts) initStore(ctx context.Context) func() error { @@ -54,6 +55,10 @@ func (opts *ListOpts) Run() error { return err } + if opts.CompactResponse { + return opts.PrintForCompactResultsResponse(r) + } + return opts.Print(r) } @@ -85,6 +90,7 @@ func ListBuilder() *cobra.Command { cmd.Flags().StringVar(&opts.ProjectID, flag.ProjectID, "", usage.ProjectID) cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut) + cmd.Flags().BoolVarP(&opts.CompactResponse, flag.CompactResponse, flag.CompactResponseShort, false, usage.CompactResponse) _ = cmd.RegisterFlagCompletionFunc(flag.Output, opts.AutoCompleteOutputFlag()) return cmd diff --git a/internal/cli/atlas/projects/users/list.go b/internal/cli/atlas/projects/users/list.go index 2dcdaf76a5..639d170843 100644 --- a/internal/cli/atlas/projects/users/list.go +++ b/internal/cli/atlas/projects/users/list.go @@ -35,7 +35,8 @@ type ListOpts struct { cli.GlobalOpts cli.OutputOpts cli.ListOpts - store store.ProjectUsersLister + CompactResponse bool + store store.ProjectUsersLister } func (opts *ListOpts) initStore(ctx context.Context) func() error { @@ -54,6 +55,10 @@ func (opts *ListOpts) Run() error { return err } + if opts.CompactResponse { + return opts.PrintForCompactResultsResponse(r) + } + return opts.Print(r) } @@ -85,6 +90,7 @@ func ListBuilder() *cobra.Command { cmd.Flags().StringVar(&opts.ProjectID, flag.ProjectID, "", usage.ProjectID) cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut) + cmd.Flags().BoolVarP(&opts.CompactResponse, flag.CompactResponse, flag.CompactResponseShort, false, usage.CompactResponse) _ = cmd.RegisterFlagCompletionFunc(flag.Output, opts.AutoCompleteOutputFlag()) return cmd diff --git a/internal/cli/atlas/teams/list.go b/internal/cli/atlas/teams/list.go index 966af93de5..ce0132001a 100644 --- a/internal/cli/atlas/teams/list.go +++ b/internal/cli/atlas/teams/list.go @@ -35,7 +35,8 @@ type ListOpts struct { cli.GlobalOpts cli.OutputOpts cli.ListOpts - store store.TeamLister + CompactResponse bool + store store.TeamLister } func (opts *ListOpts) initStore(ctx context.Context) func() error { @@ -54,6 +55,10 @@ func (opts *ListOpts) Run() error { return err } + if opts.CompactResponse { + return opts.PrintForCompactResultsResponse(r) + } + return opts.Print(r) } @@ -85,6 +90,7 @@ func ListBuilder() *cobra.Command { cmd.Flags().StringVar(&opts.OrgID, flag.OrgID, "", usage.OrgID) cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut) + cmd.Flags().BoolVarP(&opts.CompactResponse, flag.CompactResponse, flag.CompactResponseShort, false, usage.CompactResponse) _ = cmd.RegisterFlagCompletionFunc(flag.Output, opts.AutoCompleteOutputFlag()) return cmd diff --git a/internal/cli/atlas/teams/users/list.go b/internal/cli/atlas/teams/users/list.go index aade5eda34..0391c936f7 100644 --- a/internal/cli/atlas/teams/users/list.go +++ b/internal/cli/atlas/teams/users/list.go @@ -34,8 +34,9 @@ const listTemplate = `ID FIRST NAME LAST NAME USERNAME EMAIL{{range .Results}} type ListOpts struct { cli.GlobalOpts cli.OutputOpts - store store.TeamUserLister - teamID string + CompactResponse bool + store store.TeamUserLister + teamID string } func (opts *ListOpts) initStore(ctx context.Context) func() error { @@ -52,6 +53,10 @@ func (opts *ListOpts) Run() error { return err } + if opts.CompactResponse { + return opts.PrintForCompactResultsResponse(r) + } + return opts.Print(r) } @@ -82,6 +87,7 @@ func ListBuilder() *cobra.Command { cmd.Flags().StringVar(&opts.OrgID, flag.OrgID, "", usage.OrgID) cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut) + cmd.Flags().BoolVarP(&opts.CompactResponse, flag.CompactResponse, flag.CompactResponseShort, false, usage.CompactResponse) _ = cmd.RegisterFlagCompletionFunc(flag.Output, opts.AutoCompleteOutputFlag()) _ = cmd.MarkFlagRequired(flag.TeamID) diff --git a/internal/cli/output_opts.go b/internal/cli/output_opts.go index c344cfe12c..a372946877 100644 --- a/internal/cli/output_opts.go +++ b/internal/cli/output_opts.go @@ -15,12 +15,14 @@ package cli import ( + "encoding/json" "errors" "fmt" "io" "os" "strings" + "github.com/PaesslerAG/jsonpath" "github.com/mongodb/mongodb-atlas-cli/internal/config" "github.com/mongodb/mongodb-atlas-cli/internal/jsonpathwriter" "github.com/mongodb/mongodb-atlas-cli/internal/jsonwriter" @@ -113,6 +115,48 @@ func (opts *OutputOpts) Print(o interface{}) error { return err } +func (opts *OutputOpts) PrintForCompactResultsResponse(o interface{}) error { + if opts.ConfigOutput() == jsonFormat { + compactResponse, err := mapReduceResults(o) + if err == nil { + return jsonwriter.Print(opts.ConfigWriter(), compactResponse) + } + } + + outputType, val := opts.outputTypeAndValue() + if outputType == jsonPath { + compactResponse, err := mapReduceResults(o) + if err == nil { + return jsonpathwriter.Print(opts.ConfigWriter(), val, compactResponse) + } + } + + t, err := template(outputType, val) + if err != nil { + return err + } + + if t != "" { + return templatewriter.Print(opts.ConfigWriter(), t, o) + } + _, err = fmt.Fprintln(opts.ConfigWriter(), o) + return err +} + +func mapReduceResults(o interface{}) (interface{}, error) { + jsonString, err := json.Marshal(o) + if err != nil { + return nil, err + } + + var val interface{} + if e := json.Unmarshal(jsonString, &val); e != nil { + return nil, e + } + + return jsonpath.Get("results", val) +} + // outputTypeAndValue returns the output type and the associated value // Current available output types are: // "go-template=Template string", diff --git a/internal/cli/output_opts_test.go b/internal/cli/output_opts_test.go index e3068fbd99..6830adf157 100644 --- a/internal/cli/output_opts_test.go +++ b/internal/cli/output_opts_test.go @@ -18,7 +18,11 @@ package cli import ( "io" + "reflect" "testing" + + "github.com/mongodb/mongodb-atlas-cli/internal/pointer" + "go.mongodb.org/atlas-sdk/admin" ) func TestOutputOpts_outputTypeAndValue(t *testing.T) { @@ -64,3 +68,33 @@ func TestOutputOpts_outputTypeAndValue(t *testing.T) { }) } } + +func TestOutputOpts_mapReduceResults(t *testing.T) { + t.Run("when results present", func(t *testing.T) { + input := *admin.NewPaginatedTeam() + wantID := "123" + wantName := "Team A" + input.Results = []admin.TeamResponse{ + { + Id: pointer.Get(wantID), + Name: pointer.Get(wantName), + }, + } + + compactResults, err := mapReduceResults(input) + if err != nil { + t.Fatalf("mapReduceResults() unexpected error: %v", err) + } + + mapArrayResponse := reflect.ValueOf(compactResults).Interface().([]interface{}) + mapResponse := mapArrayResponse[0].(map[string]interface{}) + gotID := mapResponse["id"] + gotName := mapResponse["name"] + if gotID != wantID { + t.Errorf("mapReduceResults() got = %v, want %v", gotID, wantID) + } + if gotName != wantName { + t.Errorf("mapReduceResults() got = %v, want %v", gotName, wantName) + } + }) +} diff --git a/internal/flag/flags.go b/internal/flag/flags.go index 510e81e30a..88021a5a79 100644 --- a/internal/flag/flags.go +++ b/internal/flag/flags.go @@ -350,4 +350,6 @@ const ( EnableWatch = "watch" // EnableWatch flag EnableWatchShort = "w" // EnableWatchShort flag WatchTimeout = "watchTimeout" // WatchTimeout flag + CompactResponse = "compact" // CompactResponse flag to return compacted list response + CompactResponseShort = "c" // CompactResponseShort flag ) diff --git a/internal/usage/usage.go b/internal/usage/usage.go index e4c47ff5bb..829f0beaa9 100644 --- a/internal/usage/usage.go +++ b/internal/usage/usage.go @@ -433,4 +433,5 @@ dbName and collection are required only for built-in roles.` UpdateWarning = " Passing this flag replaces preexisting data." EnableWatch = "Watch the command until it completes its execution or the watch times out. To set the time that the watch times out, use the --watchTimeout option." WatchTimeout = "Time in seconds until a watch times out. After a watch times out, the CLI no longer watches the command." + CompactResponse = "Flag that enables the compact array response structure for a json output. The --compact option returns array objects as top-level responses and allows backward compatibility for scripts based on previous CLI versions. Omitting the --compact option for a json output returns array objects within a 'results' sub-array. You must specify --output json to use this option." ) diff --git a/test/e2e/atlas/alert_settings_test.go b/test/e2e/atlas/alert_settings_test.go index dbab1ebf53..0cf7996cd1 100644 --- a/test/e2e/atlas/alert_settings_test.go +++ b/test/e2e/atlas/alert_settings_test.go @@ -81,6 +81,28 @@ func TestAlertConfig(t *testing.T) { cmd.Env = os.Environ() resp, err := cmd.CombinedOutput() assert.NoError(t, err, string(resp)) + a := assert.New(t) + var config admin.PaginatedAlertConfig + if err := json.Unmarshal(resp, &config); a.NoError(err) { + a.NotEmpty(config.Results) + } + }) + + t.Run("List Compact", func(t *testing.T) { + cmd := exec.Command(cliPath, + alertsEntity, + configEntity, + "ls", + "-c", + "-o=json") + cmd.Env = os.Environ() + resp, err := cmd.CombinedOutput() + assert.NoError(t, err, string(resp)) + a := assert.New(t) + var config []admin.AlertConfigViewForNdsGroup + if err := json.Unmarshal(resp, &config); a.NoError(err) { + a.NotEmpty(config) + } }) t.Run("Update", func(t *testing.T) { diff --git a/test/e2e/atlas/dbusers_test.go b/test/e2e/atlas/dbusers_test.go index 24c79210b2..4d5519b276 100644 --- a/test/e2e/atlas/dbusers_test.go +++ b/test/e2e/atlas/dbusers_test.go @@ -82,6 +82,24 @@ func TestDBUserWithFlags(t *testing.T) { } }) + t.Run("List Compact", func(t *testing.T) { + cmd := exec.Command(cliPath, + dbusersEntity, + "ls", + "-c", + "-o=json") + cmd.Env = os.Environ() + resp, err := cmd.CombinedOutput() + require.NoError(t, err, string(resp)) + + var users []atlasv2.DatabaseUser + require.NoError(t, json.Unmarshal(resp, &users), string(resp)) + + if len(users) == 0 { + t.Fatalf("expected len(users) > 0, got 0") + } + }) + t.Run("Describe", func(t *testing.T) { testDescribeUser(t, cliPath, username) }) diff --git a/test/e2e/atlas/processes_test.go b/test/e2e/atlas/processes_test.go index 79a2639249..6236d08b11 100644 --- a/test/e2e/atlas/processes_test.go +++ b/test/e2e/atlas/processes_test.go @@ -55,6 +55,27 @@ func TestProcesses(t *testing.T) { } }) + t.Run("list compact", func(t *testing.T) { + cmd := exec.Command(cliPath, + processesEntity, + "list", + "-p", + "--projectId", g.projectID, + "-o=json") + + cmd.Env = os.Environ() + resp, err := cmd.CombinedOutput() + + if err != nil { + t.Fatalf("unexpected error: %v, resp: %v", err, string(resp)) + } + var hostViewsCompact []atlasv2.HostViewAtlas + + if err := json.Unmarshal(resp, &hostViewsCompact); assert.NoError(t, err) { + require.NotEmpty(t, hostViewsCompact) + } + }) + t.Run("describe", func(t *testing.T) { cmd := exec.Command(cliPath, processesEntity, diff --git a/test/e2e/iam/atlas_org_api_keys_test.go b/test/e2e/iam/atlas_org_api_keys_test.go index a0d6d64d02..982bbc07ac 100644 --- a/test/e2e/iam/atlas_org_api_keys_test.go +++ b/test/e2e/iam/atlas_org_api_keys_test.go @@ -81,6 +81,26 @@ func TestAtlasOrgAPIKeys(t *testing.T) { assert.NotEmpty(t, keys.Results) }) + t.Run("List Compact", func(t *testing.T) { + cmd := exec.Command(cliPath, + orgEntity, + apiKeysEntity, + "ls", + "-c", + "-o=json") + cmd.Env = os.Environ() + resp, err := cmd.CombinedOutput() + + if err != nil { + t.Fatalf("unexpected error: %v, resp: %v", err, string(resp)) + } + var keys []atlasv2.ApiUser + if err := json.Unmarshal(resp, &keys); err != nil { + t.Fatalf("unexpected error: %v", err) + } + assert.NotEmpty(t, keys) + }) + t.Run("Update", func(t *testing.T) { newDesc := "e2e-test-atlas-org-updated" cmd := exec.Command(cliPath, diff --git a/test/e2e/iam/atlas_project_api_keys_test.go b/test/e2e/iam/atlas_project_api_keys_test.go index 787886f557..ad45120623 100644 --- a/test/e2e/iam/atlas_project_api_keys_test.go +++ b/test/e2e/iam/atlas_project_api_keys_test.go @@ -102,6 +102,26 @@ func TestAtlasProjectAPIKeys(t *testing.T) { assert.NotEmpty(t, keys.Results) }) + t.Run("List Compact", func(t *testing.T) { + cmd := exec.Command(cliPath, + projectsEntity, + apiKeysEntity, + "ls", + "-c", + "-o=json") + cmd.Env = os.Environ() + resp, err := cmd.CombinedOutput() + + if err != nil { + t.Fatalf("unexpected error: %v, resp: %v", err, string(resp)) + } + var keys []atlasv2.ApiUser + if err := json.Unmarshal(resp, &keys); err != nil { + t.Fatalf("unexpected error: %v", err) + } + assert.NotEmpty(t, keys) + }) + t.Run("Delete", func(t *testing.T) { cmd := exec.Command(cliPath, projectsEntity, diff --git a/test/e2e/iam/atlas_team_users_test.go b/test/e2e/iam/atlas_team_users_test.go index 0142170560..d87cd48d59 100644 --- a/test/e2e/iam/atlas_team_users_test.go +++ b/test/e2e/iam/atlas_team_users_test.go @@ -95,6 +95,25 @@ func TestAtlasTeamUsers(t *testing.T) { } }) + t.Run("List Compact", func(t *testing.T) { + cmd := exec.Command(cliPath, + teamsEntity, + usersEntity, + "ls", + "-c", + "--teamId", + teamID, + "-o=json") + cmd.Env = os.Environ() + resp, err := cmd.CombinedOutput() + require.NoError(t, err, string(resp)) + a := assert.New(t) + var teams []atlasv2.AppUser + if err := json.Unmarshal(resp, &teams); a.NoError(err) { + a.NotEmpty(teams) + } + }) + t.Run("Delete", func(t *testing.T) { cmd := exec.Command(cliPath, teamsEntity, diff --git a/test/e2e/iam/atlas_teams_test.go b/test/e2e/iam/atlas_teams_test.go index afee4c83d8..635d876216 100644 --- a/test/e2e/iam/atlas_teams_test.go +++ b/test/e2e/iam/atlas_teams_test.go @@ -123,6 +123,24 @@ func TestAtlasTeams(t *testing.T) { } }) + t.Run("List Compact", func(t *testing.T) { + cmd := exec.Command(cliPath, + teamsEntity, + "ls", + "-c", + "-o=json") + cmd.Env = os.Environ() + resp, err := cmd.CombinedOutput() + + a := assert.New(t) + a.NoError(err, string(resp)) + + var teams []atlasv2.TeamResponse + if err := json.Unmarshal(resp, &teams); a.NoError(err) { + a.NotEmpty(t, teams) + } + }) + t.Run("Delete", func(t *testing.T) { cmd := exec.Command(cliPath, teamsEntity,