chatto_test.go 947 B

1234567891011121314151617181920212223242526272829303132333435
  1. package main
  2. import (
  3. "strings"
  4. "testing"
  5. "time"
  6. "gogs.netdome.biz/paul/cheapo/internal/game"
  7. )
  8. func mustParse(s string) time.Time {
  9. tt, err := time.Parse(time.RFC3339, s)
  10. if err != nil {
  11. panic(err)
  12. }
  13. return tt
  14. }
  15. func TestFormatGamesDefaultDate(t *testing.T) {
  16. t.Setenv("CHEAPO_CHATTO_OUTPUT_DATE_FORMAT", "")
  17. games := []game.Game{{Title: "G", Store: "epic", URL: "u", Kind: "free-now", EndDate: mustParse("2026-11-02T00:00:00Z")}}
  18. out := formatGames(games, "")
  19. if !strings.Contains(out, "until 02.11.2026") {
  20. t.Fatalf("expected compact date, got:\n%s", out)
  21. }
  22. }
  23. func TestFormatGamesCustomDate(t *testing.T) {
  24. t.Setenv("CHEAPO_CHATTO_OUTPUT_DATE_FORMAT", "2006-01-02")
  25. games := []game.Game{{Title: "G", Store: "epic", URL: "u", Kind: "free-now", EndDate: mustParse("2026-11-02T00:00:00Z")}}
  26. out := formatGames(games, "")
  27. if !strings.Contains(out, "until 2026-11-02") {
  28. t.Fatalf("expected ISO date, got:\n%s", out)
  29. }
  30. }