-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdeletebranch_test.go
More file actions
54 lines (49 loc) · 1.46 KB
/
deletebranch_test.go
File metadata and controls
54 lines (49 loc) · 1.46 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
44
45
46
47
48
49
50
51
52
53
54
package stash
import (
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"testing"
)
func TestDeleteBranch(t *testing.T) {
type deleteModel struct {
Ref string `json:"name"`
DryRun bool `json:"dryRun"`
}
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != "DELETE" {
t.Fatalf("wanted DELETE but found %s\n", r.Method)
}
url := *r.URL
if url.Path != "/rest/branch-utils/1.0/projects/PROJ/repos/slug/branches" {
t.Fatalf("want /rest/branch-utils/1.0/projects/PROJ/repos/slug/branches but got %s\n", url.Path)
}
if r.Header.Get("Content-type") != "application/json" {
t.Fatalf("Want Content-type application/json but found %s\n", r.Header.Get("Content-type"))
}
if r.Header.Get("Authorization") != "Basic dTpw" {
t.Fatalf("Want Basic dTpw but found %s\n", r.Header.Get("Authorization"))
}
data, err := ioutil.ReadAll(r.Body)
if err != nil {
t.Fatalf("Unexpected error: %v\n", err)
}
var d deleteModel
if err := json.Unmarshal(data, &d); err != nil {
t.Fatalf("Unexpected error: %v\n", err)
}
if d.Ref != "refs/heads/issue/1" {
t.Fatalf("Want refs/heads/issue/1 but got %s\n", d.Ref)
}
w.WriteHeader(204)
}))
defer testServer.Close()
url, _ := url.Parse(testServer.URL)
stashClient := NewClient("u", "p", url)
err := stashClient.DeleteBranch("PROJ", "slug", "issue/1")
if err != nil {
t.Fatalf("Not expecting error: %v\n", err)
}
}