Files
moby/client/internal/json-stream_test.go
Nicolas De Loof df506c107e negociate content-type used by /events API
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2025-10-03 20:27:42 +02:00

30 lines
659 B
Go

package internal
import (
"fmt"
"strings"
"testing"
"github.com/moby/moby/api/types"
"gotest.tools/v3/assert"
)
func Test_JsonSeqDecoder(t *testing.T) {
separator := string(rune(rs))
lf := "\n"
input := fmt.Sprintf(`%s{"hello":"world"}%s%s{ "hello": "again" }%s`, separator, lf, separator, lf)
decoder := NewJSONStreamDecoder(strings.NewReader(input), types.MediaTypeJSONSequence)
type Hello struct {
Hello string `json:"hello"`
}
var hello Hello
err := decoder(&hello)
assert.NilError(t, err)
assert.Equal(t, "world", hello.Hello)
var again Hello
err = decoder(&again)
assert.NilError(t, err)
assert.Equal(t, "again", again.Hello)
}