You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

confirmation_test.go 891B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (c) 2020 Shivaram Lingamneni <slingamn@cs.stanford.edu>
  2. // released under the MIT license
  3. package utils
  4. import (
  5. "testing"
  6. "time"
  7. )
  8. func easyParse(timestamp string) time.Time {
  9. result, err := time.Parse("2006-01-02 15:04:05Z", timestamp)
  10. if err != nil {
  11. panic(err)
  12. }
  13. return result
  14. }
  15. func TestConfirmation(t *testing.T) {
  16. set := make(map[string]struct{})
  17. set[ConfirmationCode("#darwin", easyParse("2006-01-01 00:00:00Z"))] = struct{}{}
  18. set[ConfirmationCode("#darwin", easyParse("2006-01-02 00:00:00Z"))] = struct{}{}
  19. set[ConfirmationCode("#xelpers", easyParse("2006-01-01 00:00:00Z"))] = struct{}{}
  20. set[ConfirmationCode("#xelpers", easyParse("2006-01-02 00:00:00Z"))] = struct{}{}
  21. if len(set) != 4 {
  22. t.Error("confirmation codes are not unique")
  23. }
  24. for code := range set {
  25. if len(code) <= 2 || len(code) >= 8 {
  26. t.Errorf("bad code: %s", code)
  27. }
  28. }
  29. }