-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserializer_test.go
More file actions
43 lines (31 loc) · 877 Bytes
/
serializer_test.go
File metadata and controls
43 lines (31 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package llmberjack
import (
"io"
"testing"
"github.com/stretchr/testify/assert"
)
func TestJsonSerializer(t *testing.T) {
type j struct {
Output string `json:"output"`
}
data := j{"Hello, world!"}
req := NewUntypedRequest().WithSerializable(RoleUser, Serializers.Json, data)
assert.Nil(t, req.err)
assert.Len(t, req.Messages, 1)
out, err := io.ReadAll(req.Messages[0].Parts[0])
assert.Nil(t, err)
assert.JSONEq(t, `{"output":"Hello, world!"}`, string(out))
}
func TestCsvSerializer(t *testing.T) {
data := [][]string{
{"one", "two"},
{"three", "four"},
{"five", "six"},
}
req := NewUntypedRequest().WithSerializable(RoleUser, Serializers.Csv, data)
assert.Nil(t, req.err)
assert.Len(t, req.Messages, 1)
out, err := io.ReadAll(req.Messages[0].Parts[0])
assert.Nil(t, err)
assert.Equal(t, "one,two\nthree,four\nfive,six\n", string(out))
}