gitlab.com/ignitionrobotics/web/ign-go@v1.0.0-rc4/net/grpc_test.go (about) 1 package net 2 3 import ( 4 "github.com/stretchr/testify/suite" 5 "google.golang.org/grpc/codes" 6 "google.golang.org/grpc/status" 7 "testing" 8 ) 9 10 func TestGRPCSuite(t *testing.T) { 11 suite.Run(t, &GRPCTestSuite{}) 12 } 13 14 type GRPCTestSuite struct { 15 suite.Suite 16 } 17 18 func (suite *GRPCTestSuite) TestGRPCCallOK() { 19 // nil should be true 20 suite.Assert().True(GRPCCallOK(nil)) 21 22 // Status with an OK code should be true 23 err := status.Error(codes.OK, "") 24 suite.Assert().True(GRPCCallOK(err)) 25 26 // Status with an Unknown code should be false 27 err = status.Error(codes.Unknown, "custom application error") 28 suite.Assert().False(GRPCCallOK(err)) 29 30 // Status with a non-OK code should be false 31 err = status.Error(codes.DeadlineExceeded, "deadline exceeded") 32 suite.Assert().False(GRPCCallOK(err)) 33 } 34 35 func (suite *GRPCTestSuite) TestGRPCCallSuccessful() { 36 // nil should be true 37 suite.Assert().True(GRPCCallSuccessful(nil)) 38 39 // Status with an OK code should be true 40 err := status.Error(codes.OK, "") 41 suite.Assert().True(GRPCCallSuccessful(err)) 42 43 // Status with an Unknown code should be true 44 err = status.Error(codes.Unknown, "custom application error") 45 suite.Assert().True(GRPCCallSuccessful(err)) 46 47 // Status with a non-OK code should be false 48 err = status.Error(codes.DeadlineExceeded, "deadline exceeded") 49 suite.Assert().False(GRPCCallSuccessful(err)) 50 }