Initial cloud-services repo - gateway service + pkg modules

This commit is contained in:
Chris Rai
2026-01-30 23:14:52 -05:00
commit fbb820d7b3
1037 changed files with 171318 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
package common_test
import (
"encoding/json"
"testing"
"fiskerinc.com/modules/common"
"fiskerinc.com/modules/testhelper"
)
type testHexBinary struct {
Data *common.BinaryHex `json:"data"`
}
func TestBinaryHexMarshalJSON(t *testing.T) {
expected := `"0000ffff"`
value := common.BinaryHex{00, 00, 0xff, 0xff}
json, err := value.MarshalJSON()
testhelper.NoError(t, "MarshalJSON error", err)
testhelper.Equal(t, "MarshalJSON json", expected, string(json))
}
func TestBinaryHexUnmarshalJSON(t *testing.T) {
expected := []byte{00, 00, 0xff, 0xff}
value := common.BinaryHex{}
err := value.UnmarshalJSON([]byte(`"0000ffff"`))
testhelper.NoError(t, "UnmarshalJSON error", err)
testhelper.EqualByteArray(t, "UnmarshalJSON len", expected, value)
}
func TestBinaryHexStructMarshalJSON(t *testing.T) {
expected := `{"data":"0000ffff"}`
value := testHexBinary{Data: &common.BinaryHex{00, 00, 0xff, 0xff}}
json, err := json.Marshal(value)
testhelper.NoError(t, "MarshalJSON error", err)
testhelper.Equal(t, "MarshalJSON json", expected, string(json))
}
func TestBinaryHexStructUnmarshalJSON(t *testing.T) {
obj := testHexBinary{}
data := `{"data":"0e00ffff"}`
expected := []byte{0x0e, 00, 0xff, 0xff}
err := json.Unmarshal([]byte(data), &obj)
testhelper.NoError(t, "UnmarshalJSON error", err)
testhelper.EqualByteArray(t, "UnmarshalJSON json", *obj.Data, expected)
}