Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) getScaleUpTargetWithF
})

if traverseErr != nil {
return nil, err
return nil, traverseErr
}

if t == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package actionssummerwindnet

import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -362,6 +363,69 @@ func TestWebhookWorkflowJobWithSelfHostedLabel(t *testing.T) {
})
}

// TestGetScaleUpTargetWithFunctionPropagatesTraverseError ensures that an error hit while
// resolving a candidate organization/enterprise runner group is returned to the caller
// instead of being silently swallowed. Previously the error from visibleGroups.Traverse
// was discarded because it was checked via a shadowed `err` variable, causing the webhook
// to respond as if no matching HorizontalRunnerAutoscaler existed instead of surfacing the
// real error.
func TestGetScaleUpTargetWithFunctionPropagatesTraverseError(t *testing.T) {
hra := &actionsv1alpha1.HorizontalRunnerAutoscaler{
ObjectMeta: metav1.ObjectMeta{
Name: "test-name",
},
Spec: actionsv1alpha1.HorizontalRunnerAutoscalerSpec{
ScaleTargetRef: actionsv1alpha1.ScaleTargetRef{
Name: "test-name",
},
},
}

rd := &actionsv1alpha1.RunnerDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: "test-name",
},
Spec: actionsv1alpha1.RunnerDeploymentSpec{
Template: actionsv1alpha1.RunnerTemplate{
Spec: actionsv1alpha1.RunnerSpec{
RunnerConfig: actionsv1alpha1.RunnerConfig{
Organization: "MYORG",
},
},
},
},
}

client := fake.NewClientBuilder().
WithScheme(sc).
WithRuntimeObjects(hra, rd).
Build()

autoscaler := &HorizontalRunnerAutoscalerGitHubWebhook{
Client: client,
Log: logr.Discard(),
}

wantErr := fmt.Errorf("boom: transient error while resolving runner group")

// Simulate a repo-scoped lookup miss followed by a failure while resolving the
// organization-scoped runner group candidate found via getManagedRunnerGroupsFromHRAs.
scaleTarget := func(value string) (*ScaleTarget, error) {
if value == "MYORG/myrepo" {
return nil, nil
}
return nil, wantErr
}

_, err := autoscaler.getScaleUpTargetWithFunction(context.Background(), logr.Discard(), "myrepo", "MYORG", "Organization", "", scaleTarget)
if err == nil {
t.Fatal("expected the error raised while resolving a candidate runner group to propagate, got nil")
}
if err.Error() != wantErr.Error() {
t.Fatalf("expected error %v to propagate unchanged, got %v", wantErr, err)
}
}

func TestGetRequest(t *testing.T) {
hra := HorizontalRunnerAutoscalerGitHubWebhook{}
request, _ := http.NewRequest(http.MethodGet, "/", nil)
Expand Down