Debian Codegraph @

plugin/errors_test.go

raw symbols SCIP
1 // Copyright The Notary Project Authors.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 package pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/
15
16 import (
17 "testingscip-go gomod github.com/golang/go/src go1.20 testing/"
18 )
19
20 func TestNewErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/TestNewError().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) {
21 msg := "someMSg"
22 err := NewErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewError().(ErrorCodeValidationscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ErrorCodeValidation., msg)
23 if err != nil {
24 if ErrorCodeValidationscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ErrorCodeValidation. != err.ErrCodescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#ErrCode. {
25 t.Errorfscip-go gomod github.com/golang/go/src go1.20 testing/common#Errorf().("NewError, expected errorCode '%s' but found'%s'", ErrorCodeValidationscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ErrorCodeValidation., err.ErrCodescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#ErrCode.)
26 }
27
28 if msg != err.Messagescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#Message. {
29 t.Errorfscip-go gomod github.com/golang/go/src go1.20 testing/common#Errorf().("NewError, expected message'%s' but found '%s'", msg, err.Messagescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#Message.)
30 }
31
32 if err.Metadatascip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#Metadata. != nil {
33 t.Errorfscip-go gomod github.com/golang/go/src go1.20 testing/common#Errorf().("NewError, expected metadata to be nil but found '%s'", err.Metadatascip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#Metadata.)
34 }
35
36 expError := "{\"errorCode\":\"VALIDATION_ERROR\",\"errorMessage\":\"someMSg\"}"
37 if expError != err.Errorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#Error().() {
38 t.Errorfscip-go gomod github.com/golang/go/src go1.20 testing/common#Errorf().("NewError#Error, expected error to be '%s' but found '%s'", expError, err.Errorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#Error().())
39
40 }
41
42 } else {
43 t.Errorscip-go gomod github.com/golang/go/src go1.20 testing/common#Error().("NewError didn't return an error")
44 }
45 }
46
47 func TestErrorCodesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/TestErrorCodes().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) {
48 testCases := []struct {
49 err *Errorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#
50 errCode ErrorCodescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ErrorCode#
51 }{
52 {err: NewValidationErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewValidationError().(""), errCode: ErrorCodeValidationscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ErrorCodeValidation.},
53 {err: NewValidationErrorfscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewValidationErrorf().("%s", ""), errCode: ErrorCodeValidationscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ErrorCodeValidation.},
54 {err: NewUnsupportedErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewUnsupportedError().(""), errCode: ErrorCodeValidationscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ErrorCodeValidation.},
55 {err: NewGenericErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewGenericError().(""), errCode: ErrorCodeGenericscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ErrorCodeGeneric.},
56 {err: NewGenericErrorfscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewGenericErrorf().("%s", ""), errCode: ErrorCodeGenericscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ErrorCodeGeneric.},
57 {err: NewJSONParsingErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewJSONParsingError().(""), errCode: ErrorCodeValidationscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ErrorCodeValidation.},
58 {err: NewUnsupportedContractVersionErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewUnsupportedContractVersionError().(""), errCode: ErrorCodeUnsupportedContractVersionscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ErrorCodeUnsupportedContractVersion.},
59 }
60 for _, test := range testCases {
61 if test.errCode != test.err.ErrCodescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#ErrCode. {
62 t.Errorfscip-go gomod github.com/golang/go/src go1.20 testing/common#Errorf().("Expected errorCode %s but found %s", test.errCode, test.err.ErrCodescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Error#ErrCode.)
63 }
64 }
65 }