Browse Source

Added unit test for mounting applications at root.

master
Benjamin Shelton 2 weeks ago
parent
commit
a9cd77d01b
1 changed files with 119 additions and 0 deletions
  1. +119
    -0
      tests/multiapp_test.go

+ 119
- 0
tests/multiapp_test.go View File

@ -2,6 +2,7 @@ package tests
import (
"bytes"
"fmt"
"testing"
"git.destrealm.org/go/capstan"
@ -123,6 +124,124 @@ func Test_MultiApp(t *testing.T) {
}
}
func Test_MultiAppAtRoot(t *testing.T) {
server := NewServer(func(app capstan.Application) {
app.Config().Server.Hostname = "example.com"
subapp1 := capstan.New(&config.Config{
Server: &config.ServerConfig{
Hostname: "example.com",
},
})
subapp1.Bind(&MultiAppController{
test: "index",
BaseController: capstan.BaseController{
Path: "/",
},
})
fmt.Println("attach subapp1")
app.AttachApplication(subapp1)
subapp2 := capstan.New(&config.Config{
Server: &config.ServerConfig{
Hostname: "example.com",
BasePath: "/app",
},
})
subapp2.Bind(&MultiAppController{
test: "subapp2",
BaseController: capstan.BaseController{
Path: "/",
},
})
fmt.Println("attach subapp2")
app.AttachApplication(subapp2)
subapp3 := capstan.New(&config.Config{
Server: &config.ServerConfig{
Hostname: "example.com",
BasePath: "/app3",
},
})
subapp3.Bind(&MultiAppController{
test: "subapp3",
BaseController: capstan.BaseController{
Path: "/",
},
})
fmt.Println("attach subapp3")
app.AttachApplication(subapp3)
})
defer server.Close()
requester := please.MakeRequest(server.URL)
requester.SetClient(server.Client())
req := requester.Get("/")
req.Host = "example.com"
response, err := req.Commit()
if err != nil {
t.Fatalf("/: response error during request: %v", errors.Unfurl(err))
}
if response.StatusCode != 200 {
t.Errorf("/: response received non-200 status code: %d", response.StatusCode)
}
out, err := response.ReadAll()
if err != nil {
t.Errorf("/: error reading body: %v", errors.Unfurl(err))
}
if bytes.Compare(out, []byte("index: index")) != 0 {
t.Errorf("expected `index`; got %s", string(out))
}
req = requester.Get("/app")
req.Host = "example.com"
response, err = req.Commit()
if err != nil {
t.Fatalf("/app: response error during request: %v", errors.Unfurl(err))
}
if response.StatusCode != 200 {
t.Errorf("/app: response received non-200 status code: %d", response.StatusCode)
}
out, err = response.ReadAll()
if err != nil {
t.Errorf("/app: error reading body: %v", errors.Unfurl(err))
}
if bytes.Compare(out, []byte("index: subapp2")) != 0 {
t.Errorf("expected `index`; got %s", string(out))
}
req = requester.Get("/app3")
req.Host = "example.com"
response, err = req.Commit()
if err != nil {
t.Fatalf("/app3: response error during request: %v", errors.Unfurl(err))
}
if response.StatusCode != 200 {
t.Errorf("/app3: response received non-200 status code: %d", response.StatusCode)
}
out, err = response.ReadAll()
if err != nil {
t.Errorf("/app3: error reading body: %v", errors.Unfurl(err))
}
if bytes.Compare(out, []byte("index: subapp3")) != 0 {
t.Errorf("expected `index`; got %s", string(out))
}
}
func Test_MultiAppMultiPathMultiDomain(t *testing.T) {
server := NewServer(func(app capstan.Application) {
app.Bind(&MultiAppController{


Loading…
Cancel
Save