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"`
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"`

View File

@ -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 <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{}
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)
}

View File

@ -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"
}