constructURLForClustersDetail function constructs an URL to access
the endpoint to retrieve results metadata for given cluster from selected
organization and rule selector
|
func constructURLForClustersDetail (
organizationID string , ruleSelector types . RuleSelector , userID types . UserID ) string {
return httputils . MakeURLToEndpoint ( apiURL ,
server . RuleClusterDetailEndpoint , ruleSelector , organizationID , userID )
}
func checkResponseContent ( f * frisby . Frisby , expectedResponse ClusterInfoResponse ) {
text , err := f . Resp . Content ( )
if err != nil {
f . AddError ( err . Error ( ) )
} else {
response := ClusterInfoResponse { }
err := json . Unmarshal ( text , & response )
if err != nil {
f . AddError ( err . Error ( ) )
}
if response . Status != expectedResponse . Status {
f . AddError ( fmt . Sprintf ( "Expecting 'status' to be set to %q but got %q" , expectedResponse . Status , response . Status ) )
}
equal := assert . ObjectsAreEqualValues ( expectedResponse . Clusters , response . Clusters )
if ! equal {
f . AddError ( fmt . Sprintf ( "Expecting clusters to be set to\n%v\nbut got\n%v" , expectedResponse . Clusters , response . Clusters ) )
}
}
f . PrintReport ( )
}
|
checkClustersDetailEndpointGet check if the endpoint to return the cluster detail works as expected with GET method.
For this test there is this data:
| Organization | Cluster | Rule | Version |
|--------------|--------------------------------------|-----------------------------------------------------------|--------------------|
| 1 | 11111111-1111-1111-1111-111111111111 | ccxrulesocp.external.rules.nodeinstallerdegraded|ek1 | 1.0 |
| 2 | 22222222-2222-2222-2222-222222222222 | ccxrulesocp.external.rules.nodeinstallerdegraded|ek1 | (empty) |
| 3 | 33333333-3333-3333-3333-333333333333 | ccxrulesocp.external.rules.nodeinstallerdegraded|ek1 | not in report_info |
|
func checkClustersEndpointDetailGet ( ) {
type testCase struct {
name string
organizationID string
ruleSelector types . RuleSelector
expectStatus int
expectedResponse ClusterInfoResponse
}
table := [ ] testCase {
{
name : "Check the endpoint to return cluster information: known organization and rule found" ,
expectStatus : 200 ,
organizationID : "1" ,
ruleSelector : types . RuleSelector ( testdata . Rule1CompositeID ) ,
expectedResponse : ClusterInfoResponse {
Status : "ok" ,
Clusters : [ ] ClusterInfo {
{
Cluster : "11111111-1111-1111-1111-111111111111" ,
Meta : ClusterInfoMeta { Version : "1.0" } ,
} ,
} ,
} ,
} ,
{
name : "Check the endpoint to return cluster information: known organization and rule didn't find any clusters" ,
expectStatus : 404 ,
organizationID : "1" ,
ruleSelector : types . RuleSelector ( testdata . Rule2CompositeID ) ,
expectedResponse : ClusterInfoResponse {
Status : fmt . Sprintf ( "Item with ID %s was not found in the storage" , testdata . Rule2CompositeID ) ,
} ,
} ,
{
name : "Check the endpoint to return cluster information: known organization and version is empty" ,
expectStatus : 200 ,
organizationID : "2" ,
ruleSelector : types . RuleSelector ( testdata . Rule1CompositeID ) ,
expectedResponse : ClusterInfoResponse {
Status : "ok" ,
Clusters : [ ] ClusterInfo {
{
Cluster : "22222222-2222-2222-2222-222222222222" ,
} ,
} ,
} ,
} ,
{
name : "Check the endpoint to return cluster information: known organization and there is no version in report_info" ,
expectStatus : 200 ,
organizationID : "3" ,
ruleSelector : types . RuleSelector ( testdata . Rule1CompositeID ) ,
expectedResponse : ClusterInfoResponse {
Status : "ok" ,
Clusters : [ ] ClusterInfo {
{
Cluster : "33333333-3333-3333-3333-333333333333" ,
} ,
} ,
} ,
} ,
{
name : "Check the endpoint to return cluster information: unknown organization" ,
expectStatus : 404 ,
organizationID : "24" ,
ruleSelector : types . RuleSelector ( testdata . Rule1CompositeID ) ,
expectedResponse : ClusterInfoResponse {
Status : fmt . Sprintf ( "Item with ID %s was not found in the storage" , testdata . Rule1CompositeID ) ,
} ,
} ,
{
name : "Check the endpoint to return cluster information: known organization invalid rule selector" ,
expectStatus : 400 ,
organizationID : "1" ,
ruleSelector : types . RuleSelector ( "not a rule" ) ,
expectedResponse : ClusterInfoResponse {
Status : fmt . Sprintf ( "Error during parsing param 'rule_selector' with value '%s'. Error: 'Param rule_selector is not a valid rule selector (plugin_name|error_key)'" , "not a rule" ) ,
} ,
} ,
}
for _ , tc := range table {
url := constructURLForClustersDetail ( tc . organizationID , tc . ruleSelector , testdata . UserID )
f := frisby . Create ( tc . name ) . Get ( url )
setAuthHeader ( f )
f . Send ( )
f . ExpectStatus ( tc . expectStatus )
f . ExpectHeader ( contentTypeHeader , ContentTypeJSON )
f . PrintReport ( )
checkResponseContent ( f , tc . expectedResponse )
if tc . expectStatus != 200 {
statusResponse := readStatusFromResponse ( f )
checkErrorStatusResponse ( f , statusResponse )
}
}
}
|