MCPcopy Create free account
hub / github.com/coder/coder / TestDevcontainerHelperProcess

Function TestDevcontainerHelperProcess

agent/agentcontainers/devcontainercli_test.go:491–533  ·  view source on GitHub ↗

This is a special test helper that is executed as a subprocess. It simulates the behavior of the devcontainer CLI. nolint:revive,paralleltest // This is a test helper function.

(t *testing.T)

Source from the content-addressed store, hash-verified

489//
490//nolint:revive,paralleltest // This is a test helper function.
491func TestDevcontainerHelperProcess(t *testing.T) {
492 // If not called by the test as a helper process, do nothing.
493 if os.Getenv("TEST_DEVCONTAINER_WANT_HELPER_PROCESS") != "1" {
494 return
495 }
496
497 helperArgs := flag.Args()
498 if len(helperArgs) < 1 {
499 fmt.Fprintf(os.Stderr, "No command\n")
500 os.Exit(2)
501 }
502
503 if helperArgs[0] != "devcontainer" {
504 fmt.Fprintf(os.Stderr, "Unknown command: %s\n", helperArgs[0])
505 os.Exit(2)
506 }
507
508 // Verify arguments against expected arguments and skip
509 // "devcontainer", it's not included in the input args.
510 wantArgs := os.Getenv("TEST_DEVCONTAINER_WANT_ARGS")
511 gotArgs := strings.Join(helperArgs[1:], " ")
512 if gotArgs != wantArgs {
513 fmt.Fprintf(os.Stderr, "Arguments don't match.\nWant: %q\nGot: %q\n",
514 wantArgs, gotArgs)
515 os.Exit(2)
516 }
517
518 logFilePath := os.Getenv("TEST_DEVCONTAINER_LOG_FILE")
519 if logFilePath != "" {
520 // Read and output log file for commands that need it (like "up")
521 output, err := os.ReadFile(logFilePath)
522 if err != nil {
523 fmt.Fprintf(os.Stderr, "Reading log file %s failed: %v\n", logFilePath, err)
524 os.Exit(2)
525 }
526 _, _ = io.Copy(os.Stdout, bytes.NewReader(output))
527 }
528
529 if os.Getenv("TEST_DEVCONTAINER_WANT_ERROR") == "true" {
530 os.Exit(1)
531 }
532 os.Exit(0)
533}
534
535// TestDockerDevcontainerCLI tests the DevcontainerCLI component with real Docker containers.
536// This test verifies that containers can be created and recreated using the actual

Callers

nothing calls this directly

Calls 4

ArgsMethod · 0.80
ExitMethod · 0.80
ReadFileMethod · 0.65
CopyMethod · 0.65

Tested by

no test coverage detected