Skip to content

Commit

Permalink
Updated errors and added Unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
BCarvalheira committed Apr 29, 2024
1 parent b3dccb4 commit cc75709
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/frontend/openshiftcluster_preflightvalidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ func (f *frontend) _preflightValidation(ctx context.Context, log *logrus.Entry,
doc, err := f.dbOpenShiftClusters.Get(ctx, resourceID)
isCreate := cosmosdb.IsErrorStatusCode(err, http.StatusNotFound)
if err != nil && !cosmosdb.IsErrorStatusCode(err, http.StatusNotFound) {
log.Warning(err.Error())
return api.ValidationResult{
Status: api.ValidationStatusFailed,
Error: &api.CloudErrorBody{
Message: err.Error(),
Message: "400: Cluster not found for resourceID: " + resourceID,
},
}
}
Expand All @@ -91,10 +92,11 @@ func (f *frontend) _preflightValidation(ctx context.Context, log *logrus.Entry,
staticValidator := f.apis[apiVersion].OpenShiftClusterStaticValidator
ext := converter.ToExternal(oc)
if err = json.Unmarshal(raw, &ext); err != nil {
log.Warning(err.Error())
return api.ValidationResult{
Status: api.ValidationStatusFailed,
Error: &api.CloudErrorBody{
Message: err.Error(),
Message: api.CloudErrorCodeInternalServerError,
},
}
}
Expand Down
40 changes: 40 additions & 0 deletions pkg/frontend/openshiftcluster_preflightvalidation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,46 @@ func TestPreflightValidation(t *testing.T) {
},
},
},
{
name: "Failed Preflight Cluster Check",
fixture: func(f *testdatabase.Fixture) {
f.AddSubscriptionDocuments(&api.SubscriptionDocument{
ID: api.ExampleOpenShiftClusterDocument().ID,
Subscription: &api.Subscription{
State: api.SubscriptionStateRegistered,
Properties: &api.SubscriptionProperties{
TenantID: api.ExampleOpenShiftClusterDocument().ClientIDKey,
},
},
})
},
preflightRequest: func() *api.PreflightRequest {
return &api.PreflightRequest{
Resources: []json.RawMessage{
[]byte(fmt.Sprintf(`
{
"apiVersion": "%s",
"id": "%s",
"name": "%s",
"type": "%s",
"location": "%s",
"properties": {}
}
`, apiVersion, "resourceGroups/resourceGroup/providers/Microsoft.RedHatOpenShift/openShiftClusters/resourceName",
api.ExampleOpenShiftClusterDocument().OpenShiftCluster.Name,
api.ExampleOpenShiftClusterDocument().OpenShiftCluster.Type,
location)),
},
}
},
wantStatusCode: http.StatusOK,
wantResponse: &api.ValidationResult{
Status: api.ValidationStatusFailed,
Error: &api.CloudErrorBody{
Message: "400: Cluster not found for resourceID: resourcegroups/resourcegroup/providers/microsoft.redhatopenshift/openshiftclusters/resourcename",
},
},
},
{
name: "Failed Preflight Install Version",
fixture: func(f *testdatabase.Fixture) {
Expand Down

0 comments on commit cc75709

Please sign in to comment.