Debian Codegraph @

cli/utils_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 cli
15
16 import (
17 "reflect"
18 "strings"
19 "testing"
20
21 "github.com/notaryproject/notation-plugin-framework-go/plugin"
22 )
23
24 func TestGetValidArgsString(t *testing.T) {
25 mdResp := plugin.GetMetadataResponse{
26 Name: "Example Plugin",
27 Description: "This is an description of example plugin. 🍺",
28 URL: "https://example.com/notation/plugin",
29 Version: "1.0.0",
30 Capabilities: []plugin.Capability{
31 plugin.CapabilityEnvelopeGenerator,
32 plugin.CapabilityTrustedIdentityVerifier,
33 plugin.CapabilityRevocationCheckVerifier},
34 }
35 s := getValidArgsString(&mdResp)
36 expected := "<generate-envelope|get-plugin-metadata|verify-signature|version>"
37 if !strings.EqualFold(s, expected) {
38 t.Errorf("Expected %s but found %s", expected, s)
39 }
40 }
41
42 func TestGetValidArgs(t *testing.T) {
43 tests := map[string]struct {
44 caps []plugin.Capability
45 args []string
46 }{
47 "sigGeneratorOnly": {
48 caps: []plugin.Capability{plugin.CapabilitySignatureGenerator},
49 args: []string{"describe-key", "generate-signature", "get-plugin-metadata", "version"},
50 },
51 "envGeneratorOnly": {
52 caps: []plugin.Capability{plugin.CapabilityEnvelopeGenerator},
53 args: []string{"generate-envelope", "get-plugin-metadata", "version"},
54 },
55 "verificationOnly": {
56 caps: []plugin.Capability{plugin.CapabilityTrustedIdentityVerifier, plugin.CapabilityRevocationCheckVerifier},
57 args: []string{"get-plugin-metadata", "verify-signature", "version"},
58 },
59 "envGenerator+verification": {
60 caps: []plugin.Capability{plugin.CapabilityEnvelopeGenerator, plugin.CapabilityTrustedIdentityVerifier, plugin.CapabilityRevocationCheckVerifier},
61 args: []string{"generate-envelope", "get-plugin-metadata", "verify-signature", "version"},
62 },
63 }
64 for name, test := range tests {
65 t.Run(name, func(t *testing.T) {
66 mdResp := plugin.GetMetadataResponse{
67 Name: "Example Plugin",
68 Description: "This is an description of example plugin. 🍺",
69 URL: "https://example.com/notation/plugin",
70 Version: "1.0.0",
71 Capabilities: test.caps,
72 }
73 s := getValidArgs(&mdResp)
74 if !reflect.DeepEqual(s, test.args) {
75 t.Errorf("Expected %s but found %s", test.args, s)
76 }
77 })
78 }
79 }