github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/utils/io/write_test.go (about) 1 package io 2 3 import ( 4 "errors" 5 "fmt" 6 "syscall" 7 "testing" 8 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestTerminateOnFullDisk(t *testing.T) { 13 // happy path 14 t.Run("return nil on no error", func(t *testing.T) { 15 result := TerminateOnFullDisk(nil) 16 require.NoError(t, result) 17 }) 18 t.Run("benign non disk related error should return the error", func(t *testing.T) { 19 benignError := errors.New("benign error") 20 result := TerminateOnFullDisk(benignError) 21 require.ErrorIs(t, result, benignError) 22 }) 23 // sad path 24 t.Run("panic on full disk", func(t *testing.T) { 25 // imitate badgerDB error wrapping 26 badgerDiskFullError := fmt.Errorf("this is intended to mimic an internal Badger error wrapping an out-of-disk system error: %w", syscall.ENOSPC) 27 defer func() { 28 if rec := recover(); rec == nil { 29 require.Fail(t, "code should panic") 30 } 31 }() 32 err := TerminateOnFullDisk(badgerDiskFullError) 33 require.NoError(t, err) 34 }) 35 }