|
package auth_test
import (
"testing"
"github.com/RedHatInsights/insights-results-smart-proxy/auth"
)
func TestConstructRBACURL ( t * testing . T ) {
tests := [ ] struct {
config * auth . RBACConfig
expectedURL string
expectedHost string
expectError bool
} {
{
config : & auth . RBACConfig { URL : "example.com" } ,
expectedURL : "https://example.com/access/?application=ocp-advisor&limit=100" ,
expectedHost : "example.com" ,
expectError : false ,
} ,
{
config : & auth . RBACConfig { URL : "http://example.com" } ,
expectedURL : "http://example.com/access/?application=ocp-advisor&limit=100" ,
expectedHost : "example.com" ,
expectError : false ,
} ,
{
|
ephemeral case:
|
config : & auth . RBACConfig { URL : "http://rbac-service:8000/api/rbac/v1" } ,
expectedURL : "http://rbac-service:8000/api/rbac/v1/access/?application=ocp-advisor&limit=100" ,
expectedHost : "rbac-service:8000" ,
expectError : false ,
} ,
{
config : & auth . RBACConfig { URL : "wrong-schema:/invalid" } ,
expectedURL : "https://wrong-schema:/invalid/access/?application=ocp-advisor&limit=100" ,
expectedHost : "wrong-schema:" ,
expectError : false ,
} ,
}
for _ , tt := range tests {
base , host , err := auth . ConstructRBACURL ( tt . config )
|
If no error is expected, check the returned values
|
if ! tt . expectError {
if base != tt . expectedURL {
t . Errorf ( "expected base URL: %s, got: %s" , tt . expectedURL , base )
}
if host != tt . expectedHost {
t . Errorf ( "expected host: %s, got: %s" , tt . expectedHost , host )
}
}
}
}
|