From b3f8c5a99d1f73e47161bdca0694cd73f5200ca4 Mon Sep 17 00:00:00 2001 From: sophia Date: Fri, 11 Mar 2022 17:13:14 -0600 Subject: [PATCH] Add test for removing boxes that are no longer available --- internal/core/box_collection_test.go | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/internal/core/box_collection_test.go b/internal/core/box_collection_test.go index 08bcb61d9..ef51e05b6 100644 --- a/internal/core/box_collection_test.go +++ b/internal/core/box_collection_test.go @@ -153,3 +153,34 @@ func TestFind(t *testing.T) { require.NoError(t, err) require.NotNil(t, boxes) } + +func TestRemoveBox(t *testing.T) { + // Create initial box collection + bc := newBoxCollection(t) + td, err := ioutil.TempDir("/tmp", "box") + require.NoError(t, err) + t.Cleanup(func() { os.RemoveAll(td) }) + testBoxPath := generateTestBox(t, td, bc.basis) + // Insert test box into the collection + box, err := bc.Add(testBoxPath, "test/box", "1.2.3", "", true) + boxPath, _ := box.Directory() + require.NoError(t, err) + require.NotNil(t, box) + + // Create new box collection to verify test box is still accessible + bc, err = NewBoxCollection(bc.basis, bc.directory, bc.logger) + require.NoError(t, err) + boxes, err := bc.Find("test/box", "1.2.3") + require.NoError(t, err) + require.NotNil(t, boxes) + + // Remove box + os.RemoveAll(boxPath) + + // Create new box collection to verify test box is no longer accessible + bc, err = NewBoxCollection(bc.basis, bc.directory, bc.logger) + require.NoError(t, err) + boxes, err = bc.Find("test/box", "1.2.3") + require.NoError(t, err) + require.Nil(t, boxes) +}