use as subtest func, to run single ones
package server_test
import (
- "fmt"
"net/http"
"reflect"
"testing"
"time"
- "github.com/avenga/couper/internal/test"
"github.com/google/go-cmp/cmp"
"github.com/sirupsen/logrus"
+
+ "github.com/avenga/couper/internal/test"
)
func TestCustomLogs_Upstream(t *testing.T) {
- client := newClient()
- helper := test.New(t)
+ client := test.NewHTTPClient()
shutdown, hook := newCouper("testdata/integration/logs/01_couper.hcl", test.New(t))
defer shutdown()
@@ -64,6 +63,8 @@ func TestCustomLogs_Upstream(t *testing.T) {
logrus.Fields{"backend": string("couper test-backend")},
},
} {
+ t.Run(tc.path, func(st *testing.T) {
+ helper := test.New(st)
req, err := http.NewRequest(http.MethodGet, "http://localhost:8080"+tc.path, nil)
helper.Must(err)
@@ -77,24 +78,28 @@ func TestCustomLogs_Upstream(t *testing.T) {
time.Sleep(200 * time.Millisecond)
// Access log
- got, ok := hook.AllEntries()[1].Data["custom"].(logrus.Fields)
+ entries := hook.AllEntries()
+ if len(entries) < 2 {
+ st.Fatal("Expected logs, got nothing")
+ }
+
+ got, ok := entries[1].Data["custom"].(logrus.Fields)
if !ok {
- t.Fatalf("expected\n%#v\ngot\n%#v", tc.expAL, got)
+ st.Fatalf("expected\n%#v\ngot\n%#v", tc.expAL, got)
}
if !reflect.DeepEqual(tc.expAL, got) {
- t.Errorf("expected\n%#v\ngot\n%#v", tc.expAL, got)
+ st.Errorf("expected\n%#v\ngot\n%#v", tc.expAL, got)
}
// Upstream log
- got, ok = hook.AllEntries()[0].Data["custom"].(logrus.Fields)
+ got, ok = entries[0].Data["custom"].(logrus.Fields)
if !ok {
- t.Fatalf("expected\n%#v\ngot\n%#v", tc.expUL, got)
+ st.Fatalf("expected\n%#v\ngot\n%#v", tc.expUL, got)
}
if !cmp.Equal(tc.expUL, got) {
- t.Fail()
-
- fmt.Println(cmp.Diff(tc.expUL, got))
+ st.Error(cmp.Diff(tc.expUL, got))
}
+ })
}
}
