✅ Added first package test
This commit is contained in:
parent
aaaf52cbb8
commit
d64a46a1d4
2
go.mod
2
go.mod
|
@ -6,3 +6,5 @@ require (
|
|||
golang.org/x/net v0.18.0
|
||||
golang.org/x/text v0.14.0
|
||||
)
|
||||
|
||||
require github.com/google/go-cmp v0.6.0 // indirect
|
||||
|
|
2
go.sum
2
go.sum
|
@ -1,3 +1,5 @@
|
|||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
|
||||
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue