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