From 344df4758661e1143cb3445d1e69bdb462de94b5 Mon Sep 17 00:00:00 2001 From: Nikolay Edigaryev Date: Tue, 23 Apr 2024 20:45:24 +0400 Subject: [PATCH] Properly separate the os.Args for the agent (#727) --- cmd/cirrus/main.go | 2 +- internal/agent/main.go | 4 ++-- internal/worker/worker_test.go | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/cirrus/main.go b/cmd/cirrus/main.go index ebc1f540..f28abb3b 100644 --- a/cmd/cirrus/main.go +++ b/cmd/cirrus/main.go @@ -42,7 +42,7 @@ func main() { // Run the Cirrus CI Agent if requested if len(os.Args) >= 2 && os.Args[1] == "agent" { - agent.Run() + agent.Run(os.Args[2:]) return } diff --git a/internal/agent/main.go b/internal/agent/main.go index fde78622..3c6f6554 100644 --- a/internal/agent/main.go +++ b/internal/agent/main.go @@ -33,7 +33,7 @@ import ( "time" ) -func Run() { +func Run(args []string) { apiEndpointPtr := flag.String("api-endpoint", "https://grpc.cirrus-ci.com:443", "GRPC endpoint URL") taskIdPtr := flag.String("task-id", "0", "Task ID") clientTokenPtr := flag.String("client-token", "", "Secret token") @@ -45,7 +45,7 @@ func Run() { commandToPtr := flag.String("command-to", "", "Command to stop execution at (exclusive)") preCreatedWorkingDir := flag.String("pre-created-working-dir", "", "working directory to use when spawned via Persistent Worker") - flag.Parse() + _ = flag.CommandLine.Parse(args) // Parse task ID as an integer for backwards-compatibility with the TaskIdentification message oldStyleTaskID, err := strconv.ParseInt(*taskIdPtr, 10, 64) diff --git a/internal/worker/worker_test.go b/internal/worker/worker_test.go index b7313e26..6615d5e6 100644 --- a/internal/worker/worker_test.go +++ b/internal/worker/worker_test.go @@ -21,6 +21,7 @@ import ( "math/rand" "net" "os" + "runtime" "testing" "time" ) @@ -488,6 +489,11 @@ func TestWorkerSecurityVolumes(t *testing.T) { } func TestTaskCancellation(t *testing.T) { + // Windows has no "sleep" command + if runtime.GOOS == "windows" { + t.SkipNow() + } + //nolint:gosec // this is a test, so it's fine to bind on 0.0.0.0 lis, err := net.Listen("tcp", "0.0.0.0:0") if err != nil {