From a374db1f8bf86a5c98a7d1ffe521ec46d4be35c4 Mon Sep 17 00:00:00 2001 From: Simeng He Date: Fri, 21 May 2021 10:51:16 -0400 Subject: [PATCH] Starting an integration test --- tstest/integration/integration_test.go | 27 +++++++++++++++++++ tstest/integration/testcontrol/testcontrol.go | 7 ++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/tstest/integration/integration_test.go b/tstest/integration/integration_test.go index 4a6fb0290..d9e0de8fa 100644 --- a/tstest/integration/integration_test.go +++ b/tstest/integration/integration_test.go @@ -757,9 +757,36 @@ func TestTwoNodePing(t *testing.T) { // Tests if our addPingRequest function works func TestAddPingRequest(t *testing.T) { + } // Test such that we can simulate the ping instead of hardcoding in the map response func TestControlSelectivePing(t *testing.T) { + t.Parallel() + bins := buildTestBinaries(t) + + env := newTestEnv(t, bins) + defer env.Close() + + // Create two nodes: + n1 := newTestNode(t, env) + d1 := n1.StartDaemon(t) + defer d1.Kill() + + n2 := newTestNode(t, env) + d2 := n2.StartDaemon(t) + defer d2.Kill() + + n1.AwaitListening(t) + n2.AwaitListening(t) + n1.MustUp() + n2.MustUp() + n1.AwaitRunning(t) + n2.AwaitRunning(t) + + t.Log("CONTROLURL", env.ControlServer.URL) + req := new(tailcfg.MapRequest) + req.Ping = true + t.Log("NEWREQ", req) } diff --git a/tstest/integration/testcontrol/testcontrol.go b/tstest/integration/testcontrol/testcontrol.go index f2c8b5ae6..d3018df0d 100644 --- a/tstest/integration/testcontrol/testcontrol.go +++ b/tstest/integration/testcontrol/testcontrol.go @@ -540,7 +540,7 @@ var prodDERPMap = derpmap.Prod() // // No updates to s are done here. func (s *Server) MapResponse(req *tailcfg.MapRequest) (res *tailcfg.MapResponse, err error) { - log.Println("MAPREQUEST : ", *req) + log.Println("MAPREQUEST : ", string(JsonPrint(req))) node := s.Node(req.NodeKey) if node == nil { // node key rotated away (once test server supports that) @@ -741,3 +741,8 @@ func (s *Server) receivePingInfo(w http.ResponseWriter, r *http.Request) { w.WriteHeader(200) io.WriteString(w, "Ping Streamed Back : "+string(reqBody)) } + +func JsonPrint(item interface{}) []byte { + res, _ := json.MarshalIndent(item, "", " ") + return res +}