app_test.go 684 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package cmd
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "github.com/urfave/cli/v2"
  6. "heckel.io/ntfy/client"
  7. "io"
  8. "log"
  9. "os"
  10. "strings"
  11. "testing"
  12. )
  13. // This only contains helpers so far
  14. func TestMain(m *testing.M) {
  15. log.SetOutput(io.Discard)
  16. os.Exit(m.Run())
  17. }
  18. func newTestApp() (*cli.App, *bytes.Buffer, *bytes.Buffer, *bytes.Buffer) {
  19. var stdin, stdout, stderr bytes.Buffer
  20. app := New()
  21. app.Reader = &stdin
  22. app.Writer = &stdout
  23. app.ErrWriter = &stderr
  24. return app, &stdin, &stdout, &stderr
  25. }
  26. func toMessage(t *testing.T, s string) *client.Message {
  27. var m *client.Message
  28. if err := json.NewDecoder(strings.NewReader(s)).Decode(&m); err != nil {
  29. t.Fatal(err)
  30. }
  31. return m
  32. }