From 26dde0f28609f48b9e0d7a2b568b22c0c95f330c Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Tue, 25 Jan 2022 22:04:54 -0500 Subject: [PATCH] Fix test --- cmd/serve_test.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cmd/serve_test.go b/cmd/serve_test.go index d49fbbb1..3b2b9b0d 100644 --- a/cmd/serve_test.go +++ b/cmd/serve_test.go @@ -8,6 +8,7 @@ import ( "heckel.io/ntfy/test" "heckel.io/ntfy/util" "math/rand" + "os" "os/exec" "path/filepath" "testing" @@ -20,9 +21,10 @@ func init() { func TestCLI_Serve_Unix_Curl(t *testing.T) { sockFile := filepath.Join(t.TempDir(), "ntfy.sock") + configFile := newEmptyFile(t) // Avoid issues with existing server.yml file on system go func() { app, _, _, _ := newTestApp() - err := app.Run([]string{"ntfy", "serve", "--listen-http=-", "--listen-unix=" + sockFile}) + err := app.Run([]string{"ntfy", "serve", "--config=" + configFile, "--listen-http=-", "--listen-unix=" + sockFile}) require.Nil(t, err) }() for i := 0; i < 40 && !util.FileExists(sockFile); i++ { @@ -40,8 +42,9 @@ func TestCLI_Serve_Unix_Curl(t *testing.T) { func TestCLI_Serve_WebSocket(t *testing.T) { port := 10000 + rand.Intn(20000) go func() { + configFile := newEmptyFile(t) // Avoid issues with existing server.yml file on system app, _, _, _ := newTestApp() - err := app.Run([]string{"ntfy", "serve", fmt.Sprintf("--listen-http=:%d", port)}) + err := app.Run([]string{"ntfy", "serve", "--config=" + configFile, fmt.Sprintf("--listen-http=:%d", port)}) require.Nil(t, err) }() test.WaitForPortUp(t, port) @@ -66,3 +69,9 @@ func TestCLI_Serve_WebSocket(t *testing.T) { require.Equal(t, "my message", m.Message) require.Equal(t, "mytopic", m.Topic) } + +func newEmptyFile(t *testing.T) string { + filename := filepath.Join(t.TempDir(), "empty") + require.Nil(t, os.WriteFile(filename, []byte{}, 0600)) + return filename +}