Fix test
parent
7d9f687768
commit
26dde0f286
|
@ -8,6 +8,7 @@ import (
|
||||||
"heckel.io/ntfy/test"
|
"heckel.io/ntfy/test"
|
||||||
"heckel.io/ntfy/util"
|
"heckel.io/ntfy/util"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -20,9 +21,10 @@ func init() {
|
||||||
|
|
||||||
func TestCLI_Serve_Unix_Curl(t *testing.T) {
|
func TestCLI_Serve_Unix_Curl(t *testing.T) {
|
||||||
sockFile := filepath.Join(t.TempDir(), "ntfy.sock")
|
sockFile := filepath.Join(t.TempDir(), "ntfy.sock")
|
||||||
|
configFile := newEmptyFile(t) // Avoid issues with existing server.yml file on system
|
||||||
go func() {
|
go func() {
|
||||||
app, _, _, _ := newTestApp()
|
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)
|
require.Nil(t, err)
|
||||||
}()
|
}()
|
||||||
for i := 0; i < 40 && !util.FileExists(sockFile); i++ {
|
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) {
|
func TestCLI_Serve_WebSocket(t *testing.T) {
|
||||||
port := 10000 + rand.Intn(20000)
|
port := 10000 + rand.Intn(20000)
|
||||||
go func() {
|
go func() {
|
||||||
|
configFile := newEmptyFile(t) // Avoid issues with existing server.yml file on system
|
||||||
app, _, _, _ := newTestApp()
|
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)
|
require.Nil(t, err)
|
||||||
}()
|
}()
|
||||||
test.WaitForPortUp(t, port)
|
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, "my message", m.Message)
|
||||||
require.Equal(t, "mytopic", m.Topic)
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue