Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix condition step tests #3046

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/util/steps/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,20 @@ func (c conditionStep) run(ctx context.Context, log *logrus.Entry) error {
return nil
}
if errors.Is(err, wait.ErrWaitTimeout) {
return enrichConditionTimeoutError(c.f)
return enrichConditionTimeoutError(c.f, err)
}
return err
}

// Instead of giving Generic, timed out waiting for a condition, error
// returns enriched error messages mentioned in timeoutConditionErrors
func enrichConditionTimeoutError(f conditionFunction) error {
func enrichConditionTimeoutError(f conditionFunction, originalErr error) error {
funcNameParts := strings.Split(FriendlyName(f), ".")
funcName := strings.TrimSuffix(funcNameParts[len(funcNameParts)-1], "-fm")

message, exists := timeoutConditionErrors[funcName]
if !exists {
return errors.New("timed out waiting for the condition")
return originalErr
}
return api.NewCloudError(
http.StatusInternalServerError,
Expand Down
17 changes: 10 additions & 7 deletions pkg/util/steps/condition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package steps

import (
"context"
"errors"
"testing"
)

Expand All @@ -23,17 +24,19 @@ func hiveClusterInstallationComplete(context.Context) (bool, error) { ret

func TestEnrichConditionTimeoutError(t *testing.T) {
for _, tt := range []struct {
desc string
function conditionFunction
wantErr string
desc string
function conditionFunction
originalErr string
wantErr string
}{
// Verify response for func's mention in timeoutConditionErrors and
// Emit generic Error if an unknown func
{
// unknown function
desc: "test conditionfail for func - unknownFunc",
function: timingOutCondition,
wantErr: "timed out waiting for the condition",
desc: "test conditionfail for func - unknownFunc",
function: timingOutCondition,
originalErr: "timed out waiting for the condition",
wantErr: "timed out waiting for the condition",
},
{
desc: "test conditionfail for func - apiServersReady",
Expand Down Expand Up @@ -87,7 +90,7 @@ func TestEnrichConditionTimeoutError(t *testing.T) {
},
} {
t.Run(tt.desc, func(t *testing.T) {
if got := enrichConditionTimeoutError(tt.function); got.Error() != tt.wantErr {
if got := enrichConditionTimeoutError(tt.function, errors.New(tt.originalErr)); got.Error() != tt.wantErr {
t.Errorf("invlaid enrichConditionTimeoutError: %s, got: %s", tt.wantErr, got)
}
})
Expand Down