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

Function TestGoGetterDownload

internal/policy/source/git_config_test.go:282–398  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

280}
281
282func TestGoGetterDownload(t *testing.T) {
283 tests := []struct {
284 name string
285 src string
286 tmpDir string
287 setupFS func(fs afero.Fs, destDir string) error
288 mockDownloader func(*mockDownloader, string)
289 expectError bool
290 errorMsg string
291 }{
292 {
293 name: "successful download with policy.yaml file",
294 src: "https://github.com/example/policy",
295 tmpDir: "/tmp/test",
296 setupFS: func(fs afero.Fs, destDir string) error {
297 // Create the downloaded directory structure
298 if err := fs.MkdirAll(destDir, 0o755); err != nil {
299 return err
300 }
301 // Create a policy.yaml file that choosePolicyFile can find
302 return afero.WriteFile(fs, path.Join(destDir, "policy.yaml"), []byte("test config"), 0o644)
303 },
304 mockDownloader: func(m *mockDownloader, destDir string) {
305 // Mock successful download
306 m.On("Download", mock.Anything, destDir, "https://github.com/example/policy", false).
307 Return(&fileMetadata.FSMetadata{Path: destDir}, nil)
308 },
309 expectError: false,
310 },
311 {
312 name: "successful download with .ec/policy.json file",
313 src: "https://github.com/example/policy2",
314 tmpDir: "/tmp/test2",
315 setupFS: func(fs afero.Fs, destDir string) error {
316 if err := fs.MkdirAll(destDir, 0o755); err != nil {
317 return err
318 }
319 // Create .ec/policy.json file (higher priority)
320 return afero.WriteFile(fs, path.Join(destDir, ".ec/policy.json"), []byte(`{"policy": "config"}`), 0o644)
321 },
322 mockDownloader: func(m *mockDownloader, destDir string) {
323 m.On("Download", mock.Anything, destDir, "https://github.com/example/policy2", false).
324 Return(&fileMetadata.FSMetadata{Path: destDir}, nil)
325 },
326 expectError: false,
327 },
328 {
329 name: "download failure",
330 src: "https://github.com/example/nonexistent",
331 tmpDir: "/tmp/test3",
332 setupFS: func(fs afero.Fs, destDir string) error {
333 // No filesystem setup needed for download failure
334 return nil
335 },
336 mockDownloader: func(m *mockDownloader, destDir string) {
337 m.On("Download", mock.Anything, destDir, "https://github.com/example/nonexistent", false).
338 Return(nil, errors.New("failed to download: repository not found"))
339 },

Callers

nothing calls this directly

Calls 7

WithFSFunction · 0.92
uniqueDirFunction · 0.85
usingDownloaderFunction · 0.85
ClearDownloadCacheFunction · 0.85
GoGetterDownloadFunction · 0.85
RunMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected