mirror of
https://github.com/kataras/iris.git
synced 2025-12-19 10:57:05 +00:00
reorganization of _examples and add some new examples such as iris+groupcache+mysql+docker
Former-commit-id: ed635ee95de7160cde11eaabc0c1dcb0e460a620
This commit is contained in:
57
_examples/routing/subdomains/www/main_test.go
Normal file
57
_examples/routing/subdomains/www/main_test.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/kataras/iris/v12/httptest"
|
||||
)
|
||||
|
||||
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"
|
||||
e := httptest.New(t, app, httptest.Debug(false))
|
||||
|
||||
for _, test := range tests {
|
||||
|
||||
req := e.Request(test.method, test.path)
|
||||
if subdomain := test.subdomain; subdomain != "" {
|
||||
req.WithURL("http://" + subdomain + "." + host)
|
||||
}
|
||||
|
||||
req.Expect().
|
||||
Status(httptest.StatusOK).
|
||||
Body().Equal(test.response())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user