1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package geoip
- import (
- "reflect"
- "testing"
- "github.com/mholt/caddy"
- )
- func TestParseConfig(t *testing.T) {
- controller := caddy.NewTestController("http", `
- localhost:8080
- geoip {
- database path/to/maxmind/db
- set_header_country_code Code
- set_header_country_name CountryName
- set_header_country_eu Eu
- set_header_city_name CityName
- set_header_location_lat Lat
- set_header_location_lon Lon
- set_header_location_tz TZ
- }
- `)
- actual, err := parseConfig(controller)
- if err != nil {
- t.Errorf("parseConfig return err: %v", err)
- }
- expected := Config{
- DatabasePath: "path/to/maxmind/db",
- HeaderNameCountryCode: "Code",
- HeaderNameCountryName: "CountryName",
- HeaderNameCountryIsEU: "Eu",
- HeaderNameCityName: "CityName",
- HeaderNameLocationLat: "Lat",
- HeaderNameLocationLon: "Lon",
- HeaderNameLocationTimeZone: "TZ",
- }
- if !reflect.DeepEqual(expected, actual) {
- t.Errorf("Expected %v actual %v", expected, actual)
- }
- }
|