@@ -295,6 +295,52 @@ func TestRemove(t *testing.T) {
295
295
})
296
296
}
297
297
298
+ func TestRemoveById (t * testing.T ) {
299
+ dockerConfigDir := fs .NewDir (t , t .Name (), fs .WithMode (0755 ))
300
+ defer dockerConfigDir .Remove ()
301
+ appstore , err := NewApplicationStore (dockerConfigDir .Path ())
302
+ assert .NilError (t , err )
303
+ bundleStore , err := appstore .BundleStore ()
304
+ assert .NilError (t , err )
305
+
306
+ t .Run ("error when id does not exist" , func (t * testing.T ) {
307
+ idRef , err := FromBundle (relocated .FromBundle (& bundle.Bundle {Name : "not-stored-bundle-name" }))
308
+ assert .NilError (t , err )
309
+
310
+ err = bundleStore .Remove (idRef )
311
+ assert .Equal (t , err .Error (), fmt .Sprintf ("no such image %q" , reference .FamiliarString (idRef )))
312
+ })
313
+
314
+ t .Run ("error on multiple repositories" , func (t * testing.T ) {
315
+ bndl := relocated .FromBundle (& bundle.Bundle {Name : "bundle-name" })
316
+ idRef , err := FromBundle (bndl )
317
+ assert .NilError (t , err )
318
+ _ , err = bundleStore .Store (idRef , bndl )
319
+ assert .NilError (t , err )
320
+ _ , err = bundleStore .Store (parseRefOrDie (t , "my-repo/a-bundle:my-tag" ), bndl )
321
+ assert .NilError (t , err )
322
+
323
+ err = bundleStore .Remove (idRef )
324
+ assert .Equal (t , err .Error (), fmt .Sprintf ("unable to delete %q - App is referenced in multiple repositories" , reference .FamiliarString (idRef )))
325
+ })
326
+
327
+ t .Run ("success when only one reference exists" , func (t * testing.T ) {
328
+ bndl := relocated .FromBundle (& bundle.Bundle {Name : "other-bundle-name" })
329
+ ref := parseRefOrDie (t , "my-repo/other-bundle:my-tag" )
330
+ _ , err = bundleStore .Store (ref , bndl )
331
+
332
+ idRef , err := FromBundle (bndl )
333
+ assert .NilError (t , err )
334
+
335
+ err = bundleStore .Remove (idRef )
336
+ assert .NilError (t , err )
337
+ bundles , err := bundleStore .List ()
338
+ assert .NilError (t , err )
339
+ for _ , bref := range bundles {
340
+ assert .Equal (t , bref == ref , false )
341
+ }
342
+ })
343
+ }
298
344
func TestLookUp (t * testing.T ) {
299
345
dockerConfigDir := fs .NewDir (t , t .Name (), fs .WithMode (0755 ))
300
346
defer dockerConfigDir .Remove ()
0 commit comments