github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/cmn/tests/err_test.go (about)

     1  // Package test provides tests for common low-level types and utilities for all aistore projects
     2  /*
     3   * Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved.
     4   */
     5  package tests_test
     6  
     7  import (
     8  	"fmt"
     9  	"testing"
    10  
    11  	"github.com/NVIDIA/aistore/cmn"
    12  	"github.com/NVIDIA/aistore/tools/tassert"
    13  )
    14  
    15  func TestAbortedErrorAs(t *testing.T) {
    16  	mockDetails := "mock details"
    17  	mockWhat := "mock what"
    18  
    19  	abortedError := cmn.NewErrAborted(mockWhat, mockDetails, nil)
    20  	tassert.Fatalf(t, cmn.IsErrAborted(abortedError), "expected errors.As to return true on the same error type")
    21  
    22  	mockError := fmt.Errorf("wrapping aborted error %w", abortedError)
    23  	tassert.Fatalf(t, cmn.IsErrAborted(mockError), "expected errors.As to return true on a wrapped error")
    24  }