Merge pull request #340 from int128/integration-test-check-run

Fix index key to find HRA in GitHub webhook handler
This commit is contained in:
Yusuke Kuoka
2021-02-22 09:49:54 +09:00
committed by GitHub
2 changed files with 11 additions and 13 deletions

View File

@@ -303,17 +303,20 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) getScaleTarget(ctx co
}
func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) getScaleUpTarget(ctx context.Context, repoNameFromWebhook, orgNameFromWebhook string, f func(v1alpha1.ScaleUpTrigger) bool) (*ScaleTarget, error) {
if target, err := autoscaler.getScaleTarget(ctx, repoNameFromWebhook, f); err != nil {
repositoryRunnerKey := orgNameFromWebhook + "/" + repoNameFromWebhook
autoscaler.Log.Info("finding repository-wide runner", "repository", repositoryRunnerKey)
if target, err := autoscaler.getScaleTarget(ctx, repositoryRunnerKey, f); err != nil {
return nil, err
} else if target != nil {
autoscaler.Log.Info("scale up target is repository-wide runners", "repository", repoNameFromWebhook)
return target, nil
}
autoscaler.Log.Info("finding organizational runner", "organization", orgNameFromWebhook)
if target, err := autoscaler.getScaleTarget(ctx, orgNameFromWebhook, f); err != nil {
return nil, err
} else if target != nil {
autoscaler.Log.Info("scale up target is organizational runners", "repository", orgNameFromWebhook)
autoscaler.Log.Info("scale up target is organizational runners", "organization", orgNameFromWebhook)
return target, nil
}

View File

@@ -9,7 +9,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"net/http"
"net/http/httptest"
"strings"
"time"
"github.com/summerwind/actions-runner-controller/github/fake"
@@ -297,14 +296,14 @@ var _ = Context("INTEGRATION: Inside of a new namespace", func() {
// Scale-up to 2 replicas on first pull_request create webhook event
{
env.SendPullRequestEvent("test/valid", "main", "created")
env.SendPullRequestEvent("test", "valid", "main", "created")
ExpectRunnerSetsCountEventuallyEquals(ctx, ns.Name, 1, "runner sets after webhook")
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 2, "runners after first webhook event")
}
// Scale-up to 3 replicas on second pull_request create webhook event
{
env.SendPullRequestEvent("test/valid", "main", "created")
env.SendPullRequestEvent("test", "valid", "main", "created")
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 3, "runners after second webhook event")
}
})
@@ -386,7 +385,7 @@ var _ = Context("INTEGRATION: Inside of a new namespace", func() {
// Scale-up to 4 replicas on first check_run create webhook event
{
env.SendCheckRunEvent("test/valid", "pending", "created")
env.SendCheckRunEvent("test", "valid", "pending", "created")
ExpectRunnerSetsCountEventuallyEquals(ctx, ns.Name, 1, "runner sets after webhook")
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 4, "runners after first webhook event")
}
@@ -397,7 +396,7 @@ var _ = Context("INTEGRATION: Inside of a new namespace", func() {
// Scale-up to 5 replicas on second check_run create webhook event
{
env.SendCheckRunEvent("test/valid", "pending", "created")
env.SendCheckRunEvent("test", "valid", "pending", "created")
ExpectRunnerSetsManagedReplicasCountEventuallyEquals(ctx, ns.Name, 5, "runners after second webhook event")
}
@@ -420,9 +419,7 @@ func (env *testEnvironment) ExpectRegisteredNumberCountEventuallyEquals(want int
time.Second*1, time.Millisecond*500).Should(Equal(want), optionalDescriptions...)
}
func (env *testEnvironment) SendPullRequestEvent(repo string, branch string, action string) {
org := strings.Split(repo, "/")[0]
func (env *testEnvironment) SendPullRequestEvent(org, repo, branch, action string) {
resp, err := sendWebhook(env.webhookServer, "pull_request", &github.PullRequestEvent{
PullRequest: &github.PullRequest{
Base: &github.PullRequestBranch{
@@ -443,9 +440,7 @@ func (env *testEnvironment) SendPullRequestEvent(repo string, branch string, act
ExpectWithOffset(1, resp.StatusCode).To(Equal(200))
}
func (env *testEnvironment) SendCheckRunEvent(repo string, status string, action string) {
org := strings.Split(repo, "/")[0]
func (env *testEnvironment) SendCheckRunEvent(org, repo, status, action string) {
resp, err := sendWebhook(env.webhookServer, "check_run", &github.CheckRunEvent{
CheckRun: &github.CheckRun{
Status: github.String(status),