app_test.go 702 B

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