Files
gitea-dynamic-runner/internal/runnerbootstrap/executor_test.go
T
panxiao81 537c620051
test / python (pull_request) Successful in 51s
test / shell (pull_request) Successful in 40s
test / go (pull_request) Successful in 3m1s
fix(runner): load job hooks configuration
2026-09-21 17:50:47 +00:00

53 lines
1.4 KiB
Go

package runnerbootstrap
import (
"context"
"net/http"
"net/http/httptest"
"reflect"
"sync/atomic"
"testing"
"time"
)
func TestRunnerArgumentsLoadJobHooksConfig(t *testing.T) {
want := []string{"daemon", "--config", "/etc/gitea-runner/config.yaml", "--once"}
if got := runnerArguments("/etc/gitea-runner/config.yaml"); !reflect.DeepEqual(got, want) {
t.Fatalf("runner arguments = %q, want %q", got, want)
}
}
func TestWaitForFacadeRetriesTransientGatewayFailure(t *testing.T) {
var requests atomic.Int32
server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, _ *http.Request) {
if requests.Add(1) < 3 {
writer.WriteHeader(http.StatusBadGateway)
return
}
writer.WriteHeader(http.StatusNotFound)
}))
defer server.Close()
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
if err := waitForFacade(ctx, server.URL); err != nil {
t.Fatal(err)
}
if requests.Load() != 3 {
t.Fatalf("requests = %d", requests.Load())
}
}
func TestWaitForFacadeStopsWithContext(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, _ *http.Request) {
writer.WriteHeader(http.StatusServiceUnavailable)
}))
defer server.Close()
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
defer cancel()
if err := waitForFacade(ctx, server.URL); err == nil {
t.Fatal("expected readiness timeout")
}
}