ntfy-server/cmd/webpush_test.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

35 lines
952 B
Go
Raw Permalink Normal View History

2023-05-29 17:57:21 +02:00
package cmd
import (
"path/filepath"
2023-05-29 17:57:21 +02:00
"testing"
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v2"
2023-11-16 20:54:58 -05:00
"heckel.io/ntfy/v2/server"
2023-05-29 17:57:21 +02:00
)
func TestCLI_WebPush_GenerateKeys(t *testing.T) {
2025-07-31 11:35:21 +02:00
app, _, stdout, _ := newTestApp()
require.Nil(t, runWebPushCommand(app, server.NewConfig(), "keys"))
2025-07-31 11:35:21 +02:00
require.Contains(t, stdout.String(), "Web Push keys generated.")
2023-05-29 17:57:21 +02:00
}
func TestCLI_WebPush_WriteKeysToFile(t *testing.T) {
tempDir := t.TempDir()
t.Chdir(tempDir)
2025-07-31 11:35:21 +02:00
app, _, stdout, _ := newTestApp()
2025-05-22 20:48:24 -04:00
require.Nil(t, runWebPushCommand(app, server.NewConfig(), "keys", "--output-file=key-file.yaml"))
2025-07-31 11:35:21 +02:00
require.Contains(t, stdout.String(), "Web Push keys written to key-file.yaml")
require.FileExists(t, filepath.Join(tempDir, "key-file.yaml"))
}
2023-05-29 17:57:21 +02:00
func runWebPushCommand(app *cli.App, conf *server.Config, args ...string) error {
webPushArgs := []string{
"ntfy",
"--log-level=ERROR",
"webpush",
2023-05-29 17:57:21 +02:00
}
return app.Run(append(webPushArgs, args...))
}