2023-05-29 17:57:21 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/urfave/cli/v2"
|
2023-11-17 02:54:58 +01:00
|
|
|
"heckel.io/ntfy/v2/server"
|
2023-05-29 17:57:21 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCLI_WebPush_GenerateKeys(t *testing.T) {
|
|
|
|
app, _, _, stderr := newTestApp()
|
2023-06-08 20:30:19 +02:00
|
|
|
require.Nil(t, runWebPushCommand(app, server.NewConfig(), "keys"))
|
|
|
|
require.Contains(t, stderr.String(), "Web Push keys generated.")
|
2023-05-29 17:57:21 +02:00
|
|
|
}
|
|
|
|
|
2024-06-26 07:58:36 +02:00
|
|
|
func TestCLI_WebPush_WriteKeysToFile(t *testing.T) {
|
|
|
|
app, _, _, stderr := newTestApp()
|
|
|
|
require.Nil(t, runWebPushCommand(app, server.NewConfig(), "keys", "--key-file=key-file.yaml"))
|
|
|
|
require.Contains(t, stderr.String(), "Web Push keys written to key-file.yaml")
|
|
|
|
require.FileExists(t, "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",
|
2023-06-08 20:30:19 +02:00
|
|
|
"webpush",
|
2023-05-29 17:57:21 +02:00
|
|
|
}
|
|
|
|
return app.Run(append(webPushArgs, args...))
|
|
|
|
}
|