Skip to content

Commit 3951fd4

Browse files
author
Jose Robles
committed
Tests now include the index handler function for API
1 parent dd25749 commit 3951fd4

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@ func indexAction(res http.ResponseWriter, req *http.Request) {
4343
fmt.Fprintf(res, "ERROR: Could not send robification")
4444
}
4545
res.WriteHeader(201)
46-
//res.Header().Set("Content-Type", "application/json")
47-
//b, _ := json.Marshal(p)
4846
fmt.Fprintf(res, "Robification sent")
4947
}
5048
}
49+
5150
}
5251

5352
func getConfig(jsonFile string) (config *JSONConfigData) {

main_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,12 @@ func TestSelectReviewers(t *testing.T) {
9191
}
9292

9393
func TestIndexAction(t *testing.T) {
94-
testJson := `{"action": "open","number": 280,"pull_request": {"html_url": "https://github.com/orgname/repo/pull/280","user": {"login": "josemrobles"}}}`
94+
testJson := `{"action": "opened","number": 280,"pull_request": {"html_url": "https://github.com/orgname/repo/pull/280","user": {"login": "josemrobles"}}}`
9595

9696
reader := strings.NewReader(testJson) //Convert string to reader
9797

9898
request, err := http.NewRequest("POST", testUrl, reader) //Create request with JSON body
99+
request.Header.Set("Token", "37f7f7446d64345dd367744428837fe5")
99100

100101
res, err := http.DefaultClient.Do(request)
101102

@@ -104,6 +105,6 @@ func TestIndexAction(t *testing.T) {
104105
}
105106

106107
if res.StatusCode != 201 {
107-
t.Fatal("Expected:", res.StatusCode) //Uh-oh this means our test failed
108+
t.Fatal("Expected 201 status code, received: ", res.StatusCode) //Uh-oh this means our test failed
108109
}
109110
}

0 commit comments

Comments
 (0)