geoip_test.go 588 B

123456789101112131415161718192021222324252627282930313233343536
  1. package config
  2. import (
  3. "errors"
  4. "testing"
  5. )
  6. func TestGeoIPValid(t *testing.T) {
  7. for _, tt := range []struct {
  8. err error
  9. input *GeoIP
  10. name string
  11. }{
  12. {
  13. name: "basic valid",
  14. input: &GeoIP{
  15. Countries: []string{"CA"},
  16. },
  17. },
  18. {
  19. name: "invalid country",
  20. input: &GeoIP{
  21. Countries: []string{"XOB"},
  22. },
  23. err: ErrNotCountryCode,
  24. },
  25. } {
  26. t.Run(tt.name, func(t *testing.T) {
  27. if err := tt.input.Valid(); !errors.Is(err, tt.err) {
  28. t.Logf("want: %v", tt.err)
  29. t.Logf("got: %v", err)
  30. t.Error("got wrong validation error")
  31. }
  32. })
  33. }
  34. }