From d8bee0b4d90444b8b09de7d60dc363d7c3ab636a Mon Sep 17 00:00:00 2001 From: Adam Chalmers Date: Mon, 8 Feb 2021 15:31:51 -0600 Subject: [PATCH] TUN-3890: Code coverage for cloudflared in CI Also changed the socks test code so that it binds to localhost, so that we don't get popups saying "would you like to allow socks.test to use the network" --- .gitignore | 1 + Makefile | 6 ++++++ hello/hello_test.go | 2 +- socks/connection_handler_test.go | 4 ++-- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 493893d9..ac8a8d4d 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ cloudflared-x86-64* .DS_Store *-session.log ssh_server_tests/.env +.cover diff --git a/Makefile b/Makefile index 46d83fae..a27f11e6 100644 --- a/Makefile +++ b/Makefile @@ -88,7 +88,13 @@ container: .PHONY: test test: vet +ifndef CI go test -v -mod=vendor -race $(VERSION_FLAGS) ./... +else + @mkdir -p .cover + go test -v -mod=vendor -race $(VERSION_FLAGS) -coverprofile=".cover/c.out" ./... + go tool cover -html ".cover/c.out" -o .cover/all.html +endif .PHONY: test-ssh-server test-ssh-server: diff --git a/hello/hello_test.go b/hello/hello_test.go index d88f478a..44551104 100644 --- a/hello/hello_test.go +++ b/hello/hello_test.go @@ -27,7 +27,7 @@ func TestCreateTLSListenerOnlyHostSuccess(t *testing.T) { } func TestCreateTLSListenerOnlyPortSuccess(t *testing.T) { - listener, err := CreateTLSListener(":8888") + listener, err := CreateTLSListener("localhost:8888") if err != nil { t.Fatal(err) } diff --git a/socks/connection_handler_test.go b/socks/connection_handler_test.go index 40bc9d87..9370de93 100644 --- a/socks/connection_handler_test.go +++ b/socks/connection_handler_test.go @@ -42,7 +42,7 @@ func startTestServer(t *testing.T, httpHandler func(w http.ResponseWriter, r *ht // create a socks server requestHandler := NewRequestHandler(NewNetDialer()) socksServer := NewConnectionHandler(requestHandler) - listener, err := net.Listen("tcp", ":8086") + listener, err := net.Listen("tcp", "localhost:8086") assert.NoError(t, err) go func() { @@ -58,7 +58,7 @@ func startTestServer(t *testing.T, httpHandler func(w http.ResponseWriter, r *ht mux.HandleFunc("/", httpHandler) // start the servers - go http.ListenAndServe(":8085", mux) + go http.ListenAndServe("localhost:8085", mux) } func respondWithJSON(w http.ResponseWriter, v interface{}, status int) {