Start on testing infra for command to JSON serialization

This commit is contained in:
Kovid Goyal
2022-08-17 22:37:03 +05:30
parent 47feb73cdf
commit 417c8887b9
5 changed files with 57 additions and 7 deletions

View File

@@ -2,11 +2,38 @@ package at
import (
"encoding/json"
"fmt"
"kitty/tools/crypto"
"kitty/tools/utils"
"testing"
)
func TestCommandToJSON(t *testing.T) {
pv := fmt.Sprint(ProtocolVersion[0], ",", ProtocolVersion[1], ",", ProtocolVersion[2])
rc, err := create_rc_ls([]string{})
if err != nil {
t.Fatal(err)
}
marshal := func(rc *utils.RemoteControlCmd) string {
q, err := json.Marshal(rc)
if err != nil {
t.Fatal(err)
}
return string(q)
}
test := func(rc *utils.RemoteControlCmd, rest string) {
q := marshal(rc)
expected := `{"cmd":"` + rc.Cmd + `","version":[` + pv + `]`
expected += rest + "}"
if q != expected {
t.Fatalf("expected != actual: %#v != %#v", expected, q)
}
}
test(rc, "")
}
func TestRCSerialization(t *testing.T) {
serializer, err := create_serializer("", "")
if err != nil {