forked from kovetskiy/stash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhasrepo_test.go
More file actions
34 lines (30 loc) · 1.01 KB
/
hasrepo_test.go
File metadata and controls
34 lines (30 loc) · 1.01 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
package stash
import (
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"testing"
)
func TestHasRepository(t *testing.T) {
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
url := *r.URL
if url.Path != "/rest/api/1.0/repos" {
t.Fatalf("GetRepositories() URL path expected to be /rest/api/1.0/repos but found %s\n", url.Path)
}
if r.Header.Get("Authorization") != "Basic dTpw" {
t.Fatalf("Want Basic dTpw but found %s\n", r.Header.Get("Authorization"))
}
fmt.Fprintln(w, repos)
}))
defer testServer.Close()
url, _ := url.Parse(testServer.URL)
stashClient := NewClient("u", "p", url)
repositories, err := stashClient.GetRepositories()
if err != nil {
t.Fatalf("GetRepositories() not expecting an error, but received: %v\n", err)
}
if _, ok := HasRepository(repositories, "ssh://git@example.com:9999/teami/rabbit.git"); !ok {
t.Fatalf("HasRepositories() expecting to contain %s, but did not\n", "ssh://git@example.com:9999/teami/rabbit.git")
}
}