From 7f8faa75652423d4906d8e47dbe2aa49ff64bbc9 Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Wed, 17 Mar 2021 04:36:47 -0700 Subject: [PATCH] pkg/apiclient: pick up dropped errors (#676) --- pkg/apiclient/alerts_service_test.go | 6 +++++- pkg/apiclient/auth_test.go | 3 +++ pkg/apiclient/decisions_service_test.go | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/apiclient/alerts_service_test.go b/pkg/apiclient/alerts_service_test.go index 53b84e75b..888a1cbe4 100644 --- a/pkg/apiclient/alerts_service_test.go +++ b/pkg/apiclient/alerts_service_test.go @@ -12,6 +12,7 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/models" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestAlertsListAsMachine(t *testing.T) { @@ -388,7 +389,7 @@ func TestAlertsGetAsMachine(t *testing.T) { } alerts, resp, err := client.Alerts.GetByID(context.Background(), 1) - + require.NoError(t, err) if resp.Response.StatusCode != http.StatusOK { t.Errorf("Alerts.List returned status: %d, want %d", resp.Response.StatusCode, http.StatusOK) } @@ -436,6 +437,7 @@ func TestAlertsCreateAsMachine(t *testing.T) { defer teardown() alert := models.AddAlertsRequest{} alerts, resp, err := client.Alerts.Add(context.Background(), alert) + require.NoError(t, err) expected := &models.AddAlertsResponse{"3"} if resp.Response.StatusCode != http.StatusOK { t.Errorf("Alerts.List returned status: %d, want %d", resp.Response.StatusCode, http.StatusOK) @@ -480,6 +482,8 @@ func TestAlertsDeleteAsMachine(t *testing.T) { alert := AlertsDeleteOpts{IPEquals: new(string)} *alert.IPEquals = "1.2.3.4" alerts, resp, err := client.Alerts.Delete(context.Background(), alert) + require.NoError(t, err) + expected := &models.DeleteAlertsResponse{""} if resp.Response.StatusCode != http.StatusOK { t.Errorf("Alerts.List returned status: %d, want %d", resp.Response.StatusCode, http.StatusOK) diff --git a/pkg/apiclient/auth_test.go b/pkg/apiclient/auth_test.go index 671a2c7e8..2817fae77 100644 --- a/pkg/apiclient/auth_test.go +++ b/pkg/apiclient/auth_test.go @@ -8,6 +8,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestApiAuth(t *testing.T) { @@ -46,6 +47,7 @@ func TestApiAuth(t *testing.T) { alert := DecisionsListOpts{IPEquals: new(string)} *alert.IPEquals = "1.2.3.4" _, resp, err := newcli.Decisions.List(context.Background(), alert) + require.NoError(t, err) if resp.Response.StatusCode != http.StatusOK { t.Errorf("Alerts.List returned status: %d, want %d", resp.Response.StatusCode, http.StatusOK) @@ -76,6 +78,7 @@ func TestApiAuth(t *testing.T) { } _, resp, err = newcli.Decisions.List(context.Background(), alert) + require.Error(t, err) log.Infof("--> %s", err) assert.Contains(t, err.Error(), "APIKey is empty") diff --git a/pkg/apiclient/decisions_service_test.go b/pkg/apiclient/decisions_service_test.go index 7e1dd02d3..1fa94e0ce 100644 --- a/pkg/apiclient/decisions_service_test.go +++ b/pkg/apiclient/decisions_service_test.go @@ -12,6 +12,7 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/models" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestDecisionsList(t *testing.T) { @@ -86,6 +87,7 @@ func TestDecisionsList(t *testing.T) { decisionsFilter = DecisionsListOpts{IPEquals: new(string)} *decisionsFilter.IPEquals = "1.2.3.5" decisions, resp, err = newcli.Decisions.List(context.Background(), decisionsFilter) + require.NoError(t, err) if resp.Response.StatusCode != http.StatusOK { t.Errorf("Alerts.List returned status: %d, want %d", resp.Response.StatusCode, http.StatusOK) @@ -159,6 +161,7 @@ func TestDecisionsStream(t *testing.T) { } decisions, resp, err := newcli.Decisions.GetStream(context.Background(), true) + require.NoError(t, err) if resp.Response.StatusCode != http.StatusOK { t.Errorf("Alerts.List returned status: %d, want %d", resp.Response.StatusCode, http.StatusOK) @@ -173,6 +176,7 @@ func TestDecisionsStream(t *testing.T) { //and second call, we get empty lists decisions, resp, err = newcli.Decisions.GetStream(context.Background(), false) + require.NoError(t, err) if resp.Response.StatusCode != http.StatusOK { t.Errorf("Alerts.List returned status: %d, want %d", resp.Response.StatusCode, http.StatusOK) @@ -182,6 +186,7 @@ func TestDecisionsStream(t *testing.T) { //delete stream resp, err = newcli.Decisions.StopStream(context.Background()) + require.NoError(t, err) if resp.Response.StatusCode != http.StatusOK { t.Errorf("Alerts.List returned status: %d, want %d", resp.Response.StatusCode, http.StatusOK)