publish_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package cmd
  2. import (
  3. "fmt"
  4. "github.com/stretchr/testify/require"
  5. "heckel.io/ntfy/test"
  6. "heckel.io/ntfy/util"
  7. "testing"
  8. )
  9. func TestCLI_Publish_Subscribe_Poll_Real_Server(t *testing.T) {
  10. testMessage := util.RandomString(10)
  11. app, _, _, _ := newTestApp()
  12. require.Nil(t, app.Run([]string{"ntfy", "publish", "ntfytest", "ntfy unit test " + testMessage}))
  13. app2, _, stdout, _ := newTestApp()
  14. require.Nil(t, app2.Run([]string{"ntfy", "subscribe", "--poll", "ntfytest"}))
  15. require.Contains(t, stdout.String(), testMessage)
  16. }
  17. func TestCLI_Publish_Subscribe_Poll(t *testing.T) {
  18. s, port := test.StartServer(t)
  19. defer test.StopServer(t, s, port)
  20. topic := fmt.Sprintf("http://127.0.0.1:%d/mytopic", port)
  21. app, _, stdout, _ := newTestApp()
  22. require.Nil(t, app.Run([]string{"ntfy", "publish", topic, "some message"}))
  23. m := toMessage(t, stdout.String())
  24. require.Equal(t, "some message", m.Message)
  25. app2, _, stdout, _ := newTestApp()
  26. require.Nil(t, app2.Run([]string{"ntfy", "subscribe", "--poll", topic}))
  27. m = toMessage(t, stdout.String())
  28. require.Equal(t, "some message", m.Message)
  29. }