Skip to content

Commit

Permalink
tests: make sure we close before removing files
Browse files Browse the repository at this point in the history
windows don't seem to be happy if we remove a file without closing it.
if you are seeing this commit then it means "yes, windows is not happy
about that". if you aren't seeing this comment then the answer is "no,
windows does not care about that" but you won't know (except if you
already knew).

Signed-off-by: Ricardo Maraschini <ricardo.maraschini@gmail.com>
  • Loading branch information
ricardomaraschini committed Aug 28, 2024
1 parent e33fb7f commit c311817
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions pkg/component/worker/ocibundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ func TestSetImageSources(t *testing.T) {
// test setting one source
fp, err := os.CreateTemp("", "test")
require.Nil(t, err)
defer os.Remove(fp.Name())
defer func() {
_ = fp.Close()
_ = os.Remove(fp.Name())
}()
info, err := fp.Stat()
require.Nil(t, err)
image = images.Image{}
Expand All @@ -83,7 +86,10 @@ func TestSetImageSources(t *testing.T) {
// test sources replacement
img0, err := os.CreateTemp("", "test")
require.Nil(t, err)
defer os.Remove(img0.Name())
defer func() {
_ = img0.Close()
_ = os.Remove(img0.Name())
}()
info0, err := img0.Stat()
require.Nil(t, err)

Expand All @@ -95,7 +101,10 @@ func TestSetImageSources(t *testing.T) {

img1, err := os.CreateTemp("", "test")
require.Nil(t, err)
defer os.Remove(img1.Name())
defer func() {
_ = img1.Close()
_ = os.Remove(img1.Name())
}()
info1, err := img1.Stat()
require.Nil(t, err)

Expand All @@ -113,7 +122,10 @@ func TestAddToImageSources(t *testing.T) {
// test replacing sources
img0, err := os.CreateTemp("", "test")
require.Nil(t, err)
defer os.Remove(img0.Name())
defer func() {
_ = img0.Close()
_ = os.Remove(img0.Name())
}()
info0, err := img0.Stat()
require.Nil(t, err)

Expand All @@ -125,7 +137,10 @@ func TestAddToImageSources(t *testing.T) {

img1, err := os.CreateTemp("", "test")
require.Nil(t, err)
defer os.Remove(img1.Name())
defer func() {
_ = img1.Close()
_ = os.Remove(img1.Name())
}()
info1, err := img1.Stat()
require.Nil(t, err)

Expand All @@ -142,6 +157,8 @@ func TestAddToImageSources(t *testing.T) {
require.True(t, expected[img1.Name()].Equal(got[img1.Name()]), "dates mismatch")

// test if it trims the sources
err = img0.Close()
require.Nil(t, err)
err = os.Remove(img0.Name())
require.Nil(t, err)

Expand Down

0 comments on commit c311817

Please sign in to comment.