Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ linters:
- dogsled
- unconvert
# - nakedret
- exportloopref
- copyloopvar
issues:
exclude-use-default: false
exclude:
Expand Down
25 changes: 13 additions & 12 deletions pkg/utils/rpcerror_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
package utils

import (
"fmt"
"errors"
"net/http"
"testing"

"github.com/labstack/echo/v4"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"gotest.tools/assert"
"net/http"
"testing"
)

func Test_ConvertGRPCError(t *testing.T) {
Expand All @@ -31,54 +32,54 @@ func Test_ConvertHttpError(t *testing.T) {

func Test_ConvertGrpcError_NoContent(t *testing.T) {
validationErrMsg := respInternalInvalid + ` test1`
httpError := ConvertGrpcError(fmt.Errorf(validationErrMsg))
httpError := ConvertGrpcError(errors.New(validationErrMsg))
assert.Error(t, httpError, "code=204, message=rpc error: code = Internal desc = rpc error: code = InvalidArgument test1")
}

func Test_ConvertGrpcError_Leafref(t *testing.T) {
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`
httpError := ConvertGrpcError(fmt.Errorf(validationErrMsg))
httpError := ConvertGrpcError(errors.New(validationErrMsg))
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")
}

func Test_ConvertGrpcError_ValidationOther(t *testing.T) {
validationErrMsg := respInvalidValidation + ` test1234` + notEqual
httpError := ConvertGrpcError(fmt.Errorf(validationErrMsg))
httpError := ConvertGrpcError(errors.New(validationErrMsg))
assert.Error(t, httpError, "code=400, message=test1234")
}

func Test_ConvertGrpcError_ValidationOther1(t *testing.T) {
validationErrMsg := respInvalidValidation + ` test1234 (test abc)` + " " + schemaPath + " /a/b/c " + hasLrPath + " /d/e/f " + notEqual + " " + notEqual
httpError := ConvertGrpcError(fmt.Errorf(validationErrMsg))
httpError := ConvertGrpcError(errors.New(validationErrMsg))
assert.Error(t, httpError, "code=400, message=Change gives LeafRef error on /d/e/f. test1234 not present. From path: /a/b/c")
}

func Test_ConvertGrpcError_ValidationNotRepeated(t *testing.T) {
validationErrMsg := respInvalidValidation + ` test1234 (test abc)` + " " + schemaPath + " /a/b/c " + hasLrPath + " /d/e/f " + notEqual
httpError := ConvertGrpcError(fmt.Errorf(validationErrMsg))
httpError := ConvertGrpcError(errors.New(validationErrMsg))
assert.Error(t, httpError, "code=400, message=Change gives LeafRef error on /d/e/f. test1234 not present. From path: /a/b/c")
}

func Test_ConvertGrpcError_ValidationNoBracket(t *testing.T) {
validationErrMsg := respInvalidValidation + ` test1234 test abc)` + " " + schemaPath + " /a/b/c " + hasLrPath + " /d/e/f " + notEqual
httpError := ConvertGrpcError(fmt.Errorf(validationErrMsg))
httpError := ConvertGrpcError(errors.New(validationErrMsg))
assert.Error(t, httpError, "code=400, message=test1234 test abc) schema path /a/b/c has leafref path /d/e/f ")
}

func Test_ConvertGrpcError_InvalidOther(t *testing.T) {
validationErrMsg := respInvalidBase + ` test1234`
httpError := ConvertGrpcError(fmt.Errorf(validationErrMsg))
httpError := ConvertGrpcError(errors.New(validationErrMsg))
assert.Error(t, httpError, "code=400, message=rpc error: code = InvalidArgument desc = test1234")
}

func Test_ConvertGrpcError_Unauthorized(t *testing.T) {
validationErrMsg := respUnauthorized + ` test1234`
httpError := ConvertGrpcError(fmt.Errorf(validationErrMsg))
httpError := ConvertGrpcError(errors.New(validationErrMsg))
assert.Error(t, httpError, "code=401, message=rpc error: code = Unauthenticated desc = test1234")
}

func Test_ConvertGrpcError_Internal(t *testing.T) {
validationErrMsg := `rpc error: code = test1234`
httpError := ConvertGrpcError(fmt.Errorf(validationErrMsg))
httpError := ConvertGrpcError(errors.New(validationErrMsg))
assert.Error(t, httpError, "code=500, message=rpc error: code = test1234")
}
Loading