Skip to content

Commit

Permalink
test for creating log fields for form body, cookies or headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Koch committed Jul 5, 2022
1 parent 11a7d56 commit 8897979
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions internal/seetie/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package seetie

import (
"fmt"
"net/http"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/sirupsen/logrus"
"github.com/zclconf/go-cty/cty"
)

Expand Down Expand Up @@ -37,3 +40,36 @@ func Test_stringListToValue(t *testing.T) {
})
}
}

func Test_ValueToLogFields(t *testing.T) {
type testCase struct {
name string
val cty.Value
expLog logrus.Fields
}
for _, tc := range []testCase{
{
name: "form body",
val: ValuesMapToValue(map[string][]string{"a": []string{"b"}}),
expLog: logrus.Fields{"v": logrus.Fields{"a": []interface{}{"b"}}},
},
{
name: "cookies",
val: CookiesToMapValue([]*http.Cookie{&http.Cookie{Name: "c", Value: "d"}}),
expLog: logrus.Fields{"v": logrus.Fields{"c": "d"}},
},
{
name: "headers",
val: HeaderToMapValue(http.Header{"c": []string{"d"}}),
expLog: logrus.Fields{"v": logrus.Fields{"c": "d"}},
},
} {
t.Run(tc.name, func(subT *testing.T) {
logs := cty.MapVal(map[string]cty.Value{"v": tc.val})
lf := ValueToLogFields(logs)
if !cmp.Equal(tc.expLog, lf) {
t.Errorf("Expected\n%#v, got:\n%#v", tc.expLog, lf)
}
})
}
}

0 comments on commit 8897979

Please sign in to comment.