@@ -220,3 +220,52 @@ func TestShortNameAndIDconflict(t *testing.T) {
220220 require .NoError (t , err )
221221 require .Equal (t , busybox [0 ].ID (), img .ID ())
222222}
223+
224+ func TestPullOCINoReference (t * testing.T ) {
225+ // Exercise pulling from the OCI transport and make sure that a
226+ // specified reference is preserved in the image name.
227+
228+ busybox := "docker.io/library/busybox:latest"
229+ runtime , cleanup := testNewRuntime (t )
230+ defer cleanup ()
231+ ctx := context .Background ()
232+ pullOptions := & PullOptions {}
233+ pullOptions .Writer = os .Stdout
234+
235+ images , err := runtime .Pull (ctx , busybox , config .PullPolicyAlways , pullOptions )
236+ require .NoError (t , err )
237+ require .Len (t , images , 1 )
238+
239+ // Push one image without the optional reference
240+ ociPathNoRef := "oci:" + t .TempDir () + "noRef"
241+ _ , err = runtime .Push (ctx , busybox , ociPathNoRef , nil )
242+ require .NoError (t , err )
243+
244+ // Push another image _with_ the optional reference which allows for
245+ // preserving the name.
246+ ociPathWithRef := "oci:" + t .TempDir () + "withRef:" + busybox
247+ _ , err = runtime .Push (ctx , busybox , ociPathWithRef , nil )
248+ require .NoError (t , err )
249+
250+ _ , errors := runtime .RemoveImages (ctx , []string {busybox }, nil )
251+ require .Nil (t , errors )
252+
253+ images , err = runtime .Pull (ctx , ociPathNoRef , config .PullPolicyAlways , pullOptions )
254+ require .NoError (t , err )
255+ require .Len (t , images , 1 )
256+
257+ exists , err := runtime .Exists (busybox ) // busybox does not exist
258+ require .NoError (t , err )
259+ require .False (t , exists )
260+
261+ names := images [0 ].Names () // The image has no names (i.e., <none>)
262+ require .Nil (t , names )
263+
264+ images , err = runtime .Pull (ctx , ociPathWithRef , config .PullPolicyAlways , pullOptions )
265+ require .NoError (t , err )
266+ require .Len (t , images , 1 )
267+
268+ exists , err = runtime .Exists (busybox ) // busybox does exist now
269+ require .NoError (t , err )
270+ require .True (t , exists )
271+ }
0 commit comments