Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorVladimir Shushlin <vshushlin@gitlab.com>2022-05-30 09:31:21 +0300
committerVladimir Shushlin <vshushlin@gitlab.com>2022-05-30 09:31:21 +0300
commitd820de93ee18a6c052fd73df6743718424f00e8f (patch)
tree0efcffeb0978bddfa87feada9eba95c21e833c3c /test
parent6e574265ffbe98c9e73e381c5b73dbd4ae9c15a5 (diff)
parent224025547ace9ee83b1cb154728ab825f92ea297 (diff)
Merge branch 'feat/unix-sock' into 'master'
feat: add support for socket listeners See merge request gitlab-org/gitlab-pages!758
Diffstat (limited to 'test')
-rw-r--r--test/acceptance/config_test.go22
-rw-r--r--test/acceptance/helpers_test.go26
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) {