Skip to content

Commit

Permalink
Properly separate the os.Args for the agent (#727)
Browse files Browse the repository at this point in the history
  • Loading branch information
edigaryev committed Apr 23, 2024
1 parent 989bbbe commit 344df47
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/cirrus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions internal/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions internal/worker/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"math/rand"
"net"
"os"
"runtime"
"testing"
"time"
)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 344df47

Please sign in to comment.