git.frostfs.info/TrueCloudLab/frostfs-sdk-go@v0.0.0-20241022124111-5361f0ecebd3/client/errors_test.go (about)

     1  package client_test
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
     8  	apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func TestErrors(t *testing.T) {
    13  	errs := []struct {
    14  		check func(error) bool
    15  		err   error
    16  	}{
    17  		{
    18  			check: client.IsErrContainerNotFound,
    19  			err:   new(apistatus.ContainerNotFound),
    20  		},
    21  		{
    22  			check: client.IsErrEACLNotFound,
    23  			err:   new(apistatus.EACLNotFound),
    24  		},
    25  		{
    26  			check: client.IsErrObjectNotFound,
    27  			err:   new(apistatus.ObjectNotFound),
    28  		},
    29  		{
    30  			check: client.IsErrObjectAlreadyRemoved,
    31  			err:   new(apistatus.ObjectAlreadyRemoved),
    32  		},
    33  		{
    34  			check: client.IsErrSessionExpired,
    35  			err:   new(apistatus.SessionTokenExpired),
    36  		},
    37  		{
    38  			check: client.IsErrSessionNotFound,
    39  			err:   new(apistatus.SessionTokenNotFound),
    40  		},
    41  		{
    42  			check: client.IsErrNodeUnderMaintenance,
    43  			err:   new(apistatus.NodeUnderMaintenance),
    44  		},
    45  	}
    46  
    47  	for i := range errs {
    48  		for j := range errs {
    49  			nestedErr := fmt.Errorf("top-level context: :%w", fmt.Errorf("inner context: %w", errs[j].err))
    50  			require.Equal(t, i == j, errs[i].check(errs[j].err))
    51  			require.Equal(t, i == j, errs[i].check(nestedErr))
    52  		}
    53  	}
    54  }