This repository has been archived by the owner on Mar 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
57 lines (48 loc) · 1.53 KB
/
main_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
package main
import (
"fmt"
"io/ioutil"
"net/http/httptest"
"strings"
"testing"
)
func TestCloneBranch(t *testing.T) {
req := httptest.NewRequest("GET", "http://example.com/clone", nil)
w := httptest.NewRecorder()
cloneBranch(w, req)
resp := w.Result()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
if !strings.Contains(string(body), "Invalid request method") {
t.Errorf("This method should only work with a POST. It worked with a GET.")
}
req = httptest.NewRequest("POST", "http://example.com/clone", nil)
w = httptest.NewRecorder()
cloneBranch(w, req)
resp = w.Result()
body, _ = ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
if !strings.Contains(string(body), "The repository entered does not look like a git repo.") {
t.Errorf("The request did not included a valid Repository but the system think it does.")
}
}
func TestGetInfo(t *testing.T) {
req := httptest.NewRequest("GET", "http://example.com/info", nil)
w := httptest.NewRecorder()
getInfo(w, req)
resp := w.Result()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
if !strings.Contains(string(body), "not set") {
t.Errorf("ENV COMMIT_HASH should always be not set during build.")
}
req = httptest.NewRequest("POST", "http://example.com/info", nil)
w = httptest.NewRecorder()
getInfo(w, req)
resp = w.Result()
body, _ = ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
if !strings.Contains(string(body), "Invalid request method") {
t.Errorf("This method should only work with a GET. It worked with a POST.")
}
}