+54
atproto/data/interop_test.go
+54
atproto/data/interop_test.go
···
78
78
assert.Equal(row.CID, cidFromCBOR.String())
79
79
80
80
}
81
+
82
+
type DataModelSimpleFixture struct {
83
+
JSON json.RawMessage `json:"json"`
84
+
}
85
+
86
+
func TestInteropDataModelValid(t *testing.T) {
87
+
assert := assert.New(t)
88
+
89
+
f, err := os.Open("testdata/data-model-valid.json")
90
+
if err != nil {
91
+
t.Fatal(err)
92
+
}
93
+
defer func() { _ = f.Close() }()
94
+
95
+
fixBytes, err := io.ReadAll(f)
96
+
if err != nil {
97
+
t.Fatal(err)
98
+
}
99
+
100
+
var fixtures []DataModelSimpleFixture
101
+
if err := json.Unmarshal(fixBytes, &fixtures); err != nil {
102
+
t.Fatal(err)
103
+
}
104
+
105
+
for _, row := range fixtures {
106
+
_, err := UnmarshalJSON(row.JSON)
107
+
assert.NoError(err)
108
+
}
109
+
}
110
+
111
+
func TestInteropDataModelInvalid(t *testing.T) {
112
+
assert := assert.New(t)
113
+
114
+
f, err := os.Open("testdata/data-model-invalid.json")
115
+
if err != nil {
116
+
t.Fatal(err)
117
+
}
118
+
defer func() { _ = f.Close() }()
119
+
120
+
fixBytes, err := io.ReadAll(f)
121
+
if err != nil {
122
+
t.Fatal(err)
123
+
}
124
+
125
+
var fixtures []DataModelSimpleFixture
126
+
if err := json.Unmarshal(fixBytes, &fixtures); err != nil {
127
+
t.Fatal(err)
128
+
}
129
+
130
+
for _, row := range fixtures {
131
+
_, err := UnmarshalJSON(row.JSON)
132
+
assert.Error(err)
133
+
}
134
+
}
+121
atproto/data/testdata/data-model-invalid.json
+121
atproto/data/testdata/data-model-invalid.json
···
1
+
[
2
+
{
3
+
"note": "top-level not an object",
4
+
"json": "blah"
5
+
},
6
+
{
7
+
"note": "float",
8
+
"json": {
9
+
"rcrd": {
10
+
"$type": "com.example.blah",
11
+
"a": 123.456,
12
+
"b": "blah"
13
+
}
14
+
}
15
+
},
16
+
{
17
+
"note": "record with $type null",
18
+
"json": {
19
+
"rcrd": {
20
+
"$type": null,
21
+
"a": 123,
22
+
"b": "blah"
23
+
}
24
+
}
25
+
},
26
+
{
27
+
"note": "record with $type wrong type",
28
+
"json": {
29
+
"rcrd": {
30
+
"$type": 123,
31
+
"a": 123,
32
+
"b": "blah"
33
+
}
34
+
}
35
+
},
36
+
{
37
+
"note": "record with empty $type string",
38
+
"json": {
39
+
"rcrd": {
40
+
"$type": "",
41
+
"a": 123,
42
+
"b": "blah"
43
+
}
44
+
}
45
+
},
46
+
{
47
+
"note": "blob with string size",
48
+
"json": {
49
+
"blb": {
50
+
"$type": "blob",
51
+
"ref": {
52
+
"$link": "bafkreiccldh766hwcnuxnf2wh6jgzepf2nlu2lvcllt63eww5p6chi4ity"
53
+
},
54
+
"mimeType": "image/jpeg",
55
+
"size": "10000"
56
+
}
57
+
}
58
+
},
59
+
{
60
+
"note": "blob with missing key",
61
+
"json": {
62
+
"blb": {
63
+
"$type": "blob",
64
+
"mimeType": "image/jpeg",
65
+
"size": 10000
66
+
}
67
+
}
68
+
},
69
+
{
70
+
"note": "bytes with wrong field type",
71
+
"json": {
72
+
"lnk": {
73
+
"$bytes": [1,2,3]
74
+
}
75
+
}
76
+
},
77
+
{
78
+
"note": "bytes with extra fields",
79
+
"json": {
80
+
"lnk": {
81
+
"$bytes": "nFERjvLLiw9qm45JrqH9QTzyC2Lu1Xb4ne6+sBrCzI0",
82
+
"other": "blah"
83
+
}
84
+
}
85
+
},
86
+
{
87
+
"note": "link with wrong field type",
88
+
"json": {
89
+
"lnk": {
90
+
"$link": 1234
91
+
}
92
+
}
93
+
},
94
+
{
95
+
"note": "link with bogus CID",
96
+
"json": {
97
+
"lnk": {
98
+
"$link": "."
99
+
}
100
+
}
101
+
},
102
+
{
103
+
"note": "link with extra fields",
104
+
"json": {
105
+
"lnk": {
106
+
"$link": "bafkreiccldh766hwcnuxnf2wh6jgzepf2nlu2lvcllt63eww5p6chi4ity",
107
+
"other": "blah"
108
+
}
109
+
}
110
+
},
111
+
{
112
+
"note": "inconsistent types in array",
113
+
"json": {
114
+
"obj": [
115
+
"one",
116
+
2,
117
+
false
118
+
]
119
+
}
120
+
}
121
+
]
+48
atproto/data/testdata/data-model-valid.json
+48
atproto/data/testdata/data-model-valid.json
···
1
+
[
2
+
{
3
+
"note": "trivial record",
4
+
"json": {
5
+
"rcrd": {
6
+
"$type": "com.example.blah",
7
+
"a": 123,
8
+
"b": "blah"
9
+
}
10
+
}
11
+
},
12
+
{
13
+
"note": "float, but integer-like",
14
+
"json": {
15
+
"rcrd": {
16
+
"$type": "com.example.blah",
17
+
"a": 123.0,
18
+
"b": "blah"
19
+
}
20
+
}
21
+
},
22
+
{
23
+
"note": "empty list and object",
24
+
"json": {
25
+
"rcrd": {
26
+
"$type": "com.example.blah",
27
+
"a": [],
28
+
"b": {}
29
+
}
30
+
}
31
+
},
32
+
{
33
+
"note": "list of nullable",
34
+
"json": {
35
+
"arr": [1,2,null]
36
+
}
37
+
},
38
+
{
39
+
"note": "list of lists",
40
+
"json": {
41
+
"arr": [
42
+
[1,2,3],
43
+
[4,5,6]
44
+
],
45
+
"arr2": [null, null, null]
46
+
}
47
+
}
48
+
]