Files
commerce/test/util/json/json_test.go
zeekay 1943f1c093 Hanzo Commerce
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans,
usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0.

Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
2026-09-23 21:52:16 -07:00

50 lines
928 B
Go

package test
import (
"bytes"
"testing"
"github.com/hanzoai/commerce/util/json"
. "github.com/hanzoai/commerce/util/test/ginkgo"
)
func Test(t *testing.T) {
Setup("util/json", t)
}
type Cart struct {
Codes []string
}
type ReadCloser struct {
*bytes.Buffer
}
func (cb *ReadCloser) Close() error {
return nil
}
var _ = Describe("json.EncodeBytes", func() {
It("Should be able to decode JSON", func() {
car := Cart{[]string{"A", "B", "C"}}
b := json.EncodeBytes(car)
json.DecodeBytes(b, &car)
json.DecodeBytes(b, &car)
json.DecodeBytes(b, &car)
Expect(len(car.Codes)).To(Equal(3))
})
})
var _ = Describe("json.Encode", func() {
It("Should be able to decode JSON", func() {
car := Cart{[]string{"A", "B", "C"}}
s := json.Encode(car)
cb := &ReadCloser{bytes.NewBufferString(s)}
json.Decode(cb, &car)
json.Decode(cb, &car)
json.Decode(cb, &car)
Expect(len(car.Codes)).To(Equal(3))
})
})