mirror of
https://github.com/mpolden/echoip.git
synced 2024-11-10 07:27:22 +01:00
parent
36fba6ff54
commit
2495b3803a
@ -243,9 +243,9 @@ func (a *API) Handlers() http.Handler {
|
||||
|
||||
// CLI
|
||||
r.Handle("/", appHandler(a.CLIHandler)).Methods("GET").MatcherFunc(cliMatcher)
|
||||
r.Handle("/ip", appHandler(a.CLIHandler)).Methods("GET").MatcherFunc(cliMatcher)
|
||||
r.Handle("/country", appHandler(a.CLICountryHandler)).Methods("GET").MatcherFunc(cliMatcher)
|
||||
r.Handle("/city", appHandler(a.CLICityHandler)).Methods("GET").MatcherFunc(cliMatcher)
|
||||
r.Handle("/ip", appHandler(a.CLIHandler)).Methods("GET")
|
||||
r.Handle("/country", appHandler(a.CLICountryHandler)).Methods("GET")
|
||||
r.Handle("/city", appHandler(a.CLICityHandler)).Methods("GET")
|
||||
|
||||
// Browser
|
||||
r.Handle("/", appHandler(a.DefaultHandler)).Methods("GET")
|
||||
|
@ -46,24 +46,25 @@ func httpGet(url string, json bool, userAgent string) (string, int, error) {
|
||||
return string(data), res.StatusCode, nil
|
||||
}
|
||||
|
||||
func TestClIHandlers(t *testing.T) {
|
||||
func TestCLIHandlers(t *testing.T) {
|
||||
log.SetOutput(ioutil.Discard)
|
||||
s := httptest.NewServer(newTestAPI().Handlers())
|
||||
|
||||
var tests = []struct {
|
||||
url string
|
||||
out string
|
||||
status int
|
||||
url string
|
||||
out string
|
||||
status int
|
||||
userAgent string
|
||||
}{
|
||||
{s.URL, "127.0.0.1\n", 200},
|
||||
{s.URL + "/ip", "127.0.0.1\n", 200},
|
||||
{s.URL + "/country", "Elbonia\n", 200},
|
||||
{s.URL + "/city", "Bornyasherk\n", 200},
|
||||
{s.URL + "/foo", "404 page not found", 404},
|
||||
{s.URL, "127.0.0.1\n", 200, "curl/7.43.0"},
|
||||
{s.URL + "/ip", "127.0.0.1\n", 200, ""},
|
||||
{s.URL + "/country", "Elbonia\n", 200, ""},
|
||||
{s.URL + "/city", "Bornyasherk\n", 200, ""},
|
||||
{s.URL + "/foo", "404 page not found", 404, ""},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
out, status, err := httpGet(tt.url /* json = */, false, "curl/7.2.6.0")
|
||||
out, status, err := httpGet(tt.url /* json = */, false, tt.userAgent)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user