From 9f68b95b617d61a35becdcf86da4e3ea5d585aab Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Wed, 25 Mar 2020 16:57:29 +0000 Subject: [PATCH 1/2] CLOUDP-59492 Add the status flag to the alerts list --- go.mod | 2 +- go.sum | 4 ++-- internal/cli/atlas_alerts_list.go | 15 ++++++++------- internal/fixtures/alerts.go | 13 ++++++------- internal/mocks/mock_alerts.go | 8 ++++---- internal/store/alerts.go | 4 ++-- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/go.mod b/go.mod index 72c6e719d4..47bb342dca 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/mattn/go-colorable v0.1.4 // indirect github.com/mattn/go-isatty v0.0.12 // indirect github.com/mitchellh/go-homedir v1.1.0 - github.com/mongodb/go-client-mongodb-atlas v0.1.4-0.20200323160302-12cb92c69adf + github.com/mongodb/go-client-mongodb-atlas v0.1.4-0.20200325161849-bca1d320f71c github.com/mongodb/go-client-mongodb-ops-manager v0.0.2-0.20200325124453-024ddde724d1 github.com/mwielbut/pointy v1.1.0 github.com/pelletier/go-toml v1.6.0 // indirect diff --git a/go.sum b/go.sum index 4d6a76b529..52399bc2df 100644 --- a/go.sum +++ b/go.sum @@ -101,8 +101,8 @@ github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mongodb/go-client-mongodb-atlas v0.1.4-0.20200318163834-8b6a5ea6eb67/go.mod h1:LS8O0YLkA+sbtOb3fZLF10yY3tJM+1xATXMJ3oU35LU= -github.com/mongodb/go-client-mongodb-atlas v0.1.4-0.20200323160302-12cb92c69adf h1:dLZh7ukw/hwt6Rnjer/Zjg53spl+YfLn1N8bAnoylu8= -github.com/mongodb/go-client-mongodb-atlas v0.1.4-0.20200323160302-12cb92c69adf/go.mod h1:LS8O0YLkA+sbtOb3fZLF10yY3tJM+1xATXMJ3oU35LU= +github.com/mongodb/go-client-mongodb-atlas v0.1.4-0.20200325161849-bca1d320f71c h1:6VkFHczRJ51vCROsvPhCdVk8V1agzmSOCNnwTAwvLdU= +github.com/mongodb/go-client-mongodb-atlas v0.1.4-0.20200325161849-bca1d320f71c/go.mod h1:LS8O0YLkA+sbtOb3fZLF10yY3tJM+1xATXMJ3oU35LU= github.com/mongodb/go-client-mongodb-ops-manager v0.0.2-0.20200325124453-024ddde724d1 h1:jQoPSGW4a+8mvxBDms0O9QInSPF5HIxjAIdYPJ54mlo= github.com/mongodb/go-client-mongodb-ops-manager v0.0.2-0.20200325124453-024ddde724d1/go.mod h1:FhMID1fXaHZpvHPfUhcDL3pfc5JrBB+aD42HLgFoO+8= github.com/mwielbut/pointy v1.1.0 h1:U5/YEfoIkaGCHv0St3CgjduqXID4FNRoyZgLM1kY9vg= diff --git a/internal/cli/atlas_alerts_list.go b/internal/cli/atlas_alerts_list.go index aa617f0aad..1219656bbf 100644 --- a/internal/cli/atlas_alerts_list.go +++ b/internal/cli/atlas_alerts_list.go @@ -52,10 +52,13 @@ func (opts *atlasAlertsListOpts) Run() error { return json.PrettyPrint(result) } -func (opts *atlasAlertsListOpts) newAlertsListOptions() *atlas.ListOptions { - return &atlas.ListOptions{ - PageNum: opts.pageNum, - ItemsPerPage: opts.itemsPerPage, +func (opts *atlasAlertsListOpts) newAlertsListOptions() *atlas.AlertsListOptions { + return &atlas.AlertsListOptions{ + Status: opts.status, + ListOptions: atlas.ListOptions{ + PageNum: opts.pageNum, + ItemsPerPage: opts.itemsPerPage, + }, } } @@ -79,9 +82,7 @@ func AtlasAlertsListBuilder() *cobra.Command { cmd.Flags().IntVar(&opts.pageNum, flags.Page, 0, usage.Page) cmd.Flags().IntVar(&opts.itemsPerPage, flags.Limit, 0, usage.Limit) - - // TODO: CLOUDP-59492 - //cmd.Flags().StringVar(&opts.status, flags.Status, "", usage.Status) + cmd.Flags().StringVar(&opts.status, flags.Status, "", usage.Status) cmd.Flags().StringVar(&opts.projectID, flags.ProjectID, "", usage.ProjectID) diff --git a/internal/fixtures/alerts.go b/internal/fixtures/alerts.go index 9485561fb3..f2d401325b 100644 --- a/internal/fixtures/alerts.go +++ b/internal/fixtures/alerts.go @@ -39,11 +39,10 @@ func Alert() *atlas.Alert { } } -func AlertsResponse() []atlas.Alert { - //return &atlas.AlertsResponse{ - // Links: nil, - // Results: []atlas.Alert{*Alert()}, - // TotalCount: 1, - //} - return []atlas.Alert{*Alert()} +func AlertsResponse() *atlas.AlertsResponse { + return &atlas.AlertsResponse{ + Links: nil, + Results: []atlas.Alert{*Alert()}, + TotalCount: 1, + } } diff --git a/internal/mocks/mock_alerts.go b/internal/mocks/mock_alerts.go index f7952128ac..ac680b2eda 100644 --- a/internal/mocks/mock_alerts.go +++ b/internal/mocks/mock_alerts.go @@ -72,10 +72,10 @@ func (m *MockAlertLister) EXPECT() *MockAlertListerMockRecorder { } // Alerts mocks base method -func (m *MockAlertLister) Alerts(arg0 string, arg1 *mongodbatlas.ListOptions) ([]mongodbatlas.Alert, error) { +func (m *MockAlertLister) Alerts(arg0 string, arg1 *mongodbatlas.AlertsListOptions) (*mongodbatlas.AlertsResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Alerts", arg0, arg1) - ret0, _ := ret[0].([]mongodbatlas.Alert) + ret0, _ := ret[0].(*mongodbatlas.AlertsResponse) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -163,10 +163,10 @@ func (mr *MockAlertsStoreMockRecorder) Alert(arg0, arg1 interface{}) *gomock.Cal } // Alerts mocks base method -func (m *MockAlertsStore) Alerts(arg0 string, arg1 *mongodbatlas.ListOptions) ([]mongodbatlas.Alert, error) { +func (m *MockAlertsStore) Alerts(arg0 string, arg1 *mongodbatlas.AlertsListOptions) (*mongodbatlas.AlertsResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Alerts", arg0, arg1) - ret0, _ := ret[0].([]mongodbatlas.Alert) + ret0, _ := ret[0].(*mongodbatlas.AlertsResponse) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/internal/store/alerts.go b/internal/store/alerts.go index 1f8f8cbe63..142809bff4 100644 --- a/internal/store/alerts.go +++ b/internal/store/alerts.go @@ -28,7 +28,7 @@ type AlertDescriber interface { } type AlertLister interface { - Alerts(string, *atlas.ListOptions) ([]atlas.Alert, error) + Alerts(string, *atlas.AlertsListOptions) (*atlas.AlertsResponse, error) } type AlertAcknowledger interface { @@ -56,7 +56,7 @@ func (s *Store) Alert(projectID, alertID string) (*atlas.Alert, error) { } // Alerts encapsulate the logic to manage different cloud providers -func (s *Store) Alerts(projectID string, opts *atlas.ListOptions) ([]atlas.Alert, error) { +func (s *Store) Alerts(projectID string, opts *atlas.AlertsListOptions) (*atlas.AlertsResponse, error) { switch s.service { case config.CloudService: result, _, err := s.client.(*atlas.Client).Alerts.List(context.Background(), projectID, opts) From 9902aa1b44e51865c6f186ac22027eea2bbdb680 Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Wed, 25 Mar 2020 17:03:57 +0000 Subject: [PATCH 2/2] Updated e2e tests --- e2e/atlas_alerts_test.go | 123 +++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 62 deletions(-) diff --git a/e2e/atlas_alerts_test.go b/e2e/atlas_alerts_test.go index db8e0fcf46..919118c487 100644 --- a/e2e/atlas_alerts_test.go +++ b/e2e/atlas_alerts_test.go @@ -97,75 +97,74 @@ func TestAtlasAlerts(t *testing.T) { t.Fatalf("unexpected error: %v, resp: %v", err, string(resp)) } - alerts := []mongodbatlas.Alert{} + alerts := mongodbatlas.AlertsResponse{} err = json.Unmarshal(resp, &alerts) if err != nil { t.Fatalf("unexpected error: %v", err) } - if len(alerts) == 0 { - t.Errorf("got=%#v\nwant>0\n", len(alerts)) + if len(alerts.Results) == 0 { + t.Errorf("got=%#v\nwant>0\n", len(alerts.Results)) + } + + }) + t.Run("List with status OPEN", func(t *testing.T) { + + cmd := exec.Command(cliPath, + atlasEntity, + alertsEntity, + "list", + "--status", + "OPEN", + ) + + cmd.Env = os.Environ() + resp, err := cmd.CombinedOutput() + + if err != nil { + t.Fatalf("unexpected error: %v, resp: %v", err, string(resp)) + } + + alerts := mongodbatlas.AlertsResponse{} + err = json.Unmarshal(resp, &alerts) + + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + + if len(alerts.Results) == 0 { + t.Errorf("got=%#v\nwant=%#v\n", len(alerts.Results), 0) + } + + }) + t.Run("List with status CLOSED", func(t *testing.T) { + + cmd := exec.Command(cliPath, + atlasEntity, + alertsEntity, + "list", + "--status", + "CLOSED", + ) + + cmd.Env = os.Environ() + resp, err := cmd.CombinedOutput() + + if err != nil { + t.Fatalf("unexpected error: %v, resp: %v", err, string(resp)) + } + + alerts := mongodbatlas.AlertsResponse{} + err = json.Unmarshal(resp, &alerts) + + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + + if len(alerts.Results) == 0 { + t.Errorf("got=%#v\nwant=%#v\n", len(alerts.Results), 7) } }) - // TODO: CLOUDP-59492 - // t.Run("List with status OPEN", func(t *testing.T) { - // - // cmd := exec.Command(cliPath, - // atlasEntity, - // alertsEntity, - // "list", - // "--status", - // "OPEN", - // ) - // - // cmd.Env = os.Environ() - // resp, err := cmd.CombinedOutput() - // - // if err != nil { - // t.Fatalf("unexpected error: %v, resp: %v", err, string(resp)) - // } - // - // alerts := mongodbatlas.AlertsResponse{} - // err = json.Unmarshal(resp, &alerts) - // - // if err != nil { - // t.Fatalf("unexpected error: %v", err) - // } - // - // if len(alerts.Results) != 0 { - // t.Errorf("got=%#v\nwant=%#v\n", len(alerts.Results), 0) - // } - // - // }) - // t.Run("List with status CLOSED", func(t *testing.T) { - // - // cmd := exec.Command(cliPath, - // atlasEntity, - // alertsEntity, - // "list", - // "--status", - // "CLOSED", - // ) - // - // cmd.Env = os.Environ() - // resp, err := cmd.CombinedOutput() - // - // if err != nil { - // t.Fatalf("unexpected error: %v, resp: %v", err, string(resp)) - // } - // - // alerts := mongodbatlas.AlertsResponse{} - // err = json.Unmarshal(resp, &alerts) - // - // if err != nil { - // t.Fatalf("unexpected error: %v", err) - // } - // - // if len(alerts.Results) != 7 { - // t.Errorf("got=%#v\nwant=%#v\n", len(alerts.Results), 7) - // } - // - // }) }