tier_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package cmd
  2. import (
  3. "github.com/stretchr/testify/require"
  4. "github.com/urfave/cli/v2"
  5. "heckel.io/ntfy/server"
  6. "heckel.io/ntfy/test"
  7. "testing"
  8. )
  9. func TestCLI_Tier_AddListChangeDelete(t *testing.T) {
  10. s, conf, port := newTestServerWithAuth(t)
  11. defer test.StopServer(t, s, port)
  12. app, _, _, stderr := newTestApp()
  13. require.Nil(t, runTierCommand(app, conf, "add", "--name", "Pro", "--message-limit", "1234", "pro"))
  14. require.Contains(t, stderr.String(), "tier added\n\ntier pro (id: ti_")
  15. err := runTierCommand(app, conf, "add", "pro")
  16. require.NotNil(t, err)
  17. require.Equal(t, "tier pro already exists", err.Error())
  18. app, _, _, stderr = newTestApp()
  19. require.Nil(t, runTierCommand(app, conf, "list"))
  20. require.Contains(t, stderr.String(), "tier pro (id: ti_")
  21. require.Contains(t, stderr.String(), "- Name: Pro")
  22. require.Contains(t, stderr.String(), "- Message limit: 1234")
  23. app, _, _, stderr = newTestApp()
  24. require.Nil(t, runTierCommand(app, conf, "change",
  25. "--message-limit=999",
  26. "--message-expiry-duration=99h",
  27. "--email-limit=91",
  28. "--reservation-limit=98",
  29. "--attachment-file-size-limit=100m",
  30. "--attachment-expiry-duration=7h",
  31. "--attachment-total-size-limit=10G",
  32. "--attachment-bandwidth-limit=100G",
  33. "--stripe-price-id=price_991",
  34. "pro",
  35. ))
  36. require.Contains(t, stderr.String(), "- Message limit: 999")
  37. require.Contains(t, stderr.String(), "- Message expiry duration: 99h")
  38. require.Contains(t, stderr.String(), "- Email limit: 91")
  39. require.Contains(t, stderr.String(), "- Reservation limit: 98")
  40. require.Contains(t, stderr.String(), "- Attachment file size limit: 100.0 MB")
  41. require.Contains(t, stderr.String(), "- Attachment expiry duration: 7h")
  42. require.Contains(t, stderr.String(), "- Attachment total size limit: 10.0 GB")
  43. require.Contains(t, stderr.String(), "- Stripe price: price_991")
  44. app, _, _, stderr = newTestApp()
  45. require.Nil(t, runTierCommand(app, conf, "remove", "pro"))
  46. require.Contains(t, stderr.String(), "tier pro removed")
  47. }
  48. func runTierCommand(app *cli.App, conf *server.Config, args ...string) error {
  49. userArgs := []string{
  50. "ntfy",
  51. "--log-level=ERROR",
  52. "tier",
  53. "--config=" + conf.File, // Dummy config file to avoid lookups of real file
  54. "--auth-file=" + conf.AuthFile,
  55. "--auth-default-access=" + conf.AuthDefault.String(),
  56. }
  57. return app.Run(append(userArgs, args...))
  58. }