Debian Codegraph @

plugin/describekey_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 plugin
15
16 import (
17 "fmt"
18 "testing"
19 )
20
21 func TestDescribeKeyRequest_Validate(t *testing.T) {
22 reqs := []DescribeKeyRequest{
23 getDescribeKeyRequest(ContractVersion, "someKeyId"),
24 {
25 ContractVersion: ContractVersion,
26 KeyID: "someKeyId",
27 PluginConfig: map[string]string{"someKey": "someValue"}},
28 }
29
30 for _, req := range reqs {
31 if err := req.Validate(); err != nil {
32 t.Errorf("VerifySignatureRequest#Validate failed with error: %+v", err)
33 }
34 }
35 }
36
37 func TestDescribeKeyRequest_Validate_Error(t *testing.T) {
38 testCases := []struct {
39 name string
40 req DescribeKeyRequest
41 }{
42 {name: "contractVersion", req: getDescribeKeyRequest("", "someKeyId")},
43 {name: "keyId", req: getDescribeKeyRequest(ContractVersion, "")},
44 }
45
46 for _, testcase := range testCases {
47 t.Run(testcase.name, func(t *testing.T) {
48 if err := testcase.req.Validate(); err != nil {
49 expMsg := fmt.Sprintf("{\"errorCode\":\"VALIDATION_ERROR\",\"errorMessage\":\"%s cannot be empty\"}", testcase.name)
50 if err.Error() != expMsg {
51 t.Errorf("expected error message '%s' but got '%s'", expMsg, err.Error())
52 }
53 } else {
54 t.Error("DescribeKeyRequest#Validate didn't returned error")
55 }
56 })
57 }
58 }
59
60 func TestDescribeKeyRequest_Command(t *testing.T) {
61 req := getDescribeKeyRequest(ContractVersion, "someKeyId")
62 if cmd := req.Command(); cmd != CommandDescribeKey {
63 t.Errorf("DescribeKeyRequest#Command, expected %s but returned %s", CommandDescribeKey, cmd)
64 }
65 }
66
67 func getDescribeKeyRequest(cv, kid string) DescribeKeyRequest {
68 return DescribeKeyRequest{
69 ContractVersion: cv,
70 KeyID: kid,
71 }
72 }