github.com/TeaOSLab/EdgeNode@v1.3.8/internal/caches/errros_test.go (about)

     1  // Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
     2  
     3  package caches_test
     4  
     5  import (
     6  	"errors"
     7  	"fmt"
     8  	"github.com/TeaOSLab/EdgeNode/internal/caches"
     9  	"github.com/iwind/TeaGo/assert"
    10  	"testing"
    11  )
    12  
    13  func TestCanIgnoreErr(t *testing.T) {
    14  	var a = assert.NewAssertion(t)
    15  
    16  	a.IsTrue(caches.CanIgnoreErr(caches.ErrFileIsWriting))
    17  	a.IsTrue(caches.CanIgnoreErr(fmt.Errorf("error: %w", caches.ErrFileIsWriting)))
    18  	a.IsTrue(errors.Is(fmt.Errorf("error: %w", caches.ErrFileIsWriting), caches.ErrFileIsWriting))
    19  	a.IsTrue(errors.Is(caches.ErrFileIsWriting, caches.ErrFileIsWriting))
    20  	a.IsTrue(caches.CanIgnoreErr(caches.NewCapacityError("over capacity")))
    21  	a.IsTrue(caches.CanIgnoreErr(fmt.Errorf("error: %w", caches.NewCapacityError("over capacity"))))
    22  	a.IsFalse(caches.CanIgnoreErr(caches.ErrNotFound))
    23  	a.IsFalse(caches.CanIgnoreErr(errors.New("test error")))
    24  }