Files
atlantis/server/router_test.go
Luke Kysow fa4aad4a74 Refine basepath changes.
- Refactoring work from https://github.com/runatlantis/atlantis/pull/314
- Use just the path in templates, not the fully qualified URL since that
is a best practice.
- Add logging to errors when rendering templates.
- Silence help output on cli errors since the help output is now so
large that you have to scroll up to see the errors.
2018-11-21 11:33:31 -06:00

63 lines
1.7 KiB
Go

package server_test
import (
"net/http"
"testing"
"github.com/gorilla/mux"
"github.com/runatlantis/atlantis/server"
. "github.com/runatlantis/atlantis/testing"
)
func TestRouter_GenerateLockURL(t *testing.T) {
cases := []struct {
AtlantisURL string
ExpURL string
}{
{
"http://localhost:4141",
"http://localhost:4141/lock?id=lkysow%252Fatlantis-example%252F.%252Fdefault",
},
{
"https://localhost:4141",
"https://localhost:4141/lock?id=lkysow%252Fatlantis-example%252F.%252Fdefault",
},
{
"https://localhost:4141/",
"https://localhost:4141/lock?id=lkysow%252Fatlantis-example%252F.%252Fdefault",
},
{
"https://example.com/basepath",
"https://example.com/basepath/lock?id=lkysow%252Fatlantis-example%252F.%252Fdefault",
},
{
"https://example.com/basepath/",
"https://example.com/basepath/lock?id=lkysow%252Fatlantis-example%252F.%252Fdefault",
},
{
"https://example.com/path/1/",
"https://example.com/path/1/lock?id=lkysow%252Fatlantis-example%252F.%252Fdefault",
},
}
queryParam := "id"
routeName := "routename"
underlyingRouter := mux.NewRouter()
underlyingRouter.HandleFunc("/lock", func(_ http.ResponseWriter, _ *http.Request) {}).Methods("GET").Queries(queryParam, "{id}").Name(routeName)
for _, c := range cases {
t.Run(c.AtlantisURL, func(t *testing.T) {
atlantisURL, err := server.ParseAtlantisURL(c.AtlantisURL)
Ok(t, err)
router := &server.Router{
AtlantisURL: atlantisURL,
LockViewRouteIDQueryParam: queryParam,
LockViewRouteName: routeName,
Underlying: underlyingRouter,
}
Equals(t, c.ExpURL, router.GenerateLockURL("lkysow/atlantis-example/./default"))
})
}
}