Starting an integration test

This commit is contained in:
Simeng He 2021-05-21 10:51:16 -04:00
parent 866c2827d6
commit a374db1f8b
2 changed files with 33 additions and 1 deletions

View File

@ -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)
}

View File

@ -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
}