From d9ec18314d3f963e32f7f36a08407b8055d70dac Mon Sep 17 00:00:00 2001 From: Sudarsan Reddy Date: Tue, 3 Aug 2021 12:08:08 +0100 Subject: [PATCH] TUN-4873: Disable unix domain socket test for windows unit tests --- origin/proxy_posix_test.go | 55 ++++++++++++++++++++++++++++++++++++++ origin/proxy_test.go | 41 ---------------------------- 2 files changed, 55 insertions(+), 41 deletions(-) create mode 100644 origin/proxy_posix_test.go diff --git a/origin/proxy_posix_test.go b/origin/proxy_posix_test.go new file mode 100644 index 00000000..24b1f278 --- /dev/null +++ b/origin/proxy_posix_test.go @@ -0,0 +1,55 @@ +// +build !windows + +package origin + +import ( + "io/ioutil" + "net" + "net/http" + "net/http/httptest" + "os" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/cloudflare/cloudflared/config" +) + +func TestUnixSocketOrigin(t *testing.T) { + file, err := ioutil.TempFile("", "unix.sock") + require.NoError(t, err) + os.Remove(file.Name()) // remove the file since binding the socket expects to create it + + l, err := net.Listen("unix", file.Name()) + require.NoError(t, err) + defer l.Close() + defer os.Remove(file.Name()) + + api := &httptest.Server{ + Listener: l, + Config: &http.Server{Handler: mockAPI{}}, + } + api.Start() + defer api.Close() + + unvalidatedIngress := []config.UnvalidatedIngressRule{ + { + Hostname: "unix.example.com", + Service: "unix:" + file.Name(), + }, + { + Hostname: "*", + Service: "http_status:404", + }, + } + + tests := []MultipleIngressTest{ + { + url: "http://unix.example.com", + expectedStatus: http.StatusCreated, + expectedBody: []byte("Created"), + }, + } + + runIngressTestScenarios(t, unvalidatedIngress, tests) +} diff --git a/origin/proxy_test.go b/origin/proxy_test.go index 5ba89a22..5c28e449 100644 --- a/origin/proxy_test.go +++ b/origin/proxy_test.go @@ -6,11 +6,9 @@ import ( "flag" "fmt" "io" - "io/ioutil" "net" "net/http" "net/http/httptest" - "os" "sync" "testing" "time" @@ -656,45 +654,6 @@ func TestConnections(t *testing.T) { } } -func TestUnixSocketOrigin(t *testing.T) { - file, err := ioutil.TempFile("", "unix.sock") - require.NoError(t, err) - os.Remove(file.Name()) // remove the file since binding the socket expects to create it - - l, err := net.Listen("unix", file.Name()) - require.NoError(t, err) - defer l.Close() - defer os.Remove(file.Name()) - - api := &httptest.Server{ - Listener: l, - Config: &http.Server{Handler: mockAPI{}}, - } - api.Start() - defer api.Close() - - unvalidatedIngress := []config.UnvalidatedIngressRule{ - { - Hostname: "unix.example.com", - Service: "unix:" + file.Name(), - }, - { - Hostname: "*", - Service: "http_status:404", - }, - } - - tests := []MultipleIngressTest{ - { - url: "http://unix.example.com", - expectedStatus: http.StatusCreated, - expectedBody: []byte("Created"), - }, - } - - runIngressTestScenarios(t, unvalidatedIngress, tests) -} - type requestBody struct { pw *io.PipeWriter pr *io.PipeReader