got: switch Date to int

This commit is contained in:
Aaron Bieber 2024-04-25 07:14:45 -06:00
parent e34a9e4cd8
commit a2543d1984
No known key found for this signature in database
3 changed files with 12 additions and 9 deletions

2
got.go
View File

@ -45,7 +45,7 @@ type Notification struct {
ID string `json:"id"` ID string `json:"id"`
Author Author `json:"author,omitempty"` Author Author `json:"author,omitempty"`
Committer Committer `json:"committer"` Committer Committer `json:"committer"`
Date string `json:"date"` Date int `json:"date"`
ShortMessage string `json:"short_message"` ShortMessage string `json:"short_message"`
Message string `json:"message"` Message string `json:"message"`
Diffstat Diffstat `json:"diffstat,omitempty"` Diffstat Diffstat `json:"diffstat,omitempty"`

View File

@ -1,19 +1,22 @@
package main package main
import ( import (
"bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"strings" "os"
"testing" "testing"
) )
func TestGotNotification(t *testing.T) { func TestGotNotification(t *testing.T) {
jsonStr := `{"notifications":[{"type":"commit", "short":false, "repo":"test-repo", "id":"34d7c970d4bd3a5832ecded86f2c28e83dbba2ba", "author":{ "full":"Flan Hacker <flan@openbsd.org>", "name":"Flan Hacker", "mail":"flan@openbsd.org", "user":"flan" }, "committer":{ "full":"Flan Hacker <flan@openbsd.org>", "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{} nots := &GotNotifications{}
dec := json.NewDecoder(strings.NewReader(jsonStr)) dec := json.NewDecoder(bytes.NewReader(jsonData))
err := dec.Decode(nots) err = dec.Decode(nots)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -17,7 +17,7 @@
"mail": "flan@openbsd.org", "mail": "flan@openbsd.org",
"user": "flan" "user": "flan"
}, },
"date": "Thu Apr 18 16:47:40 2024 UTC", "date": 1714041300,
"short_message": "make changes", "short_message": "make changes",
"message": "make changes\n", "message": "make changes\n",
"diffstat": { "diffstat": {
@ -52,7 +52,7 @@
"mail": "flans@openbsd.org", "mail": "flans@openbsd.org",
"user": "flans" "user": "flans"
}, },
"date": "Thu Apr 18 16:48:40 2024 UTC", "date": 1714041301,
"short_message": "make more changes", "short_message": "make more changes",
"message": "make more changes\n", "message": "make more changes\n",
"diffstat": { "diffstat": {
@ -81,7 +81,7 @@
"mail": "flans@openbsd.org", "mail": "flans@openbsd.org",
"user": "flans" "user": "flans"
}, },
"date": "Thu Apr 19 16:48:40 2024 UTC", "date": 1714041302,
"short_message": "revert changes", "short_message": "revert changes",
"message": "revert all the previous changes\n" "message": "revert all the previous changes\n"
} }