From e3e72de1f4dd589820d7b71bbaa27afb6f66131e Mon Sep 17 00:00:00 2001 From: Erik Date: Wed, 19 Apr 2023 14:00:41 +0200 Subject: [PATCH] Add tests for modify and delete --- commands/commands_test.go | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/commands/commands_test.go b/commands/commands_test.go index b14462e..611721c 100644 --- a/commands/commands_test.go +++ b/commands/commands_test.go @@ -12,8 +12,7 @@ import ( func TestCommandCreateJsonParse(t *testing.T) { ip, _ := netip.ParseAddr("127.0.0.99") uuid, _ := uuid.Parse("87e79cbc-6df6-4462-8412-85d6c473e3b1") - c := NewCommandCreate(5555, 6666, ip, state.CustomUUID(uuid)) - m := ProxyCommandCreate{c} + m := NewCommandCreate(5555, 6666, ip, state.CustomUUID(uuid)) msg, err := json.Marshal(m) if err != nil { t.Fatalf(`%q`, err) @@ -26,4 +25,33 @@ func TestCommandCreateJsonParse(t *testing.T) { } } +func TestCommandModifyJsonParse(t *testing.T) { + ip, _ := netip.ParseAddr("127.0.0.99") + uuid, _ := uuid.Parse("87e79cbc-6df6-4462-8412-85d6c473e3b1") + m := NewCommandModify(8888, ip, state.CustomUUID(uuid)) + msg, err := json.Marshal(m) + if err != nil { + t.Fatalf(`%q`, err) + } + expected := "{\"modify\":{\"destination_port\":8888,\"destination_ip\":\"127.0.0.99\",\"id\":\"87e79cbc-6df6-4462-8412-85d6c473e3b1\"}}" + if string(msg) != expected { + t.Fatalf( + "\nExpected:\t %q\nGot:\t\t %q\n", expected, msg) + } +} + +func TestCommandDeleteJsonParse(t *testing.T) { + uuid, _ := uuid.Parse("87e79cbc-6df6-4462-8412-85d6c473e3b1") + m := NewCommandDelete(state.CustomUUID(uuid)) + msg, err := json.Marshal(m) + if err != nil { + t.Fatalf(`%q`, err) + } + + expected := "{\"delete\":{\"id\":\"87e79cbc-6df6-4462-8412-85d6c473e3b1\"}}" + if string(msg) != expected { + t.Fatalf( + "\nExpected:\t %q\nGot:\t\t %q\n", expected, msg) + } +}