replace log.Fatal with t.Fatal (#1805)
This is required to run deferred teardown functions
This commit is contained in:
parent
f78270188f
commit
7674f907c4
|
@ -42,7 +42,7 @@ func TestWatcherAuth(t *testing.T) {
|
||||||
log.Printf("URL is %s", urlx)
|
log.Printf("URL is %s", urlx)
|
||||||
apiURL, err := url.Parse(urlx + "/")
|
apiURL, err := url.Parse(urlx + "/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("parsing api url: %s", apiURL)
|
t.Fatalf("parsing api url: %s", apiURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
//ok auth
|
//ok auth
|
||||||
|
@ -57,7 +57,7 @@ func TestWatcherAuth(t *testing.T) {
|
||||||
client, err := NewClient(mycfg)
|
client, err := NewClient(mycfg)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("new api client: %s", err)
|
t.Fatalf("new api client: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = client.Auth.AuthenticateWatcher(context.Background(), models.WatcherAuthRequest{
|
_, err = client.Auth.AuthenticateWatcher(context.Background(), models.WatcherAuthRequest{
|
||||||
|
@ -81,7 +81,7 @@ func TestWatcherAuth(t *testing.T) {
|
||||||
client, err = NewClient(mycfg)
|
client, err = NewClient(mycfg)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("new api client: %s", err)
|
t.Fatalf("new api client: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = client.Auth.AuthenticateWatcher(context.Background(), models.WatcherAuthRequest{
|
_, err = client.Auth.AuthenticateWatcher(context.Background(), models.WatcherAuthRequest{
|
||||||
|
@ -112,7 +112,7 @@ func TestWatcherRegister(t *testing.T) {
|
||||||
log.Printf("URL is %s", urlx)
|
log.Printf("URL is %s", urlx)
|
||||||
apiURL, err := url.Parse(urlx + "/")
|
apiURL, err := url.Parse(urlx + "/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("parsing api url: %s", apiURL)
|
t.Fatalf("parsing api url: %s", apiURL)
|
||||||
}
|
}
|
||||||
client, err := RegisterClient(&Config{
|
client, err := RegisterClient(&Config{
|
||||||
MachineID: "test_login",
|
MachineID: "test_login",
|
||||||
|
@ -158,7 +158,7 @@ func TestWatcherUnregister(t *testing.T) {
|
||||||
log.Printf("URL is %s", urlx)
|
log.Printf("URL is %s", urlx)
|
||||||
apiURL, err := url.Parse(urlx + "/")
|
apiURL, err := url.Parse(urlx + "/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("parsing api url: %s", apiURL)
|
t.Fatalf("parsing api url: %s", apiURL)
|
||||||
}
|
}
|
||||||
mycfg := &Config{
|
mycfg := &Config{
|
||||||
MachineID: "test_login",
|
MachineID: "test_login",
|
||||||
|
@ -171,7 +171,7 @@ func TestWatcherUnregister(t *testing.T) {
|
||||||
client, err := NewClient(mycfg)
|
client, err := NewClient(mycfg)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("new api client: %s", err)
|
t.Fatalf("new api client: %s", err)
|
||||||
}
|
}
|
||||||
_, err = client.Auth.UnregisterWatcher(context.Background())
|
_, err = client.Auth.UnregisterWatcher(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -211,7 +211,7 @@ func TestWatcherEnroll(t *testing.T) {
|
||||||
log.Printf("URL is %s", urlx)
|
log.Printf("URL is %s", urlx)
|
||||||
apiURL, err := url.Parse(urlx + "/")
|
apiURL, err := url.Parse(urlx + "/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("parsing api url: %s", apiURL)
|
t.Fatalf("parsing api url: %s", apiURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
mycfg := &Config{
|
mycfg := &Config{
|
||||||
|
@ -225,7 +225,7 @@ func TestWatcherEnroll(t *testing.T) {
|
||||||
client, err := NewClient(mycfg)
|
client, err := NewClient(mycfg)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("new api client: %s", err)
|
t.Fatalf("new api client: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = client.Auth.EnrollWatcher(context.Background(), "goodkey", "", []string{}, false)
|
_, err = client.Auth.EnrollWatcher(context.Background(), "goodkey", "", []string{}, false)
|
||||||
|
|
|
@ -29,7 +29,7 @@ func TestApiAuth(t *testing.T) {
|
||||||
log.Printf("URL is %s", urlx)
|
log.Printf("URL is %s", urlx)
|
||||||
apiURL, err := url.Parse(urlx + "/")
|
apiURL, err := url.Parse(urlx + "/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("parsing api url: %s", apiURL)
|
t.Fatalf("parsing api url: %s", apiURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
@ -41,7 +41,7 @@ func TestApiAuth(t *testing.T) {
|
||||||
|
|
||||||
newcli, err := NewDefaultClient(apiURL, "v1", "toto", auth.Client())
|
newcli, err := NewDefaultClient(apiURL, "v1", "toto", auth.Client())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("new api client: %s", err)
|
t.Fatalf("new api client: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
alert := DecisionsListOpts{IPEquals: new(string)}
|
alert := DecisionsListOpts{IPEquals: new(string)}
|
||||||
|
@ -60,7 +60,7 @@ func TestApiAuth(t *testing.T) {
|
||||||
|
|
||||||
newcli, err = NewDefaultClient(apiURL, "v1", "toto", auth.Client())
|
newcli, err = NewDefaultClient(apiURL, "v1", "toto", auth.Client())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("new api client: %s", err)
|
t.Fatalf("new api client: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, resp, err = newcli.Decisions.List(context.Background(), alert)
|
_, resp, err = newcli.Decisions.List(context.Background(), alert)
|
||||||
|
@ -74,7 +74,7 @@ func TestApiAuth(t *testing.T) {
|
||||||
auth = &APIKeyTransport{}
|
auth = &APIKeyTransport{}
|
||||||
newcli, err = NewDefaultClient(apiURL, "v1", "toto", auth.Client())
|
newcli, err = NewDefaultClient(apiURL, "v1", "toto", auth.Client())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("new api client: %s", err)
|
t.Fatalf("new api client: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, resp, err = newcli.Decisions.List(context.Background(), alert)
|
_, resp, err = newcli.Decisions.List(context.Background(), alert)
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/cwversion"
|
"github.com/crowdsecurity/crowdsec/pkg/cwversion"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,7 +18,7 @@ func TestNewRequestInvalid(t *testing.T) {
|
||||||
//missing slash in uri
|
//missing slash in uri
|
||||||
apiURL, err := url.Parse(urlx)
|
apiURL, err := url.Parse(urlx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("parsing api url: %s", apiURL)
|
t.Fatalf("parsing api url: %s", apiURL)
|
||||||
}
|
}
|
||||||
client, err := NewClient(&Config{
|
client, err := NewClient(&Config{
|
||||||
MachineID: "test_login",
|
MachineID: "test_login",
|
||||||
|
@ -52,7 +51,7 @@ func TestNewRequestTimeout(t *testing.T) {
|
||||||
//missing slash in uri
|
//missing slash in uri
|
||||||
apiURL, err := url.Parse(urlx + "/")
|
apiURL, err := url.Parse(urlx + "/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("parsing api url: %s", apiURL)
|
t.Fatalf("parsing api url: %s", apiURL)
|
||||||
}
|
}
|
||||||
client, err := NewClient(&Config{
|
client, err := NewClient(&Config{
|
||||||
MachineID: "test_login",
|
MachineID: "test_login",
|
||||||
|
|
|
@ -46,7 +46,7 @@ func TestNewClientOk(t *testing.T) {
|
||||||
defer teardown()
|
defer teardown()
|
||||||
apiURL, err := url.Parse(urlx + "/")
|
apiURL, err := url.Parse(urlx + "/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("parsing api url: %s", apiURL)
|
t.Fatalf("parsing api url: %s", apiURL)
|
||||||
}
|
}
|
||||||
client, err := NewClient(&Config{
|
client, err := NewClient(&Config{
|
||||||
MachineID: "test_login",
|
MachineID: "test_login",
|
||||||
|
@ -83,7 +83,7 @@ func TestNewClientKo(t *testing.T) {
|
||||||
defer teardown()
|
defer teardown()
|
||||||
apiURL, err := url.Parse(urlx + "/")
|
apiURL, err := url.Parse(urlx + "/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("parsing api url: %s", apiURL)
|
t.Fatalf("parsing api url: %s", apiURL)
|
||||||
}
|
}
|
||||||
client, err := NewClient(&Config{
|
client, err := NewClient(&Config{
|
||||||
MachineID: "test_login",
|
MachineID: "test_login",
|
||||||
|
@ -116,7 +116,7 @@ func TestNewDefaultClient(t *testing.T) {
|
||||||
defer teardown()
|
defer teardown()
|
||||||
apiURL, err := url.Parse(urlx + "/")
|
apiURL, err := url.Parse(urlx + "/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("parsing api url: %s", apiURL)
|
t.Fatalf("parsing api url: %s", apiURL)
|
||||||
}
|
}
|
||||||
client, err := NewDefaultClient(apiURL, "/v1", "", nil)
|
client, err := NewDefaultClient(apiURL, "/v1", "", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -36,7 +36,7 @@ func TestDecisionsList(t *testing.T) {
|
||||||
})
|
})
|
||||||
apiURL, err := url.Parse(urlx + "/")
|
apiURL, err := url.Parse(urlx + "/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("parsing api url: %s", apiURL)
|
t.Fatalf("parsing api url: %s", apiURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
//ok answer
|
//ok answer
|
||||||
|
@ -46,7 +46,7 @@ func TestDecisionsList(t *testing.T) {
|
||||||
|
|
||||||
newcli, err := NewDefaultClient(apiURL, "v1", "toto", auth.Client())
|
newcli, err := NewDefaultClient(apiURL, "v1", "toto", auth.Client())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("new api client: %s", err)
|
t.Fatalf("new api client: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tduration := "3h59m55.756182786s"
|
tduration := "3h59m55.756182786s"
|
||||||
|
@ -77,7 +77,7 @@ func TestDecisionsList(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("new api client: %s", err)
|
t.Fatalf("new api client: %s", err)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(*decisions, *expected) {
|
if !reflect.DeepEqual(*decisions, *expected) {
|
||||||
t.Fatalf("returned %+v, want %+v", resp, expected)
|
t.Fatalf("returned %+v, want %+v", resp, expected)
|
||||||
|
@ -126,7 +126,7 @@ func TestDecisionsStream(t *testing.T) {
|
||||||
|
|
||||||
apiURL, err := url.Parse(urlx + "/")
|
apiURL, err := url.Parse(urlx + "/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("parsing api url: %s", apiURL)
|
t.Fatalf("parsing api url: %s", apiURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
//ok answer
|
//ok answer
|
||||||
|
@ -136,7 +136,7 @@ func TestDecisionsStream(t *testing.T) {
|
||||||
|
|
||||||
newcli, err := NewDefaultClient(apiURL, "v1", "toto", auth.Client())
|
newcli, err := NewDefaultClient(apiURL, "v1", "toto", auth.Client())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("new api client: %s", err)
|
t.Fatalf("new api client: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tduration := "3h59m55.756182786s"
|
tduration := "3h59m55.756182786s"
|
||||||
|
@ -167,7 +167,7 @@ func TestDecisionsStream(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("new api client: %s", err)
|
t.Fatalf("new api client: %s", err)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(*decisions, *expected) {
|
if !reflect.DeepEqual(*decisions, *expected) {
|
||||||
t.Fatalf("returned %+v, want %+v", resp, expected)
|
t.Fatalf("returned %+v, want %+v", resp, expected)
|
||||||
|
@ -208,7 +208,7 @@ func TestDeleteDecisions(t *testing.T) {
|
||||||
log.Printf("URL is %s", urlx)
|
log.Printf("URL is %s", urlx)
|
||||||
apiURL, err := url.Parse(urlx + "/")
|
apiURL, err := url.Parse(urlx + "/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("parsing api url: %s", apiURL)
|
t.Fatalf("parsing api url: %s", apiURL)
|
||||||
}
|
}
|
||||||
client, err := NewClient(&Config{
|
client, err := NewClient(&Config{
|
||||||
MachineID: "test_login",
|
MachineID: "test_login",
|
||||||
|
@ -219,7 +219,7 @@ func TestDeleteDecisions(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("new api client: %s", err)
|
t.Fatalf("new api client: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
filters := DecisionsDeleteOpts{IPEquals: new(string)}
|
filters := DecisionsDeleteOpts{IPEquals: new(string)}
|
||||||
|
@ -315,7 +315,7 @@ func TestDecisionsStreamOpts_addQueryParamsToURL(t *testing.T) {
|
||||||
// log.Printf("URL is %s", urlx)
|
// log.Printf("URL is %s", urlx)
|
||||||
// apiURL, err := url.Parse(urlx + "/")
|
// apiURL, err := url.Parse(urlx + "/")
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// log.Fatalf("parsing api url: %s", apiURL)
|
// t.Fatalf("parsing api url: %s", apiURL)
|
||||||
// }
|
// }
|
||||||
// client, err := NewClient(&Config{
|
// client, err := NewClient(&Config{
|
||||||
// MachineID: "test_login",
|
// MachineID: "test_login",
|
||||||
|
@ -326,7 +326,7 @@ func TestDecisionsStreamOpts_addQueryParamsToURL(t *testing.T) {
|
||||||
// })
|
// })
|
||||||
|
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// log.Fatalf("new api client: %s", err.Error())
|
// t.Fatalf("new api client: %s", err.Error())
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// filters := DecisionsDeleteOpts{IPEquals: new(string)}
|
// filters := DecisionsDeleteOpts{IPEquals: new(string)}
|
||||||
|
|
Loading…
Reference in a new issue