config_test.go 1006 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package geoip
  2. import (
  3. "reflect"
  4. "testing"
  5. "github.com/mholt/caddy"
  6. )
  7. func TestParseConfig(t *testing.T) {
  8. controller := caddy.NewTestController("http", `
  9. localhost:8080
  10. geoip {
  11. database path/to/maxmind/db
  12. set_header_country_code Code
  13. set_header_country_name CountryName
  14. set_header_country_eu Eu
  15. set_header_city_name CityName
  16. set_header_location_lat Lat
  17. set_header_location_lon Lon
  18. set_header_location_tz TZ
  19. }
  20. `)
  21. actual, err := parseConfig(controller)
  22. if err != nil {
  23. t.Errorf("parseConfig return err: %v", err)
  24. }
  25. expected := Config{
  26. DatabasePath: "path/to/maxmind/db",
  27. HeaderNameCountryCode: "Code",
  28. HeaderNameCountryName: "CountryName",
  29. HeaderNameCountryIsEU: "Eu",
  30. HeaderNameCityName: "CityName",
  31. HeaderNameLocationLat: "Lat",
  32. HeaderNameLocationLon: "Lon",
  33. HeaderNameLocationTimeZone: "TZ",
  34. }
  35. if !reflect.DeepEqual(expected, actual) {
  36. t.Errorf("Expected %v actual %v", expected, actual)
  37. }
  38. }