Debian Codegraph @

pkg/signature/kms/hashivault/hashivault_test.go

raw
1 //
2 // Copyright 2021 The Sigstore Authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15
16 package hashivault
17
18 import "testing"
19
20 func TestParseReference(t *testing.T) {
21 tests := []struct {
22 in string
23 wantKey string
24 wantErr bool
25 }{
26 {
27 in: "hashivault://cosign",
28 wantKey: "cosign",
29 wantErr: false,
30 },
31 {
32 in: "hashivault://cosign/nested",
33 wantErr: true,
34 },
35 {
36 in: "foo://bar",
37 wantErr: true,
38 },
39 {
40 in: "",
41 wantErr: true,
42 },
43 }
44 for _, tt := range tests {
45 t.Run(tt.in, func(t *testing.T) {
46 gotKey, err := parseReference(tt.in)
47 if (err != nil) != tt.wantErr {
48 t.Errorf("parseReference() error = %v, wantErr %v", err, tt.wantErr)
49 return
50 }
51 if gotKey != tt.wantKey {
52 t.Errorf("parseReference() gotKey = %v, want %v", gotKey, tt.wantKey)
53 }
54 })
55 }
56 }