12
"github.com/hashicorp/go-multierror"
13
"github.com/stretchr/testify/assert"
14
"google.golang.org/grpc/codes"
15
"google.golang.org/grpc/status"
17
"github.com/siderolabs/talos/pkg/machinery/client"
20
func TestStatus(t *testing.T) {
21
for _, tt := range []struct {
36
err: errors.New("some error"),
42
err: status.Error(codes.AlreadyExists, "file already exists"),
43
message: "file already exists",
44
code: codes.AlreadyExists,
47
name: "status wrapped",
48
err: multierror.Append(nil, status.Error(codes.AlreadyExists, "file already exists")).ErrorOrNil(),
49
message: "file already exists",
50
code: codes.AlreadyExists,
53
name: "multiple wrapped",
54
err: multierror.Append(nil, status.Error(codes.FailedPrecondition, "can't be zero"), status.Error(codes.AlreadyExists, "file already exists")).ErrorOrNil(),
55
message: "can't be zero",
56
code: codes.FailedPrecondition,
59
name: "double wrapped",
60
err: multierror.Append(nil, fmt.Errorf("127.0.0.1: %w", status.Error(codes.AlreadyExists, "file already exists"))).ErrorOrNil(),
61
message: "file already exists",
62
code: codes.AlreadyExists,
65
t.Run(tt.name, func(t *testing.T) {
66
st := client.Status(tt.err)
70
assert.Equal(t, st.Message(), tt.message)
71
assert.Equal(t, st.Code(), tt.code)
74
assert.Equal(t, client.StatusCode(tt.err), tt.code)