From f3a02a8d1378b6fc275e8b4b68dc7350db748dc0 Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Wed, 5 Aug 2015 08:44:48 -0600 Subject: [PATCH] update tests --- audit/format_json_test.go | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/audit/format_json_test.go b/audit/format_json_test.go index 88e1df0901..a3f8270a3d 100644 --- a/audit/format_json_test.go +++ b/audit/format_json_test.go @@ -2,7 +2,9 @@ package audit import ( "bytes" + "strings" "testing" + "encoding/json" "github.com/hashicorp/vault/logical" "errors" @@ -36,13 +38,30 @@ func TestFormatJSON_formatRequest(t *testing.T) { t.Fatalf("bad: %s\nerr: %s", name, err) } - if buf.String() != tc.Result { + var expectedjson = new(JSONRequestEntry) + if err := json.Unmarshal([]byte(tc.Result), &expectedjson); err != nil { + t.Fatalf("bad json: %s", err) + } + + var actualjson = new(JSONRequestEntry) + if err := json.Unmarshal([]byte(buf.String()), &actualjson); err != nil { + t.Fatalf("bad json: %s", err) + } + + expectedjson.Time = actualjson.Time + + expectedBytes, err := json.Marshal(expectedjson) + if err != nil { + t.Fatalf("unable to marshal json: %s", err) + } + + if strings.TrimSpace(buf.String()) != string(expectedBytes) { t.Fatalf( - "bad: %s\nResult:\n\n%s\n\nExpected:\n\n%s", - name, buf.String(), tc.Result) + "bad: %s\nResult:\n\n'%s'\n\nExpected:\n\n'%s'", + name, buf.String(), string(expectedBytes)) } } } -const testFormatJSONReqBasicStr = `{"type":"request","auth":{"display_name":"","policies":["root"],"metadata":null},"request":{"operation":"write","path":"/foo","data":null,"remote_address":"127.0.0.1"},"error":"this is an error"} +const testFormatJSONReqBasicStr = `{"time":"2015-08-05T13:45:46Z","type":"request","auth":{"display_name":"","policies":["root"],"metadata":null},"request":{"operation":"write","path":"/foo","data":null,"remote_address":"127.0.0.1"},"error":"this is an error"} `