From 5b4b57e3bf51a16ee7f46dd5fcb40adb644cfdab Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Wed, 16 Aug 2023 10:14:19 +0200 Subject: [PATCH] Config: Improve docs and tests for Unix socket support #2337 #3595 Signed-off-by: Michael Mayer --- internal/config/config_server_test.go | 28 +++++++++++++-------------- internal/config/config_test.go | 21 -------------------- internal/config/flags.go | 9 +++++---- 3 files changed, 19 insertions(+), 39 deletions(-) diff --git a/internal/config/config_server_test.go b/internal/config/config_server_test.go index 343b217bb..4a8d21885 100644 --- a/internal/config/config_server_test.go +++ b/internal/config/config_server_test.go @@ -8,15 +8,7 @@ import ( "github.com/photoprism/photoprism/internal/ttl" ) -func TestConfig_HttpSocket(t *testing.T) { - c := NewConfig(CliTestContext()) - - assert.Equal(t, "", c.HttpSocket()) - c.options.HttpHost = "unix:/tmp/photoprism.sock" - assert.Equal(t, "/tmp/photoprism.sock", c.HttpSocket()) -} - -func TestConfig_HttpServerHost2(t *testing.T) { +func TestConfig_HttpServerHost(t *testing.T) { c := NewConfig(CliTestContext()) assert.Equal(t, "0.0.0.0", c.HttpHost()) @@ -26,15 +18,23 @@ func TestConfig_HttpServerHost2(t *testing.T) { assert.Equal(t, "unix:/tmp/photoprism.sock", c.HttpHost()) } -func TestConfig_HttpServerPort2(t *testing.T) { +func TestConfig_HttpSocket(t *testing.T) { c := NewConfig(CliTestContext()) - assert.Equal(t, int(2342), c.HttpPort()) - c.options.HttpPort = int(1234) - assert.Equal(t, int(1234), c.HttpPort()) + assert.Equal(t, "", c.HttpSocket()) + c.options.HttpHost = "unix:/tmp/photoprism.sock" + assert.Equal(t, "/tmp/photoprism.sock", c.HttpSocket()) } -func TestConfig_HttpServerMode2(t *testing.T) { +func TestConfig_HttpServerPort(t *testing.T) { + c := NewConfig(CliTestContext()) + + assert.Equal(t, 2342, c.HttpPort()) + c.options.HttpPort = 1234 + assert.Equal(t, 1234, c.HttpPort()) +} + +func TestConfig_HttpServerMode(t *testing.T) { c := NewConfig(CliTestContext()) assert.Equal(t, HttpModeProd, c.HttpMode()) diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 608a9d800..836c2b46b 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -156,27 +156,6 @@ func TestConfig_DetachServer(t *testing.T) { assert.Equal(t, false, detachServer) } -func TestConfig_HttpServerHost(t *testing.T) { - c := NewConfig(CliTestContext()) - - host := c.HttpHost() - assert.Equal(t, "0.0.0.0", host) -} - -func TestConfig_HttpServerPort(t *testing.T) { - c := NewConfig(CliTestContext()) - - port := c.HttpPort() - assert.Equal(t, 2342, port) -} - -func TestConfig_HttpServerMode(t *testing.T) { - c := NewConfig(CliTestContext()) - - mode := c.HttpMode() - assert.Equal(t, HttpModeProd, mode) -} - func TestConfig_OriginalsPath(t *testing.T) { c := NewConfig(CliTestContext()) diff --git a/internal/config/flags.go b/internal/config/flags.go index 70964dde2..c29911c45 100644 --- a/internal/config/flags.go +++ b/internal/config/flags.go @@ -473,12 +473,12 @@ var Flags = CliFlags{ }}, { Flag: cli.StringFlag{ Name: "tls-cert", - Usage: "public HTTPS certificate `FILE` (.crt)", + Usage: "public HTTPS certificate `FILE` (.crt), ignored for Unix domain sockets", EnvVar: EnvVar("TLS_CERT"), }}, { Flag: cli.StringFlag{ Name: "tls-key", - Usage: "private HTTPS key `FILE` (.key)", + Usage: "private HTTPS key `FILE` (.key), ignored for Unix domain sockets", EnvVar: EnvVar("TLS_KEY"), }}, { Flag: cli.StringFlag{ @@ -510,13 +510,14 @@ var Flags = CliFlags{ }}, { Flag: cli.StringFlag{ Name: "http-host, ip", - Usage: "Web server `IP` address. If start with unix:, path followed is treated as unix socket path for listening.", + Value: "0.0.0.0", + Usage: "web server `IP` address or Unix domain socket, e.g. unix:/var/run/photoprism.sock", EnvVar: EnvVar("HTTP_HOST"), }}, { Flag: cli.IntFlag{ Name: "http-port, port", Value: 2342, - Usage: "Web server port `NUMBER`", + Usage: "web server port `NUMBER`, ignored for Unix domain sockets", EnvVar: EnvVar("HTTP_PORT"), }}, { Flag: cli.StringFlag{