2023-05-19 21:57:05 +00:00
|
|
|
|
|
|
|
package skylab
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"encoding/json"
|
|
|
|
)
|
|
|
|
|
|
|
|
{{ range .Packets }}
|
|
|
|
{{- $structName := camelCase .Name true}}
|
|
|
|
func TestMarshalUnmarshal{{$structName}}(t *testing.T) {
|
|
|
|
v := &{{$structName}}{}
|
|
|
|
bin, err := v.MarshalPacket()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
err = v.UnmarshalPacket(bin)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestJSON{{$structName}}(t *testing.T) {
|
|
|
|
|
|
|
|
v := &{{$structName}}{}
|
|
|
|
|
2023-05-29 00:39:03 +00:00
|
|
|
rawData, err := json.Marshal(v)
|
2023-05-19 21:57:05 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2024-02-28 07:07:28 +00:00
|
|
|
p, err := FromJson(v.String(), rawData)
|
2023-05-19 21:57:05 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch underlying := p.(type) {
|
|
|
|
case *{{$structName}}:
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
t.Fatalf("didn't match type: %T, %v", underlying, underlying)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
{{- end }}
|