forked from kata-containers/kata-containers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors_test.go
40 lines (33 loc) · 1.08 KB
/
errors_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (c) 2019 hyper.sh
//
// SPDX-License-Identifier: Apache-2.0
//
package containerdshim
import (
"errors"
"syscall"
"testing"
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func TestToGRPC(t *testing.T) {
assert := assert.New(t)
for _, err := range []error{vc.ErrNeedSandbox, vc.ErrNeedSandboxID,
vc.ErrNeedContainerID, vc.ErrNeedState, syscall.EINVAL, vc.ErrNoSuchContainer, syscall.ENOENT} {
assert.False(isGRPCError(err))
err = toGRPC(err)
assert.True(isGRPCError(err))
err = toGRPC(err)
assert.True(isGRPCError(err))
err = toGRPCf(err, "appending")
assert.True(isGRPCError(err))
}
}
func TestIsGRPCErrorCode(t *testing.T) {
assert := assert.New(t)
assert.True(isGRPCErrorCode(codes.Unimplemented, status.New(codes.Unimplemented, "foobar").Err()))
assert.True(isGRPCErrorCode(codes.NotFound, status.New(codes.NotFound, "foobar").Err()))
assert.False(isGRPCErrorCode(codes.Unimplemented, errors.New("foobar")))
}