feat: establish Orbit models, migrations and development baseline
This commit is contained in:
51
model/primitives_test.go
Normal file
51
model/primitives_test.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestIDBinaryAndJSONRoundTrip(t *testing.T) {
|
||||
id, err := NewID()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
binary, err := id.Value()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var copy ID
|
||||
if err := copy.Scan(binary); err != nil || copy != id {
|
||||
t.Fatalf("binary roundtrip: %s %v", copy, err)
|
||||
}
|
||||
b, err := json.Marshal(id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := json.Unmarshal(b, ©); err != nil || copy != id {
|
||||
t.Fatalf("JSON roundtrip: %s %v", copy, err)
|
||||
}
|
||||
if err := json.Unmarshal([]byte(`"0123"`), ©); err == nil {
|
||||
t.Fatal("accepted truncated ID")
|
||||
}
|
||||
if _, err := ID("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").Value(); err == nil {
|
||||
t.Fatal("accepted case-folded ID")
|
||||
}
|
||||
if err := copy.Scan([]byte{1}); err == nil {
|
||||
t.Fatal("accepted truncated binary ID")
|
||||
}
|
||||
}
|
||||
func TestJSONScanOwnsBytes(t *testing.T) {
|
||||
src := []byte(`{"ok":true}`)
|
||||
var doc JSON
|
||||
if err := doc.Scan(src); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
src[2] = 'x'
|
||||
if string(doc) != `{"ok":true}` {
|
||||
t.Fatal("document aliases driver buffer")
|
||||
}
|
||||
if _, err := JSON(`{broken`).Value(); err == nil {
|
||||
t.Fatal("accepted invalid JSON")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user