Debian Codegraph @

cmd/webpush_test.go

raw
1 package cmd
2
3 import (
4 "path/filepath"
5 "testing"
6
7 "github.com/stretchr/testify/require"
8 "github.com/urfave/cli/v2"
9 "heckel.io/ntfy/v2/server"
10 )
11
12 func TestCLI_WebPush_GenerateKeys(t *testing.T) {
13 app, _, stdout, _ := newTestApp()
14 require.Nil(t, runWebPushCommand(app, server.NewConfig(), "keys"))
15 require.Contains(t, stdout.String(), "Web Push keys generated.")
16 }
17
18 func TestCLI_WebPush_WriteKeysToFile(t *testing.T) {
19 tempDir := t.TempDir()
20 t.Chdir(tempDir)
21 app, _, stdout, _ := newTestApp()
22 require.Nil(t, runWebPushCommand(app, server.NewConfig(), "keys", "--output-file=key-file.yaml"))
23 require.Contains(t, stdout.String(), "Web Push keys written to key-file.yaml")
24 require.FileExists(t, filepath.Join(tempDir, "key-file.yaml"))
25 }
26
27 func runWebPushCommand(app *cli.App, conf *server.Config, args ...string) error {
28 webPushArgs := []string{
29 "ntfy",
30 "--log-level=ERROR",
31 "webpush",
32 }
33 return app.Run(append(webPushArgs, args...))
34 }