Skip to content

Commit

Permalink
chore(cbor): add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
imsk17 committed Oct 19, 2024
1 parent 75f24a9 commit ee26b4f
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions cbor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,69 @@ func Test_DefaultCBORDecoder(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "Hello World", ss.ImportantString)
}

func Test_DefaultCBOREncoderWithEmptyString(t *testing.T) {
t.Parallel()

var (
ss = &sampleStructure{
ImportantString: "",
}
importantString = `a170696d706f7274616e745f737472696e6760`
cborEncoder CBORMarshal = cbor.Marshal
)

raw, err := cborEncoder(ss)
require.NoError(t, err)

require.Equal(t, hex.EncodeToString(raw), importantString)
}

func Test_DefaultCBORDecoderWithEmptyString(t *testing.T) {
t.Parallel()

var (
ss sampleStructure
importantString, err = hex.DecodeString("a170696d706f7274616e745f737472696e6760")
cborDecoder CBORUnmarshal = cbor.Unmarshal
)
if err != nil {
t.Error("Failed to decode hex string")
}

err = cborDecoder(importantString, &ss)
require.NoError(t, err)
require.Equal(t, "", ss.ImportantString)
}

func Test_DefaultCBOREncoderWithUnitializedStruct(t *testing.T) {
t.Parallel()

var (
ss sampleStructure
importantString = `a170696d706f7274616e745f737472696e6760`
cborEncoder CBORMarshal = cbor.Marshal
)

raw, err := cborEncoder(ss)
require.NoError(t, err)

require.Equal(t, hex.EncodeToString(raw), importantString)
}

func Test_DefaultCBORDecoderWithUnitializedStruct(t *testing.T) {
t.Parallel()

var (
ss sampleStructure
importantString, err = hex.DecodeString("a170696d706f7274616e745f737472696e6760")
cborDecoder CBORUnmarshal = cbor.Unmarshal
)
if err != nil {
t.Error("Failed to decode hex string")
}

err = cborDecoder(importantString, &ss)
require.NoError(t, err)
require.Equal(t, ss, ss)

Check failure on line 108 in cbor_test.go

View workflow job for this annotation

GitHub Actions / lint

useless-assert: asserting of the same variable (testifylint)
}

0 comments on commit ee26b4f

Please sign in to comment.