112 lines
1.9 KiB
Go
112 lines
1.9 KiB
Go
|
|
package cognitoauth
|
||
|
|
|
||
|
|
import (
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"github.com/stretchr/testify/assert"
|
||
|
|
)
|
||
|
|
|
||
|
|
// TestGetResourceFromRoute tests the resource mapping function
|
||
|
|
func TestGetResourceFromRoute(t *testing.T) {
|
||
|
|
tests := []struct {
|
||
|
|
name string
|
||
|
|
route string
|
||
|
|
expected string
|
||
|
|
}{
|
||
|
|
{
|
||
|
|
name: "SimpleRoute",
|
||
|
|
route: "/document",
|
||
|
|
expected: "document",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "RouteWithID",
|
||
|
|
route: "/document/123",
|
||
|
|
expected: "document",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "RouteWithMultipleSegments",
|
||
|
|
route: "/document/foo/123",
|
||
|
|
expected: "document",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "NestedRoute",
|
||
|
|
route: "/api/v1/document",
|
||
|
|
expected: "api",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "RootRoute",
|
||
|
|
route: "/",
|
||
|
|
expected: "",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "RouteWithoutLeadingSlash",
|
||
|
|
route: "document",
|
||
|
|
expected: "document",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "RouteWithoutLeadingSlashMultipleSegments",
|
||
|
|
route: "document/foo/123",
|
||
|
|
expected: "document",
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
for _, tt := range tests {
|
||
|
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
|
result := GetResourceFromRoute(tt.route)
|
||
|
|
assert.Equal(t, tt.expected, result)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// TestGetActionFromMethod tests the action mapping function
|
||
|
|
func TestGetActionFromMethod(t *testing.T) {
|
||
|
|
tests := []struct {
|
||
|
|
name string
|
||
|
|
method string
|
||
|
|
expected string
|
||
|
|
}{
|
||
|
|
{
|
||
|
|
name: "GET",
|
||
|
|
method: "GET",
|
||
|
|
expected: "get",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "POST",
|
||
|
|
method: "POST",
|
||
|
|
expected: "post",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "PUT",
|
||
|
|
method: "PUT",
|
||
|
|
expected: "put",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "DELETE",
|
||
|
|
method: "DELETE",
|
||
|
|
expected: "delete",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "PATCH",
|
||
|
|
method: "PATCH",
|
||
|
|
expected: "patch",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "LowercaseMethod",
|
||
|
|
method: "get",
|
||
|
|
expected: "get",
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "MixedCaseMethod",
|
||
|
|
method: "GeT",
|
||
|
|
expected: "get",
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
for _, tt := range tests {
|
||
|
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
|
result := GetActionFromMethod(tt.method)
|
||
|
|
assert.Equal(t, tt.expected, result)
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|