зеркало из https://github.com/Azure/ARO-RP.git
Add unit tests
This commit is contained in:
Родитель
401380f572
Коммит
d76314eb97
|
@ -306,7 +306,7 @@ func enrichClusterSystemData(doc *api.OpenShiftClusterDocument, systemData *api.
|
|||
}
|
||||
|
||||
func validateIdentityUrl(cluster *api.OpenShiftCluster, identityURL string, isCreate bool) error {
|
||||
if err := validateIdentityParam(cluster, identityURL, isCreate); err != nil {
|
||||
if err := validateIdentityParam(identityURL, isCreate); err != nil {
|
||||
return fmt.Errorf("%w: %s", err, "identity URL")
|
||||
}
|
||||
|
||||
|
@ -316,7 +316,7 @@ func validateIdentityUrl(cluster *api.OpenShiftCluster, identityURL string, isCr
|
|||
}
|
||||
|
||||
func validateIdentityTenantID(cluster *api.OpenShiftCluster, identityTenantID string, isCreate bool) error {
|
||||
if err := validateIdentityParam(cluster, identityTenantID, isCreate); err != nil {
|
||||
if err := validateIdentityParam(identityTenantID, isCreate); err != nil {
|
||||
return fmt.Errorf("%w: %s", err, "identity tenant ID")
|
||||
}
|
||||
|
||||
|
@ -325,7 +325,7 @@ func validateIdentityTenantID(cluster *api.OpenShiftCluster, identityTenantID st
|
|||
return nil
|
||||
}
|
||||
|
||||
func validateIdentityParam(cluster *api.OpenShiftCluster, param string, isCreate bool) error {
|
||||
func validateIdentityParam(param string, isCreate bool) error {
|
||||
if param == "" {
|
||||
if isCreate {
|
||||
return errMissingIdentityParmeter
|
||||
|
|
|
@ -6,6 +6,7 @@ package frontend
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
@ -3315,50 +3316,21 @@ func TestValidateIdentityUrl(t *testing.T) {
|
|||
isCreate bool
|
||||
wantError error
|
||||
}{
|
||||
{
|
||||
name: "identity URL is empty, is not wi/mi cluster create",
|
||||
identityURL: "",
|
||||
cluster: &api.OpenShiftCluster{},
|
||||
expected: &api.OpenShiftCluster{},
|
||||
isCreate: false,
|
||||
},
|
||||
{
|
||||
name: "identity URL is empty, is wi/mi cluster create",
|
||||
identityURL: "",
|
||||
cluster: &api.OpenShiftCluster{},
|
||||
expected: &api.OpenShiftCluster{},
|
||||
isCreate: true,
|
||||
wantError: errMissingIdentityURL,
|
||||
wantError: errMissingIdentityParmeter,
|
||||
},
|
||||
{
|
||||
name: "cluster is not wi/mi, identityURL passed",
|
||||
identityURL: "http://foo.bar",
|
||||
cluster: &api.OpenShiftCluster{
|
||||
Properties: api.OpenShiftClusterProperties{
|
||||
ServicePrincipalProfile: &api.ServicePrincipalProfile{},
|
||||
},
|
||||
},
|
||||
expected: &api.OpenShiftCluster{
|
||||
Properties: api.OpenShiftClusterProperties{
|
||||
ServicePrincipalProfile: &api.ServicePrincipalProfile{},
|
||||
},
|
||||
},
|
||||
isCreate: true,
|
||||
},
|
||||
{
|
||||
name: "cluster is not wi/mi, identityURL not passed",
|
||||
name: "identity URL is empty, is not wi/mi cluster create",
|
||||
identityURL: "",
|
||||
cluster: &api.OpenShiftCluster{
|
||||
Properties: api.OpenShiftClusterProperties{
|
||||
ServicePrincipalProfile: &api.ServicePrincipalProfile{},
|
||||
},
|
||||
},
|
||||
expected: &api.OpenShiftCluster{
|
||||
Properties: api.OpenShiftClusterProperties{
|
||||
ServicePrincipalProfile: &api.ServicePrincipalProfile{},
|
||||
},
|
||||
},
|
||||
isCreate: true,
|
||||
cluster: &api.OpenShiftCluster{},
|
||||
expected: &api.OpenShiftCluster{},
|
||||
isCreate: false,
|
||||
wantError: nil,
|
||||
},
|
||||
{
|
||||
name: "pass - identity URL passed on wi/mi cluster",
|
||||
|
@ -3376,7 +3348,7 @@ func TestValidateIdentityUrl(t *testing.T) {
|
|||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := validateIdentityUrl(tt.cluster, tt.identityURL, tt.isCreate)
|
||||
if err != nil && err != tt.wantError {
|
||||
if !errors.Is(err, tt.wantError) {
|
||||
t.Error(cmp.Diff(err, tt.wantError))
|
||||
}
|
||||
|
||||
|
@ -3386,3 +3358,90 @@ func TestValidateIdentityUrl(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateIdentityTenantID(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
tenantID string
|
||||
cluster *api.OpenShiftCluster
|
||||
expected *api.OpenShiftCluster
|
||||
isCreate bool
|
||||
wantError error
|
||||
}{
|
||||
{
|
||||
name: "tenantID is empty, is wi/mi cluster create",
|
||||
tenantID: "",
|
||||
cluster: &api.OpenShiftCluster{},
|
||||
expected: &api.OpenShiftCluster{},
|
||||
isCreate: true,
|
||||
wantError: errMissingIdentityParmeter,
|
||||
},
|
||||
{
|
||||
name: "tenantID is empty, is not wi/mi cluster create",
|
||||
tenantID: "",
|
||||
cluster: &api.OpenShiftCluster{},
|
||||
expected: &api.OpenShiftCluster{},
|
||||
isCreate: false,
|
||||
wantError: nil,
|
||||
},
|
||||
{
|
||||
name: "pass - tenantID passed on wi/mi cluster",
|
||||
cluster: &api.OpenShiftCluster{
|
||||
Identity: &api.Identity{},
|
||||
},
|
||||
tenantID: "bogus",
|
||||
expected: &api.OpenShiftCluster{
|
||||
Identity: &api.Identity{
|
||||
TenantID: "bogus",
|
||||
},
|
||||
},
|
||||
isCreate: true,
|
||||
},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := validateIdentityTenantID(tt.cluster, tt.tenantID, tt.isCreate)
|
||||
if !errors.Is(err, tt.wantError) {
|
||||
t.Error(cmp.Diff(err, tt.wantError))
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(tt.cluster, tt.expected) {
|
||||
t.Error(cmp.Diff(tt.cluster, tt.expected))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateIdentityParam(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
param string
|
||||
isCreate bool
|
||||
wantError error
|
||||
}{
|
||||
{
|
||||
name: "param is empty, is wi/mi cluster create",
|
||||
param: "",
|
||||
isCreate: true,
|
||||
wantError: errMissingIdentityParmeter,
|
||||
},
|
||||
{
|
||||
name: "param is empty, is not wi/mi cluster create",
|
||||
param: "",
|
||||
isCreate: false,
|
||||
wantError: nil,
|
||||
},
|
||||
{
|
||||
name: "pass - param passed on wi/mi cluster",
|
||||
param: "bogus",
|
||||
isCreate: true,
|
||||
wantError: nil,
|
||||
},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := validateIdentityParam(tt.param, tt.isCreate)
|
||||
if !errors.Is(err, tt.wantError) {
|
||||
t.Error(cmp.Diff(err, tt.wantError))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче