2021-12-19 23:32:16 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2021-12-24 14:01:29 +00:00
|
|
|
"encoding/json"
|
2021-12-19 23:32:16 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2023-11-17 01:54:58 +00:00
|
|
|
"heckel.io/ntfy/v2/client"
|
|
|
|
"heckel.io/ntfy/v2/log"
|
2021-12-19 23:32:16 +00:00
|
|
|
"os"
|
2021-12-24 14:01:29 +00:00
|
|
|
"strings"
|
2021-12-19 23:32:16 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// This only contains helpers so far
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
2023-02-06 04:34:27 +00:00
|
|
|
log.SetLevel(log.ErrorLevel)
|
2021-12-19 23:32:16 +00:00
|
|
|
os.Exit(m.Run())
|
|
|
|
}
|
|
|
|
|
|
|
|
func newTestApp() (*cli.App, *bytes.Buffer, *bytes.Buffer, *bytes.Buffer) {
|
|
|
|
var stdin, stdout, stderr bytes.Buffer
|
|
|
|
app := New()
|
|
|
|
app.Reader = &stdin
|
|
|
|
app.Writer = &stdout
|
|
|
|
app.ErrWriter = &stderr
|
|
|
|
return app, &stdin, &stdout, &stderr
|
|
|
|
}
|
2021-12-24 14:01:29 +00:00
|
|
|
|
|
|
|
func toMessage(t *testing.T, s string) *client.Message {
|
|
|
|
var m *client.Message
|
|
|
|
if err := json.NewDecoder(strings.NewReader(s)).Decode(&m); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
return m
|
|
|
|
}
|