config_test.go 937 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. set_header_country_code "Code"
  12. set_header_country_name "CountryName"
  13. set_header_country_eu "Eu"
  14. set_header_city_name "CityName"
  15. set_header_location_lat "Lat"
  16. set_header_location_lon "Lon"
  17. set_header_location_tz "TZ"
  18. }
  19. `)
  20. actual, err := parseConfig(controller)
  21. if err != nil {
  22. t.Errorf("parseConfig return err: %v", err)
  23. }
  24. expected := Config{
  25. HeaderNameCountryCode: "Code",
  26. HeaderNameCountryName: "CountryName",
  27. HeaderNameCountryIsEU: "Eu",
  28. HeaderNameCityName: "CityName",
  29. HeaderNameLocationLat: "Lat",
  30. HeaderNameLocationLon: "Lon",
  31. HeaderNameLocationTimeZone: "TZ",
  32. }
  33. if !reflect.DeepEqual(expected, actual) {
  34. t.Errorf("Expected %v actual %v", expected, actual)
  35. }
  36. }