فهرست منبع

Add test config

Andrey Blinov 7 سال پیش
والد
کامیت
c75655fe0b
3فایلهای تغییر یافته به همراه49 افزوده شده و 0 حذف شده
  1. 39 0
      config_test.go
  2. 10 0
      handler_test.go
  3. 0 0
      setup.go

+ 39 - 0
config_test.go

@@ -0,0 +1,39 @@
+package geoip
+
+import (
+	"reflect"
+	"testing"
+
+	"github.com/mholt/caddy"
+)
+
+func TestParseConfig(t *testing.T) {
+	controller := caddy.NewTestController("http", `
+		localhost:8080
+		geoip {
+			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{
+		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)
+	}
+}

+ 10 - 0
handler_test.go

@@ -0,0 +1,10 @@
+package geoip
+
+import (
+	"testing"
+)
+
+func TestInvokeOK(t *testing.T) {
+	//gip := GeoIP{}
+	//caddy.NewTestController("http", test.input)
+}

+ 0 - 0
init.go → setup.go