mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
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
50 lines
928 B
Go
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))
|
|
})
|
|
})
|