gotelem/skylab/templates/golang_tests.go.tmpl
saji d6cd4d3e26
Some checks failed
Go / build (push) Failing after 1m45s
fix tests, add packets stuff for db
2024-02-28 01:07:36 -06:00

48 lines
713 B
Cheetah

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}}{}
rawData, err := json.Marshal(v)
if err != nil {
t.Fatal(err)
}
p, err := FromJson(v.String(), rawData)
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 }}