MCPcopy Create free account
hub / github.com/conforma/cli / TestGetPolicy

Function TestGetPolicy

internal/policy/source/source_test.go:63–117  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

61}
62
63func TestGetPolicy(t *testing.T) {
64 tests := []struct {
65 name string
66 sourceUrl string
67 dest string
68 metadata metadata.Metadata
69 err error
70 }{
71 {
72 name: "Gets policies",
73 sourceUrl: "https://example.com/user/foo.git",
74 dest: "/tmp/ec-work-1234/policy/[0-9a-f]+",
75 metadata: &fileMetadata.FSMetadata{},
76 err: nil,
77 },
78 {
79 name: "Gets policies with getter style source url",
80 sourceUrl: "git::https://example.com/user/foo.git//subdir?ref=devel",
81 dest: "/tmp/ec-work-1234/policy/[0-9a-f]+",
82 metadata: &fileMetadata.FSMetadata{},
83 err: nil,
84 },
85 {
86 name: "Fails fetching the policy",
87 sourceUrl: "failure",
88 dest: "/tmp/ec-work-1234/policy/[0-9a-f]+",
89 metadata: &fileMetadata.FSMetadata{},
90 err: errors.New("expected"),
91 },
92 }
93 for _, tt := range tests {
94 t.Run(tt.name, func(t *testing.T) {
95 p := PolicyUrl{Url: tt.sourceUrl, Kind: PolicyKind}
96
97 dl := mockDownloader{}
98 dl.On("Download", mock.Anything, mock.MatchedBy(func(dest string) bool {
99 matched, err := regexp.MatchString(tt.dest, dest)
100 if err != nil {
101 panic(err)
102 }
103
104 return matched
105 }), tt.sourceUrl, false).Return(tt.metadata, tt.err)
106
107 _, err := p.GetPolicy(usingDownloader(context.TODO(), &dl), "/tmp/ec-work-1234", false)
108 if tt.err == nil {
109 assert.NoError(t, err, "GetPolicies returned an error")
110 } else {
111 assert.EqualError(t, err, tt.err.Error())
112 }
113
114 mock.AssertExpectationsForObjects(t, &dl)
115 })
116 }
117}
118
119func TestInlineDataSource(t *testing.T) {
120 tests := []struct {

Callers

nothing calls this directly

Calls 4

GetPolicyMethod · 0.95
usingDownloaderFunction · 0.85
RunMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected