Start CLI tests

This commit is contained in:
Philipp Heckel 2021-12-19 18:32:16 -05:00
parent e3dfea1991
commit ddd5ce2c21
4 changed files with 50 additions and 2 deletions

26
cmd/app_test.go Normal file
View file

@ -0,0 +1,26 @@
package cmd
import (
"bytes"
"github.com/urfave/cli/v2"
"io"
"log"
"os"
"testing"
)
// This only contains helpers so far
func TestMain(m *testing.M) {
log.SetOutput(io.Discard)
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
}

18
cmd/publish_test.go Normal file
View file

@ -0,0 +1,18 @@
package cmd
import (
"github.com/stretchr/testify/require"
"heckel.io/ntfy/util"
"testing"
)
func TestCLI_Publish_Real_Server(t *testing.T) {
testMessage := util.RandomString(10)
app, _, _, _ := newTestApp()
require.Nil(t, app.Run([]string{"ntfy", "publish", "ntfytest", "ntfy unit test " + testMessage}))
app2, _, stdout, _ := newTestApp()
require.Nil(t, app2.Run([]string{"ntfy", "subscribe", "--poll", "ntfytest"}))
require.Contains(t, stdout.String(), testMessage)
}