MCPcopy
hub / github.com/determined-ai/determined / TestRunContainer

Function TestRunContainer

agent/pkg/docker/docker_api_test.go:122–193  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

120}
121
122func TestRunContainer(t *testing.T) {
123 ctx, cancel := context.WithCancel(context.Background())
124 defer cancel()
125
126 t.Log("building client")
127 rawCl, err := dclient.NewClientWithOpts(dclient.WithAPIVersionNegotiation(), dclient.FromEnv)
128 require.NoError(t, err)
129 defer func() {
130 if cErr := rawCl.Close(); cErr != nil {
131 t.Logf("closing docker client: %s", cErr)
132 }
133 }()
134 cl := docker.NewClient(rawCl)
135
136 t.Log("pull test image")
137 evs := make(chan docker.Event, 1024)
138 pub := events.ChannelPublisher(evs)
139 if err = cl.PullImage(ctx, docker.PullImage{Name: testImage}, pub); err != nil {
140 t.Errorf("pulling image: %s", err.Error())
141 return
142 }
143 close(evs)
144 _, _, err = rawCl.ImageInspectWithRaw(ctx, testImage)
145 require.NoError(t, err)
146
147 t.Log("creating simple container")
148 evs = make(chan docker.Event, 64)
149 pub = events.ChannelPublisher(evs)
150 dockerID, err := cl.CreateContainer(ctx, cproto.NewID(), cproto.RunSpec{
151 ContainerConfig: container.Config{
152 Image: testImage,
153 Entrypoint: []string{"cat", "/tmp/whatever"},
154 },
155 Archives: []cproto.RunArchive{
156 {
157 Path: "/tmp",
158 Archive: []archive.Item{
159 {
160 Path: "/whatever",
161 Type: tar.TypeReg,
162 Content: []byte("hello"),
163 FileMode: 0o0777,
164 },
165 },
166 },
167 },
168 }, pub)
169 require.NoError(t, err)
170
171 t.Log("running simple container")
172 c, err := cl.RunContainer(ctx, ctx, dockerID, pub)
173 require.NoError(t, err)
174
175 close(evs)
176 defer func() {
177 if err := rawCl.ContainerRemove(
178 ctx,
179 dockerID,

Callers

nothing calls this directly

Calls 14

PullImageMethod · 0.95
CreateContainerMethod · 0.95
RunContainerMethod · 0.95
NewClientFunction · 0.92
ChannelPublisherFunction · 0.92
NewIDFunction · 0.92
cancelFunction · 0.85
makeFunction · 0.85
LogfMethod · 0.80
CloseMethod · 0.65
closeFunction · 0.50
int64Function · 0.50

Tested by

no test coverage detected