webpush_test.go 952 B

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