From a2543d19846dbf5df1bc5556409b4abc7887e6d7 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Thu, 25 Apr 2024 07:14:45 -0600 Subject: [PATCH] got: switch Date to int --- got.go | 2 +- got_test.go | 13 ++++++++----- test_body.json | 6 +++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/got.go b/got.go index 3f2fb37..2c0f965 100644 --- a/got.go +++ b/got.go @@ -45,7 +45,7 @@ type Notification struct { ID string `json:"id"` Author Author `json:"author,omitempty"` Committer Committer `json:"committer"` - Date string `json:"date"` + Date int `json:"date"` ShortMessage string `json:"short_message"` Message string `json:"message"` Diffstat Diffstat `json:"diffstat,omitempty"` diff --git a/got_test.go b/got_test.go index 773d73f..1bd28ca 100644 --- a/got_test.go +++ b/got_test.go @@ -1,19 +1,22 @@ package main import ( + "bytes" "encoding/json" "fmt" - "strings" + "os" "testing" ) func TestGotNotification(t *testing.T) { - jsonStr := `{"notifications":[{"type":"commit", "short":false, "repo":"test-repo", "id":"34d7c970d4bd3a5832ecded86f2c28e83dbba2ba", "author":{ "full":"Flan Hacker ", "name":"Flan Hacker", "mail":"flan@openbsd.org", "user":"flan" }, "committer":{ "full":"Flan Hacker ", "name":"Flan Hacker", "mail":"flan@openbsd.org", "user":"flan" }, "date":"Thu Apr 18 16:47:40 2024 UTC", "short_message":"make changes", "message":"make changes\n", "diffstat":{ "files":[{ "action":"modified", "file":"alpha", "added":1, "removed":1 }], "total":{ "added":1, "removed":1 } }}]}` + jsonData, err := os.ReadFile("test_body.json") + if err != nil { + t.Fatal(err) + } nots := &GotNotifications{} - dec := json.NewDecoder(strings.NewReader(jsonStr)) - err := dec.Decode(nots) - + dec := json.NewDecoder(bytes.NewReader(jsonData)) + err = dec.Decode(nots) if err != nil { t.Fatal(err) } diff --git a/test_body.json b/test_body.json index 1937a22..bb99528 100644 --- a/test_body.json +++ b/test_body.json @@ -17,7 +17,7 @@ "mail": "flan@openbsd.org", "user": "flan" }, - "date": "Thu Apr 18 16:47:40 2024 UTC", + "date": 1714041300, "short_message": "make changes", "message": "make changes\n", "diffstat": { @@ -52,7 +52,7 @@ "mail": "flans@openbsd.org", "user": "flans" }, - "date": "Thu Apr 18 16:48:40 2024 UTC", + "date": 1714041301, "short_message": "make more changes", "message": "make more changes\n", "diffstat": { @@ -81,7 +81,7 @@ "mail": "flans@openbsd.org", "user": "flans" }, - "date": "Thu Apr 19 16:48:40 2024 UTC", + "date": 1714041302, "short_message": "revert changes", "message": "revert all the previous changes\n" }