MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / TestEnsureScheme

Function TestEnsureScheme

pkg/policies/loader_test.go:26–78  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func TestEnsureScheme(t *testing.T) {
27 tests := []struct {
28 name string
29 ref string
30 expected []string
31 wantPath string
32 wantErr bool
33 }{
34 {
35 name: "we want ta file scheme and received one",
36 ref: "file:///tmp/policy.json",
37 expected: []string{fileScheme},
38 wantPath: "/tmp/policy.json",
39 },
40 {
41 name: "we want a file scheme and received a chainloop scheme",
42 ref: "chainloop:///policy.json",
43 expected: []string{fileScheme},
44 wantErr: true,
45 },
46 {
47 name: "we want a https scheme",
48 ref: "https://example.com/policy.json",
49 expected: []string{httpsScheme},
50 wantPath: "example.com/policy.json",
51 },
52 {
53 name: "it works with both http and https",
54 ref: "http://example.com/policy.json",
55 expected: []string{httpsScheme, httpScheme},
56 wantPath: "example.com/policy.json",
57 },
58 {
59 name: "doest not supports default schema",
60 ref: "built-in-policy",
61 expected: []string{chainloopScheme},
62 wantErr: true,
63 },
64 }
65
66 for _, tt := range tests {
67 t.Run(tt.name, func(t *testing.T) {
68 gotScheme, err := ensureScheme(tt.ref, tt.expected...)
69 if tt.wantErr {
70 assert.Error(t, err)
71 return
72 }
73
74 require.NoError(t, err)
75 assert.Equal(t, tt.wantPath, gotScheme)
76 })
77 }
78}
79
80func TestPolicyReferenceResourceDescriptor(t *testing.T) {
81 testCases := []struct {

Callers

nothing calls this directly

Calls 3

ensureSchemeFunction · 0.85
ErrorMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected