option_test.go 880 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //nolint:all
  2. package cron
  3. import (
  4. "log"
  5. "strings"
  6. "testing"
  7. "time"
  8. )
  9. func TestWithLocation(t *testing.T) {
  10. c := New(WithLocation(time.UTC))
  11. if c.location != time.UTC {
  12. t.Errorf("expected UTC, got %v", c.location)
  13. }
  14. }
  15. func TestWithParser(t *testing.T) {
  16. var parser = NewParser(Dow)
  17. c := New(WithParser(parser))
  18. if c.parser != parser {
  19. t.Error("expected provided parser")
  20. }
  21. }
  22. func TestWithVerboseLogger(t *testing.T) {
  23. var buf syncWriter
  24. var logger = log.New(&buf, "", log.LstdFlags)
  25. c := New(WithLogger(VerbosePrintfLogger(logger)))
  26. if c.logger.(printfLogger).logger != logger {
  27. t.Error("expected provided logger")
  28. }
  29. c.AddFunc("@every 1s", func() {})
  30. c.Start()
  31. time.Sleep(OneSecond)
  32. c.Stop()
  33. out := buf.String()
  34. if !strings.Contains(out, "schedule,") ||
  35. !strings.Contains(out, "run,") {
  36. t.Error("expected to see some actions, got:", out)
  37. }
  38. }