-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathgetrawfile_test.go
More file actions
43 lines (38 loc) · 1.08 KB
/
getrawfile_test.go
File metadata and controls
43 lines (38 loc) · 1.08 KB
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
package stash
import (
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"testing"
)
func TestGetRawFile(t *testing.T) {
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
t.Fatalf("wanted GET but found %s\n", r.Method)
}
url := *r.URL
wantPath := "/projects/prj/repos/repo/browse/foo/bar"
if url.Path != wantPath {
t.Fatalf("Want %s but found %s\n", wantPath, url.Path)
}
if r.Header.Get("Authorization") != "Basic dTpw" {
t.Fatalf("Want Basic dTpw but found %s\n", r.Header.Get("Authorization"))
}
params := url.Query()
if params.Get("at") != "master" {
t.Fatalf("Want master but found %s\n", params["at"])
}
if _, ok := params["raw"]; !ok {
t.Fatalf("Want a raw query param but found none")
}
fmt.Fprint(w, "hello")
}))
defer testServer.Close()
url, _ := url.Parse(testServer.URL)
stashClient := NewClient("u", "p", url)
data, _ := stashClient.GetRawFile("PRJ", "REPO", "foo/bar", "master")
if string(data) != "hello" {
t.Fatalf("Want hello, but got <%s>\n", string(data))
}
}