MCPcopy
hub / github.com/google/go-containerregistry / TestMultiKeychain

Function TestMultiKeychain

pkg/authn/multikeychain_test.go:23–86  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

21)
22
23func TestMultiKeychain(t *testing.T) {
24 one := &Basic{Username: "one", Password: "secret"}
25 two := &Basic{Username: "two", Password: "secret"}
26 three := &Basic{Username: "three", Password: "secret"}
27
28 regOne, _ := name.NewRegistry("one.gcr.io", name.StrictValidation)
29 regTwo, _ := name.NewRegistry("two.gcr.io", name.StrictValidation)
30 regThree, _ := name.NewRegistry("three.gcr.io", name.StrictValidation)
31
32 tests := []struct {
33 name string
34 reg name.Registry
35 kc Keychain
36 want Authenticator
37 }{{
38 // Make sure our test keychain WAI
39 name: "simple fixed test (match)",
40 reg: regOne,
41 kc: fixedKeychain{regOne: one},
42 want: one,
43 }, {
44 // Make sure our test keychain WAI
45 name: "simple fixed test (no match)",
46 reg: regTwo,
47 kc: fixedKeychain{regOne: one},
48 want: Anonymous,
49 }, {
50 name: "match first keychain",
51 reg: regOne,
52 kc: NewMultiKeychain(
53 fixedKeychain{regOne: one},
54 fixedKeychain{regOne: three, regTwo: two},
55 ),
56 want: one,
57 }, {
58 name: "match second keychain",
59 reg: regTwo,
60 kc: NewMultiKeychain(
61 fixedKeychain{regOne: one},
62 fixedKeychain{regOne: three, regTwo: two},
63 ),
64 want: two,
65 }, {
66 name: "match no keychain",
67 reg: regThree,
68 kc: NewMultiKeychain(
69 fixedKeychain{regOne: one},
70 fixedKeychain{regOne: three, regTwo: two},
71 ),
72 want: Anonymous,
73 }}
74
75 for _, test := range tests {
76 t.Run(test.name, func(t *testing.T) {
77 got, err := test.kc.Resolve(test.reg)
78 if err != nil {
79 t.Errorf("Resolve() = %v", err)
80 }

Callers

nothing calls this directly

Calls 3

NewRegistryFunction · 0.92
NewMultiKeychainFunction · 0.85
ResolveMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…