package router import ( "bytes" "html/template" "net/http" "testing" "github.com/stretchr/testify/assert" ) const expectedHome = ` What is my IP Address ?

What is my IP ?


Your IPv4 address is: 127.0.0.1

Client Port 1000
Host localhost

Geolocation

Country A Country
Country Code XX
City A City
Latitude 100
Longitude -100
Postal Code 00000
Time Zone My/Timezone

Autonomous System

ASN 0
ASN Organization My ISP

Headers

Header1 value1
Header2 value21
Header2 value22
Header3 value3
` func TestDefaultTemplate(t *testing.T) { req, _ := http.NewRequest("GET", "/", nil) req.Header = map[string][]string{ "Header1": {"value1"}, "Header2": {"value21", "value22"}, "Header3": {"value3"}, } tmpl, _ := template.New("home").Parse(home) response := JSONResponse{ IP: "127.0.0.1", IPVersion: 4, ClientPort: "1000", Country: "A Country", CountryCode: "XX", City: "A City", Latitude: 100, Longitude: -100, PostalCode: "00000", TimeZone: "My/Timezone", ASN: 0, ASNOrganization: "My ISP", Host: "localhost", Headers: req.Header, } buf := &bytes.Buffer{} err := tmpl.Execute(buf, response) assert.Nil(t, err) assert.Equal(t, expectedHome, buf.String()) }