1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2024-12-28 04:32:30 +01:00
ntfy/cmd/publish_test.go

37 lines
1.1 KiB
Go
Raw Normal View History

2021-12-20 00:32:16 +01:00
package cmd
import (
2021-12-24 15:01:29 +01:00
"fmt"
2021-12-20 00:32:16 +01:00
"github.com/stretchr/testify/require"
2021-12-24 15:01:29 +01:00
"heckel.io/ntfy/test"
2021-12-20 00:32:16 +01:00
"heckel.io/ntfy/util"
"testing"
)
func TestCLI_Publish_Subscribe_Poll_Real_Server(t *testing.T) {
2021-12-20 00:32:16 +01:00
testMessage := util.RandomString(10)
app, _, _, _ := newTestApp()
require.Nil(t, app.Run([]string{"ntfy", "publish", "ntfytest", "ntfy unit test " + testMessage}))
app2, _, stdout, _ := newTestApp()
require.Nil(t, app2.Run([]string{"ntfy", "subscribe", "--poll", "ntfytest"}))
require.Contains(t, stdout.String(), testMessage)
}
2021-12-24 15:01:29 +01:00
func TestCLI_Publish_Subscribe_Poll(t *testing.T) {
s, port := test.StartServer(t)
defer test.StopServer(t, s, port)
topic := fmt.Sprintf("http://127.0.0.1:%d/mytopic", port)
app, _, stdout, _ := newTestApp()
require.Nil(t, app.Run([]string{"ntfy", "publish", topic, "some message"}))
m := toMessage(t, stdout.String())
require.Equal(t, "some message", m.Message)
app2, _, stdout, _ := newTestApp()
require.Nil(t, app2.Run([]string{"ntfy", "subscribe", "--poll", topic}))
m = toMessage(t, stdout.String())
require.Equal(t, "some message", m.Message)
}