Skip to content

Commit 344df47

Browse files
authored
Properly separate the os.Args for the agent (#727)
1 parent 989bbbe commit 344df47

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

cmd/cirrus/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func main() {
4242

4343
// Run the Cirrus CI Agent if requested
4444
if len(os.Args) >= 2 && os.Args[1] == "agent" {
45-
agent.Run()
45+
agent.Run(os.Args[2:])
4646

4747
return
4848
}

internal/agent/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"time"
3434
)
3535

36-
func Run() {
36+
func Run(args []string) {
3737
apiEndpointPtr := flag.String("api-endpoint", "https://grpc.cirrus-ci.com:443", "GRPC endpoint URL")
3838
taskIdPtr := flag.String("task-id", "0", "Task ID")
3939
clientTokenPtr := flag.String("client-token", "", "Secret token")
@@ -45,7 +45,7 @@ func Run() {
4545
commandToPtr := flag.String("command-to", "", "Command to stop execution at (exclusive)")
4646
preCreatedWorkingDir := flag.String("pre-created-working-dir", "",
4747
"working directory to use when spawned via Persistent Worker")
48-
flag.Parse()
48+
_ = flag.CommandLine.Parse(args)
4949

5050
// Parse task ID as an integer for backwards-compatibility with the TaskIdentification message
5151
oldStyleTaskID, err := strconv.ParseInt(*taskIdPtr, 10, 64)

internal/worker/worker_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"math/rand"
2222
"net"
2323
"os"
24+
"runtime"
2425
"testing"
2526
"time"
2627
)
@@ -488,6 +489,11 @@ func TestWorkerSecurityVolumes(t *testing.T) {
488489
}
489490

490491
func TestTaskCancellation(t *testing.T) {
492+
// Windows has no "sleep" command
493+
if runtime.GOOS == "windows" {
494+
t.SkipNow()
495+
}
496+
491497
//nolint:gosec // this is a test, so it's fine to bind on 0.0.0.0
492498
lis, err := net.Listen("tcp", "0.0.0.0:0")
493499
if err != nil {

0 commit comments

Comments
 (0)