Skip to content

Commit

Permalink
test(logging): addressing feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
KellyMerrick committed Sep 26, 2023
1 parent 29a363e commit 6f49a95
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ require (
github.com/yuin/gopher-lua v1.1.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,8 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down
27 changes: 10 additions & 17 deletions router/middleware/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,11 @@ func TestMiddleware_Logger_Sanitize(t *testing.T) {

func TestMiddleware_Format(t *testing.T) {

wantLabels := "labels.vela"

// setup data, fields, and logger
formatter := &Formatter{
DataKey: "labels.vela",
DataKey: wantLabels,
}

fields := logrus.Fields{
Expand All @@ -248,37 +250,28 @@ func TestMiddleware_Format(t *testing.T) {

got, err := formatter.Format(entry)

wantLabels := "labels.vela"
wantMethod := http.MethodGet
wantOrg := "foo"

fmt.Println("got:", string(got))
// run test
gotLabels := string(formatter.DataKey)
gotMethod := entry.Data["method"]
gotOrg := entry.Data["org"]

if err != nil {
fmt.Println("err:", err.Error())
t.Errorf("Format returned err: %v", err)
}

if got == nil {
t.Errorf("Logger returned nothing, want a log")
t.Errorf("Format returned nothing, want a log")
}

if !reflect.DeepEqual(gotLabels, wantLabels) {
t.Errorf("Logger returned %v, want %v", gotLabels, wantLabels)
}

if !reflect.DeepEqual(wantMethod, gotMethod) {
t.Errorf("Logger returned %v, want %v", gotMethod, wantMethod)
}

if !reflect.DeepEqual(wantMethod, gotMethod) {
t.Errorf("Logger returned %v, want %v", gotMethod, wantMethod)
if !strings.Contains(string(got), "GET") {
t.Errorf("Format returned %v, want to contain GET", string(got))
}

if !reflect.DeepEqual(wantOrg, gotOrg) {
t.Errorf("Logger returned %v, want %v", gotOrg, wantOrg)
if !strings.Contains(string(got), "/foobar") {
t.Errorf("Format returned %v, want to contain GET", string(got))
}

}

0 comments on commit 6f49a95

Please sign in to comment.