This repository has been archived by the owner on Feb 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Olivier Biesmans
committed
Sep 7, 2017
1 parent
3da1487
commit 945f546
Showing
6 changed files
with
161 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,77 @@ | ||
package hooks | ||
|
||
import ( | ||
"io/ioutil" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
) | ||
|
||
var GetApplications = []byte(`{ | ||
"applications": [ | ||
{ | ||
"id": 456, | ||
"name": "Webhooks" | ||
} | ||
] | ||
}`) | ||
|
||
var GetApplicationsEmpty = []byte(`{"applications": []}`) | ||
|
||
var apiStub = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
switch r.RequestURI { | ||
case "/v2/applications/456/deployments.json": | ||
if r.Header.Get("X-Api-Key") != "123" { | ||
w.WriteHeader(http.StatusUnauthorized) | ||
} else { | ||
body, _ := ioutil.ReadAll(r.Body) | ||
|
||
if r.Header.Get("X-Api-Key") != "123" { | ||
w.WriteHeader(http.StatusUnauthorized) | ||
} else { | ||
switch r.RequestURI { | ||
case "/v2/applications.json": | ||
w.WriteHeader(http.StatusOK) | ||
if string(body) == "filter[name]=webhook" { | ||
w.Write(GetApplications) | ||
} else { | ||
w.Write(GetApplicationsEmpty) | ||
} | ||
|
||
case "/v2/applications/456/deployments.json": | ||
w.WriteHeader(http.StatusCreated) | ||
|
||
default: | ||
w.WriteHeader(http.StatusBadRequest) | ||
} | ||
default: | ||
w.WriteHeader(http.StatusBadRequest) | ||
} | ||
})) | ||
|
||
func TestCreateDeployment(t *testing.T) { | ||
c := &NewRelicClient{ | ||
HttpClient: &http.Client{}, | ||
Url: apiStub.URL, | ||
ApplicationId: 456, | ||
ApiKey: "123", | ||
ApplicationId: "456", | ||
Stop: false, | ||
} | ||
//c.Log.SetLevel(log.DebugLevel) | ||
d := &NewRelicDeployment{} | ||
|
||
err := c.CreateDeployment(d) | ||
if err != nil { | ||
t.Errorf("Unexpected err : %q", err) | ||
} | ||
} | ||
|
||
func TestFindApplicationId(t *testing.T) { | ||
c := &NewRelicClient{ | ||
HttpClient: &http.Client{}, | ||
Url: apiStub.URL, | ||
ApiKey: "123", | ||
Stop: false, | ||
} | ||
// log.SetLevel(log.DebugLevel) | ||
|
||
appId, err := c.findApplicationId("webhook") | ||
if err != nil { | ||
t.Errorf("Unexpected err : %q", err) | ||
} | ||
if appId != 456 { | ||
t.Errorf("Unexpected appId : %q", appId) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters