Skip to content

Commit

Permalink
fix(scorecard): error when constructing request should be checked (#843)
Browse files Browse the repository at this point in the history
* fix(scorecard): error when constructing request should be checked

Signed-off-by: Thuan Vo <[email protected]>

* chore(scorecard): better error message and avoid nil pointer

---------

Signed-off-by: Thuan Vo <[email protected]>
  • Loading branch information
tthvo authored Jun 5, 2024
1 parent 7025c66 commit e7b7afc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
20 changes: 17 additions & 3 deletions internal/test/scorecard/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ func get[r runtime.Object](ctx context.Context, c rest.Interface, res string, ns
if len(ns) > 0 {
rq = rq.Namespace(ns)
}
if err := rq.Error(); err != nil {
return result, err
}
err := rq.Do(ctx).Into(result)
return result, err
}
Expand All @@ -158,14 +161,22 @@ func create[r runtime.Object](ctx context.Context, c rest.Interface, res string,
if len(ns) > 0 {
rq = rq.Namespace(ns)
}
if err := rq.Error(); err != nil {
return result, err
}
err := rq.Do(ctx).Into(result)
return result, err
}

func update[r runtime.Object](ctx context.Context, c rest.Interface, res string, ns string, obj r, result r, name string) (r, error) {
err := c.Put().
Namespace(ns).Resource(res).Name(name).
Body(obj).Do(ctx).Into(result)
rq := c.Put().Resource(res).Name(name).Body(obj)
if len(ns) > 0 {
rq = rq.Namespace(ns)
}
if err := rq.Error(); err != nil {
return result, err
}
err := rq.Do(ctx).Into(result)
return result, err
}

Expand All @@ -174,6 +185,9 @@ func delete(ctx context.Context, c rest.Interface, res string, ns string, name s
if len(ns) > 0 {
rq = rq.Namespace(ns)
}
if err := rq.Error(); err != nil {
return err
}
return rq.Do(ctx).Error()
}

Expand Down
8 changes: 4 additions & 4 deletions internal/test/scorecard/common_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func configureIngress(name string, cryostatSpec *operatorv1beta2.CryostatSpec) {
func (r *TestResources) createAndWaitTillCryostatAvailable(cr *operatorv1beta2.Cryostat) (*operatorv1beta2.Cryostat, error) {
cr, err := r.Client.OperatorCRDs().Cryostats(cr.Namespace).Create(context.Background(), cr)
if err != nil {
r.logError(fmt.Sprintf("failed to create Cryostat CR: %s", err.Error()))
r.logError(fmt.Sprintf("failed to create Cryostat CR \"%s\": %s", cr.Name, err.Error()))
return nil, err
}

Expand All @@ -347,7 +347,7 @@ func (r *TestResources) createAndWaitTillCryostatAvailable(cr *operatorv1beta2.C
err = wait.PollUntilContextCancel(ctx, time.Second, true, func(ctx context.Context) (done bool, err error) {
cr, err = r.Client.OperatorCRDs().Cryostats(cr.Namespace).Get(ctx, cr.Name)
if err != nil {
return false, fmt.Errorf("failed to get Cryostat CR: %s", err.Error())
return false, fmt.Errorf("failed to get Cryostat CR \"%s\": %s", cr.Name, err.Error())
}
if len(cr.Spec.TargetNamespaces) > 0 {
if len(cr.Status.TargetNamespaces) == 0 {
Expand Down Expand Up @@ -457,7 +457,7 @@ func (r *TestResources) updateAndWaitTillCryostatAvailable(cr *operatorv1beta2.C
var err error
cr, err = r.Client.OperatorCRDs().Cryostats(cr.Namespace).Get(ctx, cr.Name)
if err != nil {
return fmt.Errorf("failed to get Cryostat CR: %s", err.Error())
return fmt.Errorf("failed to get Cryostat CR \"%s\": %s", cr.Name, err.Error())
}

cr.Spec.StorageOptions = &operatorv1beta2.StorageConfiguration{
Expand All @@ -477,7 +477,7 @@ func (r *TestResources) updateAndWaitTillCryostatAvailable(cr *operatorv1beta2.C
return err
})
if err != nil {
return nil, fmt.Errorf("failed to update Cryostat CR: %s", err.Error())
return nil, fmt.Errorf("failed to update Cryostat CR \"%s\": %s", cr.Name, err.Error())
}

// Poll the deployment until it becomes available or we timeout
Expand Down
4 changes: 2 additions & 2 deletions internal/test/scorecard/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func CryostatConfigChangeTest(bundle *apimanifests.Bundle, namespace string, ope
},
}

_, err = r.createAndWaitTillCryostatAvailable(cr)
cr, err = r.createAndWaitTillCryostatAvailable(cr)
if err != nil {
return r.fail(fmt.Sprintf("failed to determine application URL: %s", err.Error()))
}
Expand Down Expand Up @@ -243,7 +243,7 @@ func CryostatRecordingTest(bundle *apimanifests.Bundle, namespace string, openSh
return r.fail(fmt.Sprintf("failed to get the recordings: %s", err.Error()))
}
if rec.State != "STOPPED" {
return r.fail(fmt.Sprintf("recording %s failed to stop: %s", rec.Name, err.Error()))
return r.fail(fmt.Sprintf("expect recording %s to have state STOPPED but found %s", rec.Name, rec.State))
}
r.Log += fmt.Sprintf("stopped the recording: %s\n", rec.Name)

Expand Down

0 comments on commit e7b7afc

Please sign in to comment.