MCPcopy Create free account
hub / github.com/docker/buildx / testDialStdio

Function testDialStdio

tests/dialstdio.go:27–121  ·  view source on GitHub ↗
(t *testing.T, sb integration.Sandbox)

Source from the content-addressed store, hash-verified

25}
26
27func testDialStdio(t *testing.T, sb integration.Sandbox) {
28 do := func(t *testing.T, pipe func(t *testing.T, cmd *exec.Cmd) net.Conn) {
29 errBuf := bytes.NewBuffer(nil)
30 defer func() {
31 if t.Failed() {
32 t.Log(errBuf.String())
33 }
34 }()
35 var cmd *exec.Cmd
36 c, err := client.New(sb.Context(), "", client.WithContextDialer(func(ctx context.Context, _ string) (net.Conn, error) {
37 cmd = buildxCmd(sb, withArgs("dial-stdio", "--progress", "auto"))
38 conn := pipe(t, cmd)
39 cmd.Stderr = errBuf
40 if err := cmd.Start(); err != nil {
41 return nil, errors.Wrap(err, errBuf.String())
42 }
43
44 return conn, nil
45 }))
46 require.NoError(t, err)
47
48 defer func() {
49 c.Close()
50 // Since the client is closed (and as such the connection shutdown), the buildx command should exit cleanly.
51 chErr := make(chan error, 1)
52 go func() {
53 chErr <- cmd.Wait()
54 }()
55 select {
56 case <-time.After(10 * time.Second):
57 t.Error("timeout waiting for buildx command to exit")
58 case <-chErr:
59 require.NoError(t, err)
60 }
61 }()
62
63 skipNoCompatBuildKit(t, sb, ">= 0.11.0-0", "unknown method Info for service moby.buildkit.v1.Control")
64 _, err = c.Info(sb.Context())
65 require.NoError(t, err)
66
67 require.Contains(t, errBuf.String(), "builder: "+sb.Address())
68
69 dir := t.TempDir()
70
71 f, err := os.CreateTemp(dir, "log")
72 require.NoError(t, err)
73 defer f.Close()
74
75 defer func() {
76 if t.Failed() {
77 dt, _ := os.ReadFile(f.Name())
78 t.Log(string(dt))
79 }
80 }()
81
82 p, err := progress.NewPrinter(sb.Context(), f, progressui.AutoMode)
83 require.NoError(t, err)
84

Callers

nothing calls this directly

Calls 15

NewPrinterFunction · 0.92
NewChannelFunction · 0.92
buildxCmdFunction · 0.85
withArgsFunction · 0.85
skipNoCompatBuildKitFunction · 0.85
WaitMethod · 0.80
AddressMethod · 0.80
ReadFileMethod · 0.80
DoneMethod · 0.80
LogMethod · 0.65
NewMethod · 0.65
StartMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…