Skip to content

Commit

Permalink
Merge pull request #4 from brandur/stripelocal-version
Browse files Browse the repository at this point in the history
Set special `Stripelocal-Version` response header
  • Loading branch information
brandur committed Jul 26, 2017
2 parents 2eccb9f + dad9562 commit fe5f212
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ func writeResponse(w http.ResponseWriter, start time.Time, status int, data inte
return
}

w.Header().Set("Stripelocal-Version", version)

w.WriteHeader(status)
_, err = w.Write(encodedData)
if err != nil {
Expand Down
15 changes: 14 additions & 1 deletion server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ import (
assert "github.com/stretchr/testify/require"
)

func TestStubServer_SetsSpecialHeaders(t *testing.T) {
server := getStubServer(t)

// Does this regardless of endpoint
req := httptest.NewRequest("GET", "https://stripe.com/", nil)
w := httptest.NewRecorder()
server.HandleRequest(w, req)

resp := w.Result()
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
assert.Equal(t, version, resp.Header.Get("Stripelocal-Version"))
}

func TestStubServer_ParameterValidation(t *testing.T) {
server := getStubServer(t)

Expand All @@ -23,7 +36,7 @@ func TestStubServer_ParameterValidation(t *testing.T) {
assert.NoError(t, err)

assert.Contains(t, string(body), "property 'amount' is required")
assert.Equal(t, 400, resp.StatusCode)
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
}

func TestStubServer_RoutesRequest(t *testing.T) {
Expand Down

0 comments on commit fe5f212

Please sign in to comment.