(t *testing.T)
| 58 | } |
| 59 | |
| 60 | func Test_Download(t *testing.T) { |
| 61 | tmpDir := t.TempDir() |
| 62 | destDir, err := safepaths.ParseAbsolute(filepath.Join(tmpDir, "artifact")) |
| 63 | require.NoError(t, err) |
| 64 | |
| 65 | reg := &httpmock.Registry{} |
| 66 | defer reg.Verify(t) |
| 67 | |
| 68 | reg.Register( |
| 69 | httpmock.REST("GET", "repos/OWNER/REPO/actions/artifacts/12345/zip"), |
| 70 | httpmock.FileResponse("./fixtures/myproject.zip")) |
| 71 | |
| 72 | api := &apiPlatform{ |
| 73 | client: &http.Client{Transport: reg}, |
| 74 | } |
| 75 | require.NoError(t, api.Download("https://api.github.com/repos/OWNER/REPO/actions/artifacts/12345/zip", destDir)) |
| 76 | |
| 77 | var paths []string |
| 78 | parentPrefix := tmpDir + string(filepath.Separator) |
| 79 | err = filepath.Walk(tmpDir, func(p string, info os.FileInfo, err error) error { |
| 80 | if err != nil { |
| 81 | return err |
| 82 | } |
| 83 | if p == tmpDir { |
| 84 | return nil |
| 85 | } |
| 86 | entry := strings.TrimPrefix(p, parentPrefix) |
| 87 | if info.IsDir() { |
| 88 | entry += "/" |
| 89 | } else if info.Mode()&0111 != 0 { |
| 90 | entry += "(X)" |
| 91 | } |
| 92 | paths = append(paths, entry) |
| 93 | return nil |
| 94 | }) |
| 95 | require.NoError(t, err) |
| 96 | |
| 97 | sort.Strings(paths) |
| 98 | assert.Equal(t, []string{ |
| 99 | "artifact/", |
| 100 | filepath.Join("artifact", "bin") + "/", |
| 101 | filepath.Join("artifact", "bin", "myexe"), |
| 102 | filepath.Join("artifact", "readme.md"), |
| 103 | filepath.Join("artifact", "src") + "/", |
| 104 | filepath.Join("artifact", "src", "main.go"), |
| 105 | filepath.Join("artifact", "src", "util.go"), |
| 106 | }, paths) |
| 107 | } |
nothing calls this directly
no test coverage detected