1
0
Fork 0
jf2/jf2_test.go

65 lines
1.3 KiB
Go

package jf2_test
import (
"encoding/json"
"os"
"path/filepath"
"testing"
"github.com/google/go-cmp/cmp"
"source.toby3d.me/toby3d/jf2"
)
func TestJF2_01(t *testing.T) {
t.Parallel()
type (
Author struct {
Type jf2.Type `json:"type"`
Name string `json:"name"`
URL string `json:"url"`
Photo string `json:"photo"`
}
Object struct {
Type jf2.Type `json:"type"`
Published string `json:"published"`
URL string `json:"url"`
Author Author `json:"author"`
Name string `json:"name"`
Content string `json:"content"`
Category string `json:"category"`
}
)
expect := &Object{
Type: jf2.TypeEntry,
Published: "2015-10-20T15:49:00-0700",
URL: "http://example.com/post/fsjeuu8372",
Name: "Hello World",
Content: "This is a blog post",
Category: "Posts",
Author: Author{
Type: jf2.TypeCard,
Name: "Alice",
URL: "http://alice.example.com",
Photo: "http://alice.example.com/photo.jpg",
},
}
data, err := os.ReadFile(filepath.Join(".", "testdata", "spec-ex-01.json"))
if err != nil {
t.Fatal(err)
}
actual := new(Object)
if err := json.Unmarshal(data, actual); err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(actual, expect, cmp.AllowUnexported(jf2.Type{})); diff != "" {
t.Error(diff)
}
}