good morning!!!!

Skip to content
Snippets Groups Projects
Verified Commit 1a4aa37e authored by a's avatar a
Browse files

v2

parent a5ca8736
Branches
Tags
1 merge request!15Draft: V2
...@@ -112,7 +112,7 @@ func (id *ID) RawMessage() json.RawMessage { ...@@ -112,7 +112,7 @@ func (id *ID) RawMessage() json.RawMessage {
} }
// MarshalJSON implements json.Marshaler. // MarshalJSON implements json.Marshaler.
func (id *ID) MarshalJSON() ([]byte, error) { func (id ID) MarshalJSON() ([]byte, error) {
return id.RawMessage(), nil return id.RawMessage(), nil
} }
......
package codec
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
)
func TestVersion(t *testing.T) {
var v Version
t.Run("encoding", func(t *testing.T) {
ans, err := json.Marshal(v)
assert.NoError(t, err)
assert.Equal(t, []byte(`"2.0"`), ans)
})
t.Run("decoding", func(t *testing.T) {
err := json.Unmarshal([]byte(`"2.0"`), &v)
assert.NoError(t, err)
err = json.Unmarshal([]byte("not"), &v)
assert.Error(t, err)
})
}
func TestID(t *testing.T) {
var v ID
t.Run("number", func(t *testing.T) {
v = NewNumberID(2)
ans, err := json.Marshal(v)
assert.NoError(t, err)
assert.Equal(t, `2`, string(ans))
})
t.Run("numberstring", func(t *testing.T) {
v = NewStringID("2")
ans, err := json.Marshal(v)
assert.NoError(t, err)
assert.Equal(t, `"2"`, string(ans))
})
t.Run("string", func(t *testing.T) {
v = NewStringID("doggo")
ans, err := json.Marshal(v)
assert.NoError(t, err)
assert.Equal(t, `"doggo"`, string(ans))
})
t.Run("null", func(t *testing.T) {
v = NewNullID()
ans, err := json.Marshal(v)
assert.NoError(t, err)
assert.Equal(t, `null`, string(ans))
})
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment