diff options
author | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-05-30 00:52:55 +0300 |
---|---|---|
committer | feistel <6742251-feistel@users.noreply.gitlab.com> | 2022-05-30 00:52:55 +0300 |
commit | 224025547ace9ee83b1cb154728ab825f92ea297 (patch) | |
tree | 238f9501ec7315dc3be0f963218e461790829035 /test/acceptance | |
parent | 2da055bf835b14238360754753e42c384ac98988 (diff) |
Add acceptance tests for socket listeners
Diffstat (limited to 'test/acceptance')
-rw-r--r-- | test/acceptance/config_test.go | 22 | ||||
-rw-r--r-- | test/acceptance/helpers_test.go | 26 |
2 files changed, 48 insertions, 0 deletions
diff --git a/test/acceptance/config_test.go b/test/acceptance/config_test.go index 07697c48..95be6e17 100644 --- a/test/acceptance/config_test.go +++ b/test/acceptance/config_test.go @@ -4,6 +4,7 @@ import ( "fmt" "net" "net/http" + "path/filepath" "testing" "github.com/stretchr/testify/require" @@ -64,3 +65,24 @@ func TestMultipleListenersFromEnvironmentVariables(t *testing.T) { require.Equal(t, http.StatusOK, rsp.StatusCode) } } + +func TestUnixSocketListener(t *testing.T) { + tmp := t.TempDir() + sockPath := filepath.Join(tmp, "unix.sock") + + spec := ListenSpec{ + Type: "unix", + Host: sockPath, + } + + RunPagesProcess(t, + withListeners([]ListenSpec{spec}), + ) + require.NoError(t, spec.WaitUntilRequestSucceeds(nil)) + + rsp, err := GetPageFromListener(t, spec, "group.gitlab-example.com", "project/") + + require.NoError(t, err) + rsp.Body.Close() + require.Equal(t, http.StatusOK, rsp.StatusCode) +} diff --git a/test/acceptance/helpers_test.go b/test/acceptance/helpers_test.go index 8a81553d..0ac4a40b 100644 --- a/test/acceptance/helpers_test.go +++ b/test/acceptance/helpers_test.go @@ -151,11 +151,23 @@ func (l ListenSpec) httpsDialContext() dialContext { } } +func (l ListenSpec) unixSocketDialContext() dialContext { + return func(ctx context.Context, _, _ string) (net.Conn, error) { + var d net.Dialer + + return d.DialContext(ctx, "unix", l.Host) + } +} + func (l ListenSpec) dialContext() dialContext { if l.Type == "https-proxyv2" { return l.proxyV2DialContext() } + if l.Type == "unix" { + return l.unixSocketDialContext() + } + return l.httpsDialContext() } @@ -213,6 +225,15 @@ func (l ListenSpec) WaitUntilRequestSucceeds(done chan struct{}) error { } func (l ListenSpec) JoinHostPort() string { + if l.Type == "unix" { + // The dialer ignores the addr parameter and uses + // the socket path directly. + // This is a stub used by ListenSpec#URL() + // ListenSpec.Host cannot be used because it is + // not a valid hostname. + return "unix" + } + return net.JoinHostPort(l.Host, l.Port) } @@ -328,6 +349,11 @@ func getPagesArgs(t *testing.T, listeners []ListenSpec, promPort string, extraAr args = append(args, "-log-verbose=true") for _, spec := range listeners { + if spec.Type == "unix" { + args = append(args, "-listen-http", spec.Host) + continue + } + args = append(args, "-listen-"+spec.Type, spec.JoinHostPort()) if strings.Contains(spec.Type, request.SchemeHTTPS) { |