Commit 71f620be authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 9ed9b81e
...@@ -460,6 +460,7 @@ func sha1s(data []byte) string { ...@@ -460,6 +460,7 @@ func sha1s(data []byte) string {
return fmt.Sprintf("%x", sha1.Sum(data)) return fmt.Sprintf("%x", sha1.Sum(data))
} }
// download an URL
func download(t *testing.T, url string, h http.Header) (*http.Response, []byte) { func download(t *testing.T, url string, h http.Header) (*http.Response, []byte) {
req, err := http.NewRequest("GET", url, nil) req, err := http.NewRequest("GET", url, nil)
if err != nil { if err != nil {
...@@ -489,18 +490,18 @@ type DownloadContext struct { ...@@ -489,18 +490,18 @@ type DownloadContext struct {
Header http.Header Header http.Header
} }
func DownloadContextNew(t *testing.T, urlPrefix string) *DownloadContext { func NewDownloadContext(t *testing.T, urlPrefix string) *DownloadContext {
h := make(http.Header) h := make(http.Header)
return &DownloadContext{t, urlPrefix, h} return &DownloadContext{t, urlPrefix, h}
} }
func (dl DownloadContext) downloadRaw(path string) (*http.Response, []byte) { func (dl DownloadContext) download(path string) (*http.Response, []byte) {
return download(dl.t, dl.urlPrefix+path, dl.Header) return download(dl.t, dl.urlPrefix+path, dl.Header)
} }
// download `path` and expect content sha1 to be `expectSha1` // download `path` and expect content sha1 to be `expectSha1`
func (dl DownloadContext) ExpectSha1(path, expectSha1 string) { func (dl DownloadContext) ExpectSha1(path, expectSha1 string) {
resp, out := dl.downloadRaw(path) resp, out := dl.download(path)
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
dl.t.Fatalf("Unexpected status code (expected 200, got %v)", resp.StatusCode) dl.t.Fatalf("Unexpected status code (expected 200, got %v)", resp.StatusCode)
} }
...@@ -517,7 +518,7 @@ func (dl DownloadContext) Expect(path, expect string) { ...@@ -517,7 +518,7 @@ func (dl DownloadContext) Expect(path, expect string) {
// download `path` and expect HTTP status code to be `code` // download `path` and expect HTTP status code to be `code`
func (dl DownloadContext) ExpectCode(path string, code int) { func (dl DownloadContext) ExpectCode(path string, code int) {
resp, _ := dl.downloadRaw(path) resp, _ := dl.download(path)
if resp.StatusCode != code { if resp.StatusCode != code {
dl.t.Fatalf("Unexpected status code (expected %v, got %v)", code, resp.StatusCode) dl.t.Fatalf("Unexpected status code (expected %v, got %v)", code, resp.StatusCode)
} }
...@@ -529,7 +530,7 @@ func TestBlobDownload(t *testing.T) { ...@@ -529,7 +530,7 @@ func TestBlobDownload(t *testing.T) {
defer ts.Close() defer ts.Close()
ws := startWorkhorseServer(ts.URL) ws := startWorkhorseServer(ts.URL)
defer ws.Close() defer ws.Close()
dl := DownloadContextNew(t, fmt.Sprintf("%s/%s/raw", ws.URL, testProject)) dl := NewDownloadContext(t, fmt.Sprintf("%s/%s/raw", ws.URL, testProject))
dl.Expect("/5f923865/README.md", "testme\n======\n\nSample repo for testing gitlab features\n") dl.Expect("/5f923865/README.md", "testme\n======\n\nSample repo for testing gitlab features\n")
dl.ExpectSha1("/5f923865/README.md", "5f7af35c185a9e5face2f4afb6d7c4f00328d04c") dl.ExpectSha1("/5f923865/README.md", "5f7af35c185a9e5face2f4afb6d7c4f00328d04c")
...@@ -544,7 +545,7 @@ func TestDeniedBlobDownload(t *testing.T) { ...@@ -544,7 +545,7 @@ func TestDeniedBlobDownload(t *testing.T) {
defer ts.Close() defer ts.Close()
ws := startWorkhorseServer(ts.URL) ws := startWorkhorseServer(ts.URL)
defer ws.Close() defer ws.Close()
dl := DownloadContextNew(t, fmt.Sprintf("%s/%s/raw", ws.URL, testProject)) dl := NewDownloadContext(t, fmt.Sprintf("%s/%s/raw", ws.URL, testProject))
dl.ExpectCode("/5f923865/README.md", 403) dl.ExpectCode("/5f923865/README.md", 403)
dl.ExpectCode("/5f923865/files/ruby/popen.rb", 403) dl.ExpectCode("/5f923865/files/ruby/popen.rb", 403)
...@@ -576,7 +577,7 @@ func TestPrivateBlobDownload(t *testing.T) { ...@@ -576,7 +577,7 @@ func TestPrivateBlobDownload(t *testing.T) {
defer ts.Close() defer ts.Close()
ws := startWorkhorseServer(ts.URL) ws := startWorkhorseServer(ts.URL)
defer ws.Close() defer ws.Close()
dl := DownloadContextNew(t, fmt.Sprintf("%s/%s/raw", ws.URL, testProject)) dl := NewDownloadContext(t, fmt.Sprintf("%s/%s/raw", ws.URL, testProject))
dl.ExpectCode("/5f923865/README.md", 403) dl.ExpectCode("/5f923865/README.md", 403)
dl.ExpectCode("/5f923865/README.md?bbb_token=TOKEN-4BBB", 403) dl.ExpectCode("/5f923865/README.md?bbb_token=TOKEN-4BBB", 403)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment