Start on testing infra for command to JSON serialization
This commit is contained in:
parent
47feb73cdf
commit
417c8887b9
@ -1 +0,0 @@
|
||||
|
||||
@ -113,7 +113,11 @@ def create_go_filter(packages: List[str], *names: str) -> str:
|
||||
if not go:
|
||||
return ''
|
||||
all_tests = set()
|
||||
for line in subprocess.check_output(f'{go} test -list .'.split() + packages).decode().splitlines():
|
||||
try:
|
||||
lines = subprocess.check_output(f'{go} test -list .'.split() + packages).decode().splitlines()
|
||||
except subprocess.CalledProcessError as e:
|
||||
raise SystemExit(e.returncode)
|
||||
for line in lines:
|
||||
if line.startswith('Test'):
|
||||
all_tests.add(line[4:])
|
||||
tests = set(names) & all_tests
|
||||
|
||||
@ -19,6 +19,8 @@ import (
|
||||
"kitty/tools/utils"
|
||||
)
|
||||
|
||||
var ProtocolVersion [3]int = [3]int{0, 20, 0}
|
||||
|
||||
func add_bool_set(cmd *cobra.Command, name string, short string, usage string) *bool {
|
||||
if short == "" {
|
||||
return cmd.Flags().Bool(name, false, usage)
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -24,19 +24,37 @@ type CMD_NAME_json_type struct {
|
||||
|
||||
var CMD_NAME_json CMD_NAME_json_type
|
||||
|
||||
func create_payload_CMD_NAME(args []string) (payload map[string]interface{}, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func create_rc_CMD_NAME(args []string) (*utils.RemoteControlCmd, error) {
|
||||
var err error
|
||||
payload, err := create_payload_CMD_NAME(args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rc := utils.RemoteControlCmd{
|
||||
Cmd: "CLI_NAME",
|
||||
Version: ProtocolVersion,
|
||||
NoResponse: NO_RESPONSE_BASE,
|
||||
Payload: payload,
|
||||
}
|
||||
return &rc, nil
|
||||
}
|
||||
|
||||
func run_CMD_NAME(cmd *cobra.Command, args []string) (err error) {
|
||||
SET_OPTION_VALUES_CODE
|
||||
|
||||
rc := utils.RemoteControlCmd{
|
||||
Cmd: "CLI_NAME",
|
||||
Version: [3]int{0, 20, 0},
|
||||
NoResponse: NO_RESPONSE_BASE,
|
||||
rc, err := create_rc_CMD_NAME(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
nrv, err := cmd.Flags().GetBool("no-response")
|
||||
if err == nil {
|
||||
rc.NoResponse = nrv
|
||||
}
|
||||
err = send_rc_command(&rc, WAIT_TIMEOUT)
|
||||
err = send_rc_command(rc, WAIT_TIMEOUT)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user