+41
testing/feedpost_test.go
+41
testing/feedpost_test.go
···
146
146
147
147
fmt.Println(string(outb))
148
148
}
149
+
150
+
// checks a corner-case with $type: "app.bsky.richtext.facet#link"
151
+
func TestFeedPostRichtextLink(t *testing.T) {
152
+
assert := assert.New(t)
153
+
cidBuilder := cid.V1Builder{0x71, 0x12, 0}
154
+
155
+
// this is a app.bsky.feed.post with richtext link
156
+
inFile, err := os.Open("testdata/post_richtext_link.cbor")
157
+
if err != nil {
158
+
t.Fatal(err)
159
+
}
160
+
cborBytes, err := io.ReadAll(inFile)
161
+
if err != nil {
162
+
t.Fatal(err)
163
+
}
164
+
fmt.Println("=== typescript CBOR bytes (hex)")
165
+
fmt.Println(hex.EncodeToString(cborBytes))
166
+
origCID, err := cidBuilder.Sum(cborBytes)
167
+
if err != nil {
168
+
t.Fatal(err)
169
+
}
170
+
171
+
recordCBOR := new(bytes.Buffer)
172
+
var recordOrig appbsky.FeedPost
173
+
var recordRepro appbsky.FeedPost
174
+
assert.NoError(recordOrig.UnmarshalCBOR(bytes.NewReader(cborBytes)))
175
+
assert.Equal("app.bsky.feed.post", recordOrig.LexiconTypeID)
176
+
177
+
recordJSON, err := json.Marshal(recordOrig)
178
+
fmt.Println(string(recordJSON))
179
+
assert.NoError(err)
180
+
assert.NoError(json.Unmarshal(recordJSON, &recordRepro))
181
+
assert.Equal(recordOrig, recordRepro)
182
+
assert.NoError(recordRepro.MarshalCBOR(recordCBOR))
183
+
fmt.Println("=== golang cbor-gen bytes (hex)")
184
+
fmt.Println(hex.EncodeToString(recordCBOR.Bytes()))
185
+
reproCID, err := cidBuilder.Sum(recordCBOR.Bytes())
186
+
assert.NoError(err)
187
+
assert.Equal(origCID.String(), reproCID.String())
188
+
189
+
}
testing/testdata/post_richtext_link.cbor
testing/testdata/post_richtext_link.cbor
This is a binary file and will not be displayed.