-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* custom endpoint create unit tests * fix custom endpoint + test * lint * fix integration tests * changelog * sample API url
- Loading branch information
Showing
9 changed files
with
74 additions
and
28 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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package endpoints_test | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/logzio/logzio_terraform_client/endpoints" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestEndpoints_CreateCustomEndpoint(t *testing.T) { | ||
underTest, err, teardown := setupEndpointsTest() | ||
defer teardown() | ||
|
||
endpointId := int64(1234567) | ||
|
||
mux.HandleFunc("/v1/endpoints/custom", func(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "application/json") | ||
assert.Equal(t, http.MethodPost, r.Method) | ||
jsonBytes, _ := ioutil.ReadAll(r.Body) | ||
var target map[string]interface{} | ||
err = json.Unmarshal(jsonBytes, &target) | ||
assert.NoError(t, err) | ||
assert.Contains(t, target, "title") | ||
assert.Contains(t, target, "description") | ||
assert.Contains(t, target, "url") | ||
assert.Contains(t, target, "headers") | ||
Headers := strings.Split(fmt.Sprint(target["headers"]), ",") | ||
assert.Equal(t, 2, len(Headers)) | ||
assert.Equal(t, strings.Split(Headers[1], "=")[1], "two words") | ||
|
||
w.WriteHeader(http.StatusOK) | ||
w.Header().Set("Content-Type", "application/json") | ||
fmt.Fprint(w, fixture("create_endpoint.json")) | ||
}) | ||
|
||
if assert.NoError(t, err) { | ||
endpoint, err := underTest.CreateEndpoint(endpoints.Endpoint{ | ||
Title: "testCreateCustomEndpoint", | ||
Method: "POST", | ||
Description: "my description", | ||
Url: "https://jsonplaceholder.typicode.com/todos/1", | ||
EndpointType: endpoints.EndpointTypeCustom, | ||
Headers: map[string]string{"hello": "there", "header": "two words"}, | ||
BodyTemplate: map[string]string{"hello": "there", "header": "two"}, | ||
}) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, endpoint) | ||
assert.Equal(t, endpointId, endpoint.Id) | ||
} | ||
} |
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
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,5 +1,3 @@ | ||
// +build integration | ||
|
||
package endpoints_test | ||
|
||
import ( | ||
|