cadence_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. package web
  2. import (
  3. "testing"
  4. "github.com/robfig/cron/v3"
  5. )
  6. // All centralized background-job cadences must remain valid cron specs. This is
  7. // the guard for the "single tuning surface" refactor: editing a cadence to an
  8. // invalid spec fails here instead of silently dropping a job at startup.
  9. //
  10. // NOTE: package web embeds the built frontend (//go:embed all:dist), so this
  11. // test compiles only after `npm run build` has populated web/dist — the normal
  12. // repo build flow.
  13. func TestJobCadencesAreValidCronSpecs(t *testing.T) {
  14. cadences := map[string]string{
  15. "cadenceXrayRunning": cadenceXrayRunning,
  16. "cadenceXrayRestart": cadenceXrayRestart,
  17. "cadenceXrayTraffic": cadenceXrayTraffic,
  18. "cadenceMtproto": cadenceMtproto,
  19. "cadenceClientIPScan": cadenceClientIPScan,
  20. "cadenceNodeHeartbeat": cadenceNodeHeartbeat,
  21. "cadenceNodeTraffic": cadenceNodeTraffic,
  22. "cadenceOutboundSub": cadenceOutboundSub,
  23. "cadenceCheckHash": cadenceCheckHash,
  24. "cadenceCPUAlarm": cadenceCPUAlarm,
  25. }
  26. for name, spec := range cadences {
  27. if _, err := cron.ParseStandard(spec); err != nil {
  28. t.Errorf("%s = %q is not a valid cron spec: %v", name, spec, err)
  29. }
  30. }
  31. }