-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdownload_test.go
72 lines (61 loc) · 2.93 KB
/
download_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
func TestDownload(t *testing.T) {
testEnv(t)
api := Ding{}
const buildScript = `#!/usr/bin/env bash
set -e
echo building...
echo hi>myfile
echo version: 1.2.3
echo release: mycmd linux amd64 toolchain1.2.3 myfile
touch $DING_DOWNLOADDIR/coverage.txt
echo coverage: 80.0
echo coverage-report: coverage.txt
`
r := Repo{
Name: "dltest",
VCS: VCSCommand,
Origin: "sh -c 'echo clone..; mkdir -p checkout/$DING_CHECKOUTPATH; echo commit: ...'",
DefaultBranch: "main",
CheckoutPath: "dltest",
BuildScript: buildScript,
}
api.RepoCreate(ctxbg, config.Password, r)
b := api.BuildCreate(ctxbg, config.Password, r.Name, "unused", "", false)
twaitBuild(t, b, StatusSuccess)
testGet := func(h http.HandlerFunc, path string, expCode int) {
t.Helper()
w := httptest.NewRecorder()
r := httptest.NewRequest("GET", path, nil)
h(w, r)
tcompare(t, w.Code, expCode)
}
testGet(serveDownload, fmt.Sprintf("/dl/file/dltest/%d/coverage.txt", b.ID), http.StatusOK)
testGet(serveDownload, fmt.Sprintf("/dl/file/dltest/%d/bogus.txt", b.ID), http.StatusNotFound)
testGet(serveDownload, fmt.Sprintf("/dl/file/bogus/%d/coverage.txt", b.ID), http.StatusNotFound)
testGet(serveDownload, fmt.Sprintf("/dl/file/dltest/%d/coverage.txt", b.ID+990), http.StatusNotFound)
testGet(serveDownload, fmt.Sprintf("/dl/result/dltest/%d/any.zip", b.ID), http.StatusOK)
testGet(serveDownload, fmt.Sprintf("/dl/result/dltest/%d/any.tgz", b.ID), http.StatusOK)
testGet(serveDownload, fmt.Sprintf("/dl/release/dltest/%d/any.zip", b.ID), http.StatusNotFound)
testGet(serveDownload, fmt.Sprintf("/dl/release/dltest/%d/any.tgz", b.ID), http.StatusNotFound)
testGet(serveResult, fmt.Sprintf("/result/dltest/%d/myfile", b.ID), http.StatusOK)
testGet(serveResult, fmt.Sprintf("/result/bogus/%d/myfile", b.ID), http.StatusNotFound)
testGet(serveResult, fmt.Sprintf("/result/dltest/%d/myfile", b.ID+999), http.StatusNotFound)
testGet(serveResult, fmt.Sprintf("/result/dltest/%d/bogusfile", b.ID), http.StatusNotFound)
testGet(serveRelease, fmt.Sprintf("/release/dltest/%d/myfile", b.ID), http.StatusNotFound)
api.ReleaseCreate(ctxbg, config.Password, r.Name, b.ID)
testGet(serveDownload, fmt.Sprintf("/dl/release/dltest/%d/any.zip", b.ID), http.StatusOK)
testGet(serveDownload, fmt.Sprintf("/dl/release/dltest/%d/any.tgz", b.ID), http.StatusOK)
testGet(serveDownload, fmt.Sprintf("/dl/result/dltest/%d/any.zip", b.ID), http.StatusOK)
testGet(serveDownload, fmt.Sprintf("/dl/result/dltest/%d/any.tgz", b.ID), http.StatusOK)
testGet(serveDownload, fmt.Sprintf("/dl/release/dltest/%d/any.bogus", b.ID), http.StatusNotFound)
testGet(serveDownload, fmt.Sprintf("/dl/result/dltest/%d/any.bogus", b.ID), http.StatusNotFound)
testGet(serveResult, fmt.Sprintf("/result/dltest/%d/myfile", b.ID), http.StatusOK)
testGet(serveRelease, fmt.Sprintf("/release/dltest/%d/myfile", b.ID), http.StatusOK)
}