@@ -30,8 +30,10 @@ import (
3030
3131 "google.golang.org/grpc/grpclog"
3232
33+ "github.com/containerd/containerd/images"
3334 "github.com/containerd/containerd/log"
3435 "github.com/containerd/containerd/namespaces"
36+ "github.com/containerd/containerd/platforms"
3537 "github.com/containerd/containerd/sys"
3638 "github.com/containerd/containerd/testutil"
3739 "github.com/sirupsen/logrus"
@@ -116,7 +118,7 @@ func TestMain(m *testing.M) {
116118 }).Info ("running tests against containerd" )
117119
118120 // pull a seed image
119- if _ , err = client .Pull (ctx , testImage , WithPullUnpack ); err != nil {
121+ if _ , err = client .Pull (ctx , testImage , WithPullUnpack , WithPlatform ( platforms . Default ()) ); err != nil {
120122 ctrd .Stop ()
121123 ctrd .Wait ()
122124 fmt .Fprintf (os .Stderr , "%s: %s\n " , err , buf .String ())
@@ -187,12 +189,115 @@ func TestImagePull(t *testing.T) {
187189
188190 ctx , cancel := testContext ()
189191 defer cancel ()
190- _ , err = client .Pull (ctx , testImage )
192+ _ , err = client .Pull (ctx , testImage , WithPlatform ( platforms . Default ()) )
191193 if err != nil {
192194 t .Fatal (err )
193195 }
194196}
195197
198+ func TestImagePullAllPlatforms (t * testing.T ) {
199+ client , err := newClient (t , address )
200+ if err != nil {
201+ t .Fatal (err )
202+ }
203+ defer client .Close ()
204+ ctx , cancel := testContext ()
205+ defer cancel ()
206+
207+ cs := client .ContentStore ()
208+ img , err := client .Pull (ctx , testImage )
209+ if err != nil {
210+ t .Fatal (err )
211+ }
212+ index := img .Target ()
213+ manifests , err := images .Children (ctx , cs , index )
214+ if err != nil {
215+ t .Fatal (err )
216+ }
217+ for _ , manifest := range manifests {
218+ children , err := images .Children (ctx , cs , manifest )
219+ if err != nil {
220+ t .Fatal ("Th" )
221+ }
222+ // check if childless data type has blob in content store
223+ for _ , desc := range children {
224+ ra , err := cs .ReaderAt (ctx , desc .Digest )
225+ if err != nil {
226+ t .Fatal (err )
227+ }
228+ ra .Close ()
229+ }
230+ }
231+ }
232+
233+ func TestImagePullSomePlatforms (t * testing.T ) {
234+ client , err := newClient (t , address )
235+ if err != nil {
236+ t .Fatal (err )
237+ }
238+ defer client .Close ()
239+ ctx , cancel := testContext ()
240+ defer cancel ()
241+
242+ cs := client .ContentStore ()
243+ platformList := []string {"linux/arm64/v8" , "linux/386" }
244+ m := make (map [string ]platforms.Matcher )
245+ var opts []RemoteOpt
246+
247+ for _ , platform := range platformList {
248+ p , err := platforms .Parse (platform )
249+ if err != nil {
250+ t .Fatal (err )
251+ }
252+ m [platform ] = platforms .NewMatcher (p )
253+ opts = append (opts , WithPlatform (platform ))
254+ }
255+
256+ img , err := client .Pull (ctx , "docker.io/library/busybox:latest" , opts ... )
257+ if err != nil {
258+ t .Fatal (err )
259+ }
260+
261+ index := img .Target ()
262+ manifests , err := images .Children (ctx , cs , index )
263+ if err != nil {
264+ t .Fatal (err )
265+ }
266+
267+ count := 0
268+ for _ , manifest := range manifests {
269+ children , err := images .Children (ctx , cs , manifest )
270+ found := false
271+ for _ , matcher := range m {
272+ if matcher .Match (* manifest .Platform ) {
273+ count ++
274+ found = true
275+ }
276+ }
277+
278+ if found {
279+ if len (children ) == 0 {
280+ t .Fatal ("manifest should have pulled children content" )
281+ }
282+
283+ // check if childless data type has blob in content store
284+ for _ , desc := range children {
285+ ra , err := cs .ReaderAt (ctx , desc .Digest )
286+ if err != nil {
287+ t .Fatal (err )
288+ }
289+ ra .Close ()
290+ }
291+ } else if ! found && err == nil {
292+ t .Fatal ("manifest should not have pulled children content" )
293+ }
294+ }
295+
296+ if count != len (platformList ) {
297+ t .Fatal ("expected a different number of pulled manifests" )
298+ }
299+ }
300+
196301func TestClientReconnect (t * testing.T ) {
197302 t .Parallel ()
198303
0 commit comments