github.com/nilium/gitlab-runner@v12.5.0+incompatible/helpers/archives/path_error_tracker_test.go (about)

     1  package archives
     2  
     3  import (
     4  	"errors"
     5  	"os"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestNilsArentActionable(t *testing.T) {
    12  	var genericNil error
    13  	var typedNil *os.PathError
    14  	tracker := newPathErrorTracker()
    15  
    16  	assert.False(t, tracker.actionable(genericNil), "Untyped nils should not be actionable")
    17  	assert.False(t, tracker.actionable(typedNil), "PathError typed nils should not be actionable")
    18  }
    19  
    20  func TestPathErrorIsActionableTheFirstTimeOnly(t *testing.T) {
    21  	pathErr1 := &os.PathError{Op: "anything"}
    22  	pathErr2 := &os.PathError{Op: "anything"}
    23  	pathErr3 := &os.PathError{Op: "something else"}
    24  	tracker := newPathErrorTracker()
    25  
    26  	assert.True(t, tracker.actionable(pathErr1), "Should be actionable the first time an Op is seen")
    27  	assert.False(t, tracker.actionable(pathErr2), "Should not be actionable if the same Op is seen in a different instance")
    28  	assert.False(t, tracker.actionable(pathErr1), "Should not be actionable if the same instance is passed again")
    29  	assert.True(t, tracker.actionable(pathErr3), "Another Op should be actionable")
    30  }
    31  
    32  func TestNonPathErrorsAlwaysActionable(t *testing.T) {
    33  	nonPathErrs := []error{errors.New("one"), errors.New("two")}
    34  	nonPathErrs = append(nonPathErrs, nonPathErrs...) // try each error twice
    35  	tracker := newPathErrorTracker()
    36  
    37  	for i, err := range nonPathErrs {
    38  		assert.True(t, tracker.actionable(err), "#%d should be actionable", i)
    39  	}
    40  }