2017-06-15 19:02:08 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12/httptest"
|
2017-06-15 19:02:08 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type testRoute struct {
|
|
|
|
path string
|
|
|
|
method string
|
|
|
|
subdomain string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r testRoute) response() string {
|
|
|
|
msg := fmt.Sprintf("\nInfo\n\nMethod: %s\nSubdomain: %s\nPath: %s", r.method, r.subdomain, r.path)
|
|
|
|
return msg
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSubdomainWWW(t *testing.T) {
|
|
|
|
app := newApp()
|
|
|
|
|
|
|
|
tests := []testRoute{
|
|
|
|
// host
|
|
|
|
{"/", "GET", ""},
|
|
|
|
{"/about", "GET", ""},
|
|
|
|
{"/contact", "GET", ""},
|
|
|
|
{"/api/users", "GET", ""},
|
|
|
|
{"/api/users/42", "GET", ""},
|
|
|
|
{"/api/users", "POST", ""},
|
|
|
|
{"/api/users/42", "PUT", ""},
|
|
|
|
// www sub domain
|
|
|
|
{"/", "GET", "www"},
|
|
|
|
{"/about", "GET", "www"},
|
|
|
|
{"/contact", "GET", "www"},
|
|
|
|
{"/api/users", "GET", "www"},
|
|
|
|
{"/api/users/42", "GET", "www"},
|
|
|
|
{"/api/users", "POST", "www"},
|
|
|
|
{"/api/users/42", "PUT", "www"},
|
|
|
|
}
|
|
|
|
|
|
|
|
host := "localhost:1111"
|
2019-06-21 18:43:25 +02:00
|
|
|
e := httptest.New(t, app, httptest.Debug(false))
|
2017-06-15 19:02:08 +02:00
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
|
|
|
|
req := e.Request(test.method, test.path)
|
|
|
|
if subdomain := test.subdomain; subdomain != "" {
|
2018-01-25 05:31:05 +01:00
|
|
|
req.WithURL("http://" + subdomain + "." + host)
|
2017-06-15 19:02:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
req.Expect().
|
2017-07-10 17:32:42 +02:00
|
|
|
Status(httptest.StatusOK).
|
2023-07-08 01:08:18 +02:00
|
|
|
Body().IsEqual(test.response())
|
2017-06-15 19:02:08 +02:00
|
|
|
}
|
|
|
|
}
|