MCPcopy Create free account
hub / github.com/ProspectOne/perfops-cli / TestRunPing

Function TestRunPing

cmd/ping_test.go:57–86  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

55}
56
57func TestRunPing(t *testing.T) {
58 testCases := map[string]struct {
59 from string
60 nodeIDs []int
61 ipv6 bool
62 exp string
63 }{
64 "Location": {"From here", []int{}, false, `{"target":"example.com","location":"From here","limit":12,"ipversion":4}`},
65 "NodeID": {"", []int{123}, false, `{"target":"example.com","nodes":"123","limit":12,"ipversion":4}`},
66 "IPv6": {"", []int{}, true, `{"target":"example.com","limit":12,"ipversion":6}`},
67 }
68 // We're only interested in the first HTTP call, e.g., the one to get the test ID
69 // to validate our parameters got passed properly.
70 tr := &recordingTransport{}
71 c, err := newTestPerfopsClient(tr)
72 if err != nil {
73 t.Fatalf("unexpected error %v", err)
74 }
75 for name, tc := range testCases {
76 t.Run(name, func(t *testing.T) {
77 runPing(c, "example.com", tc.from, tc.nodeIDs, 12, tc.ipv6)
78 if got, exp := tr.req.URL.Path, "/run/ping"; got != exp {
79 t.Fatalf("expected %v; got %v", exp, got)
80 }
81 if got, exp := reqBody(tr.req), tc.exp; got != exp {
82 t.Fatalf("expected %v; got %v", exp, got)
83 }
84 })
85 }
86}

Callers

nothing calls this directly

Calls 3

newTestPerfopsClientFunction · 0.85
runPingFunction · 0.85
reqBodyFunction · 0.70

Tested by

no test coverage detected