app_test.go 674 B

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