From ddd5ce2c2131646f0f513cee15d7719376a3e6e0 Mon Sep 17 00:00:00 2001
From: Philipp Heckel <pheckel@datto.com>
Date: Sun, 19 Dec 2021 18:32:16 -0500
Subject: [PATCH] Start CLI tests

---
 cmd/app_test.go     | 26 ++++++++++++++++++++++++++
 cmd/publish_test.go | 18 ++++++++++++++++++
 docs/install.md     |  3 ++-
 main.go             |  5 ++++-
 4 files changed, 50 insertions(+), 2 deletions(-)
 create mode 100644 cmd/app_test.go
 create mode 100644 cmd/publish_test.go

diff --git a/cmd/app_test.go b/cmd/app_test.go
new file mode 100644
index 0000000..52eafa7
--- /dev/null
+++ b/cmd/app_test.go
@@ -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
+}
diff --git a/cmd/publish_test.go b/cmd/publish_test.go
new file mode 100644
index 0000000..315413b
--- /dev/null
+++ b/cmd/publish_test.go
@@ -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)
+}
diff --git a/docs/install.md b/docs/install.md
index 379f855..45a6c25 100644
--- a/docs/install.md
+++ b/docs/install.md
@@ -13,7 +13,8 @@ The ntfy server comes as a statically linked binary and is shipped as tarball, d
 We support amd64, armv7 and arm64.
 
 1. Install ntfy using one of the methods described below
-2. Then (optionally) edit `/etc/ntfy/server.yml` (see [configuration](config.md))
+2. Then (optionally) edit `/etc/ntfy/server.yml` for the server (see [configuration](config.md) or [sample server.yml](https://github.com/binwiederhier/ntfy/blob/main/server/server.yml))
+3. Or (optionally) create/edit `~/.config/ntfy/client.yml` (or `/etc/ntfy/client.yml`, see [sample client.yml](https://github.com/binwiederhier/ntfy/blob/main/client/client.yml))
 
 To run the ntfy server, then just run `ntfy serve` (or `systemctl start ntfy` when using the deb/rpm).
 To send messages, use `ntfy publish`. To subscribe to topics, use `ntfy subscribe` (see [subscribing via CLI][subscribe/cli.md]
diff --git a/main.go b/main.go
index f6cdbdc..eab90e3 100644
--- a/main.go
+++ b/main.go
@@ -16,7 +16,10 @@ var (
 
 func main() {
 	cli.AppHelpTemplate += fmt.Sprintf(`
-Try 'ntfy COMMAND --help' for more information.
+Try 'ntfy COMMAND --help' or https://ntfy.sh/docs/ for more information.
+
+To report a bug, open an issue on GitHub: https://github.com/binwiederhier/ntfy/issues.
+If you want to chat, simply join the Discord server: https://discord.gg/cT7ECsZj9w.
 
 ntfy %s (%s), runtime %s, built at %s
 Copyright (C) 2021 Philipp C. Heckel, licensed under Apache License 2.0 & GPLv2
-- 
GitLab