66package utils
77
88import (
9- "fmt"
9+ "errors"
10+ "net/http"
11+ "testing"
12+
1013 "github.com/labstack/echo/v4"
1114 "google.golang.org/grpc/codes"
1215 "google.golang.org/grpc/status"
1316 "gotest.tools/assert"
14- "net/http"
15- "testing"
1617)
1718
1819func Test_ConvertGRPCError (t * testing.T ) {
@@ -31,54 +32,54 @@ func Test_ConvertHttpError(t *testing.T) {
3132
3233func Test_ConvertGrpcError_NoContent (t * testing.T ) {
3334 validationErrMsg := respInternalInvalid + ` test1`
34- httpError := ConvertGrpcError (fmt . Errorf (validationErrMsg ))
35+ httpError := ConvertGrpcError (errors . New (validationErrMsg ))
3536 assert .Error (t , httpError , "code=204, message=rpc error: code = Internal desc = rpc error: code = InvalidArgument test1" )
3637}
3738
3839func Test_ConvertGrpcError_Leafref (t * testing.T ) {
3940 validationErrMsg := respInvalidValidation + ` Application value starbucks-nvr (string ptr) schema path /a/b/c has leafref path /d/e/f not equal to any target nodes, field name Application value starbucks-nvr (string ptr) schema path /a/b/c has leafref path /d/e/f not equal to any target nodes`
40- httpError := ConvertGrpcError (fmt . Errorf (validationErrMsg ))
41+ httpError := ConvertGrpcError (errors . New (validationErrMsg ))
4142 assert .Error (t , httpError , "code=400, message=Change gives LeafRef error on /d/e/f. Application value starbucks-nvr not present. From path: /a/b/c" )
4243}
4344
4445func Test_ConvertGrpcError_ValidationOther (t * testing.T ) {
4546 validationErrMsg := respInvalidValidation + ` test1234` + notEqual
46- httpError := ConvertGrpcError (fmt . Errorf (validationErrMsg ))
47+ httpError := ConvertGrpcError (errors . New (validationErrMsg ))
4748 assert .Error (t , httpError , "code=400, message=test1234" )
4849}
4950
5051func Test_ConvertGrpcError_ValidationOther1 (t * testing.T ) {
5152 validationErrMsg := respInvalidValidation + ` test1234 (test abc)` + " " + schemaPath + " /a/b/c " + hasLrPath + " /d/e/f " + notEqual + " " + notEqual
52- httpError := ConvertGrpcError (fmt . Errorf (validationErrMsg ))
53+ httpError := ConvertGrpcError (errors . New (validationErrMsg ))
5354 assert .Error (t , httpError , "code=400, message=Change gives LeafRef error on /d/e/f. test1234 not present. From path: /a/b/c" )
5455}
5556
5657func Test_ConvertGrpcError_ValidationNotRepeated (t * testing.T ) {
5758 validationErrMsg := respInvalidValidation + ` test1234 (test abc)` + " " + schemaPath + " /a/b/c " + hasLrPath + " /d/e/f " + notEqual
58- httpError := ConvertGrpcError (fmt . Errorf (validationErrMsg ))
59+ httpError := ConvertGrpcError (errors . New (validationErrMsg ))
5960 assert .Error (t , httpError , "code=400, message=Change gives LeafRef error on /d/e/f. test1234 not present. From path: /a/b/c" )
6061}
6162
6263func Test_ConvertGrpcError_ValidationNoBracket (t * testing.T ) {
6364 validationErrMsg := respInvalidValidation + ` test1234 test abc)` + " " + schemaPath + " /a/b/c " + hasLrPath + " /d/e/f " + notEqual
64- httpError := ConvertGrpcError (fmt . Errorf (validationErrMsg ))
65+ httpError := ConvertGrpcError (errors . New (validationErrMsg ))
6566 assert .Error (t , httpError , "code=400, message=test1234 test abc) schema path /a/b/c has leafref path /d/e/f " )
6667}
6768
6869func Test_ConvertGrpcError_InvalidOther (t * testing.T ) {
6970 validationErrMsg := respInvalidBase + ` test1234`
70- httpError := ConvertGrpcError (fmt . Errorf (validationErrMsg ))
71+ httpError := ConvertGrpcError (errors . New (validationErrMsg ))
7172 assert .Error (t , httpError , "code=400, message=rpc error: code = InvalidArgument desc = test1234" )
7273}
7374
7475func Test_ConvertGrpcError_Unauthorized (t * testing.T ) {
7576 validationErrMsg := respUnauthorized + ` test1234`
76- httpError := ConvertGrpcError (fmt . Errorf (validationErrMsg ))
77+ httpError := ConvertGrpcError (errors . New (validationErrMsg ))
7778 assert .Error (t , httpError , "code=401, message=rpc error: code = Unauthenticated desc = test1234" )
7879}
7980
8081func Test_ConvertGrpcError_Internal (t * testing.T ) {
8182 validationErrMsg := `rpc error: code = test1234`
82- httpError := ConvertGrpcError (fmt . Errorf (validationErrMsg ))
83+ httpError := ConvertGrpcError (errors . New (validationErrMsg ))
8384 assert .Error (t , httpError , "code=500, message=rpc error: code = test1234" )
8485}
0 commit comments