replace log.Fatal with t.Fatal (#1805)

This is required to run deferred teardown functions
This commit is contained in:
mmetc 2022-10-13 10:42:46 +02:00 committed by GitHub
parent f78270188f
commit 7674f907c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 28 deletions

View file

@ -42,7 +42,7 @@ func TestWatcherAuth(t *testing.T) {
log.Printf("URL is %s", urlx)
apiURL, err := url.Parse(urlx + "/")
if err != nil {
log.Fatalf("parsing api url: %s", apiURL)
t.Fatalf("parsing api url: %s", apiURL)
}
//ok auth
@ -57,7 +57,7 @@ func TestWatcherAuth(t *testing.T) {
client, err := NewClient(mycfg)
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{
@ -81,7 +81,7 @@ func TestWatcherAuth(t *testing.T) {
client, err = NewClient(mycfg)
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{
@ -112,7 +112,7 @@ func TestWatcherRegister(t *testing.T) {
log.Printf("URL is %s", urlx)
apiURL, err := url.Parse(urlx + "/")
if err != nil {
log.Fatalf("parsing api url: %s", apiURL)
t.Fatalf("parsing api url: %s", apiURL)
}
client, err := RegisterClient(&Config{
MachineID: "test_login",
@ -158,7 +158,7 @@ func TestWatcherUnregister(t *testing.T) {
log.Printf("URL is %s", urlx)
apiURL, err := url.Parse(urlx + "/")
if err != nil {
log.Fatalf("parsing api url: %s", apiURL)
t.Fatalf("parsing api url: %s", apiURL)
}
mycfg := &Config{
MachineID: "test_login",
@ -171,7 +171,7 @@ func TestWatcherUnregister(t *testing.T) {
client, err := NewClient(mycfg)
if err != nil {
log.Fatalf("new api client: %s", err)
t.Fatalf("new api client: %s", err)
}
_, err = client.Auth.UnregisterWatcher(context.Background())
if err != nil {
@ -211,7 +211,7 @@ func TestWatcherEnroll(t *testing.T) {
log.Printf("URL is %s", urlx)
apiURL, err := url.Parse(urlx + "/")
if err != nil {
log.Fatalf("parsing api url: %s", apiURL)
t.Fatalf("parsing api url: %s", apiURL)
}
mycfg := &Config{
@ -225,7 +225,7 @@ func TestWatcherEnroll(t *testing.T) {
client, err := NewClient(mycfg)
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)

View file

@ -29,7 +29,7 @@ func TestApiAuth(t *testing.T) {
log.Printf("URL is %s", urlx)
apiURL, err := url.Parse(urlx + "/")
if err != nil {
log.Fatalf("parsing api url: %s", apiURL)
t.Fatalf("parsing api url: %s", apiURL)
}
defer teardown()
@ -41,7 +41,7 @@ func TestApiAuth(t *testing.T) {
newcli, err := NewDefaultClient(apiURL, "v1", "toto", auth.Client())
if err != nil {
log.Fatalf("new api client: %s", err)
t.Fatalf("new api client: %s", err)
}
alert := DecisionsListOpts{IPEquals: new(string)}
@ -60,7 +60,7 @@ func TestApiAuth(t *testing.T) {
newcli, err = NewDefaultClient(apiURL, "v1", "toto", auth.Client())
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)
@ -74,7 +74,7 @@ func TestApiAuth(t *testing.T) {
auth = &APIKeyTransport{}
newcli, err = NewDefaultClient(apiURL, "v1", "toto", auth.Client())
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)

View file

@ -9,7 +9,6 @@ import (
"time"
"github.com/crowdsecurity/crowdsec/pkg/cwversion"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)
@ -19,7 +18,7 @@ func TestNewRequestInvalid(t *testing.T) {
//missing slash in uri
apiURL, err := url.Parse(urlx)
if err != nil {
log.Fatalf("parsing api url: %s", apiURL)
t.Fatalf("parsing api url: %s", apiURL)
}
client, err := NewClient(&Config{
MachineID: "test_login",
@ -52,7 +51,7 @@ func TestNewRequestTimeout(t *testing.T) {
//missing slash in uri
apiURL, err := url.Parse(urlx + "/")
if err != nil {
log.Fatalf("parsing api url: %s", apiURL)
t.Fatalf("parsing api url: %s", apiURL)
}
client, err := NewClient(&Config{
MachineID: "test_login",

View file

@ -46,7 +46,7 @@ func TestNewClientOk(t *testing.T) {
defer teardown()
apiURL, err := url.Parse(urlx + "/")
if err != nil {
log.Fatalf("parsing api url: %s", apiURL)
t.Fatalf("parsing api url: %s", apiURL)
}
client, err := NewClient(&Config{
MachineID: "test_login",
@ -83,7 +83,7 @@ func TestNewClientKo(t *testing.T) {
defer teardown()
apiURL, err := url.Parse(urlx + "/")
if err != nil {
log.Fatalf("parsing api url: %s", apiURL)
t.Fatalf("parsing api url: %s", apiURL)
}
client, err := NewClient(&Config{
MachineID: "test_login",
@ -116,7 +116,7 @@ func TestNewDefaultClient(t *testing.T) {
defer teardown()
apiURL, err := url.Parse(urlx + "/")
if err != nil {
log.Fatalf("parsing api url: %s", apiURL)
t.Fatalf("parsing api url: %s", apiURL)
}
client, err := NewDefaultClient(apiURL, "/v1", "", nil)
if err != nil {

View file

@ -36,7 +36,7 @@ func TestDecisionsList(t *testing.T) {
})
apiURL, err := url.Parse(urlx + "/")
if err != nil {
log.Fatalf("parsing api url: %s", apiURL)
t.Fatalf("parsing api url: %s", apiURL)
}
//ok answer
@ -46,7 +46,7 @@ func TestDecisionsList(t *testing.T) {
newcli, err := NewDefaultClient(apiURL, "v1", "toto", auth.Client())
if err != nil {
log.Fatalf("new api client: %s", err)
t.Fatalf("new api client: %s", err)
}
tduration := "3h59m55.756182786s"
@ -77,7 +77,7 @@ func TestDecisionsList(t *testing.T) {
}
if err != nil {
log.Fatalf("new api client: %s", err)
t.Fatalf("new api client: %s", err)
}
if !reflect.DeepEqual(*decisions, *expected) {
t.Fatalf("returned %+v, want %+v", resp, expected)
@ -126,7 +126,7 @@ func TestDecisionsStream(t *testing.T) {
apiURL, err := url.Parse(urlx + "/")
if err != nil {
log.Fatalf("parsing api url: %s", apiURL)
t.Fatalf("parsing api url: %s", apiURL)
}
//ok answer
@ -136,7 +136,7 @@ func TestDecisionsStream(t *testing.T) {
newcli, err := NewDefaultClient(apiURL, "v1", "toto", auth.Client())
if err != nil {
log.Fatalf("new api client: %s", err)
t.Fatalf("new api client: %s", err)
}
tduration := "3h59m55.756182786s"
@ -167,7 +167,7 @@ func TestDecisionsStream(t *testing.T) {
}
if err != nil {
log.Fatalf("new api client: %s", err)
t.Fatalf("new api client: %s", err)
}
if !reflect.DeepEqual(*decisions, *expected) {
t.Fatalf("returned %+v, want %+v", resp, expected)
@ -208,7 +208,7 @@ func TestDeleteDecisions(t *testing.T) {
log.Printf("URL is %s", urlx)
apiURL, err := url.Parse(urlx + "/")
if err != nil {
log.Fatalf("parsing api url: %s", apiURL)
t.Fatalf("parsing api url: %s", apiURL)
}
client, err := NewClient(&Config{
MachineID: "test_login",
@ -219,7 +219,7 @@ func TestDeleteDecisions(t *testing.T) {
})
if err != nil {
log.Fatalf("new api client: %s", err)
t.Fatalf("new api client: %s", err)
}
filters := DecisionsDeleteOpts{IPEquals: new(string)}
@ -315,7 +315,7 @@ func TestDecisionsStreamOpts_addQueryParamsToURL(t *testing.T) {
// log.Printf("URL is %s", urlx)
// apiURL, err := url.Parse(urlx + "/")
// if err != nil {
// log.Fatalf("parsing api url: %s", apiURL)
// t.Fatalf("parsing api url: %s", apiURL)
// }
// client, err := NewClient(&Config{
// MachineID: "test_login",
@ -326,7 +326,7 @@ func TestDecisionsStreamOpts_addQueryParamsToURL(t *testing.T) {
// })
// if err != nil {
// log.Fatalf("new api client: %s", err.Error())
// t.Fatalf("new api client: %s", err.Error())
// }
// filters := DecisionsDeleteOpts{IPEquals: new(string)}