Skip to content
This repository has been archived by the owner on Oct 27, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into http-timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank B Greco Jr committed Aug 10, 2017
2 parents 660c6c0 + cdd9989 commit 241c2ba
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Fixed issue where Docker images were not pushed for tag builds.

## [1.0.1] - 2017-08-10
### Added
- Improved test coverage.
### Changed
Expand Down
27 changes: 24 additions & 3 deletions steps/mockplugin_test.go → steps/mockplugins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,40 @@ package steps

import (
"context"
"errors"
"net/http"

"github.com/northwesternmutual/kanali/controller"
"github.com/northwesternmutual/kanali/spec"
"github.com/opentracing/opentracing-go"
)

type fakePlugin struct{}
type fakePanicPlugin struct{}

func (plugin fakePlugin) OnRequest(ctx context.Context, p spec.APIProxy, c controller.Controller, r *http.Request, span opentracing.Span) error {
func (plugin fakePanicPlugin) OnRequest(ctx context.Context, p spec.APIProxy, c controller.Controller, r *http.Request, span opentracing.Span) error {
panic("intentional")
}

func (plugin fakePlugin) OnResponse(ctx context.Context, p spec.APIProxy, c controller.Controller, r *http.Request, resp *http.Response, span opentracing.Span) error {
func (plugin fakePanicPlugin) OnResponse(ctx context.Context, p spec.APIProxy, c controller.Controller, r *http.Request, resp *http.Response, span opentracing.Span) error {
panic("intentional")
}

type fakeSuccessPlugin struct{}

func (plugin fakeSuccessPlugin) OnRequest(ctx context.Context, p spec.APIProxy, c controller.Controller, r *http.Request, span opentracing.Span) error {
return nil
}

func (plugin fakeSuccessPlugin) OnResponse(ctx context.Context, p spec.APIProxy, c controller.Controller, r *http.Request, resp *http.Response, span opentracing.Span) error {
return nil
}

type fakeErrorPlugin struct{}

func (plugin fakeErrorPlugin) OnRequest(ctx context.Context, p spec.APIProxy, c controller.Controller, r *http.Request, span opentracing.Span) error {
return errors.New("error")
}

func (plugin fakeErrorPlugin) OnResponse(ctx context.Context, p spec.APIProxy, c controller.Controller, r *http.Request, resp *http.Response, span opentracing.Span) error {
return errors.New("error")
}
5 changes: 3 additions & 2 deletions steps/pluginsonrequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestPluginsOnRequestGetName(t *testing.T) {
}

func TestDoOnRequest(t *testing.T) {
err := doOnRequest(context.Background(), spec.APIProxy{}, controller.Controller{}, nil, opentracing.StartSpan("test span"), fakePlugin{})
assert.Equal(t, err.Error(), "OnRequest paniced")
assert.Equal(t, doOnRequest(context.Background(), spec.APIProxy{}, controller.Controller{}, nil, opentracing.StartSpan("test span"), fakePanicPlugin{}).Error(), "OnRequest paniced")
assert.Equal(t, doOnRequest(context.Background(), spec.APIProxy{}, controller.Controller{}, nil, opentracing.StartSpan("test span"), fakeErrorPlugin{}).Error(), "error")
assert.Nil(t, doOnRequest(context.Background(), spec.APIProxy{}, controller.Controller{}, nil, opentracing.StartSpan("test span"), fakeSuccessPlugin{}))
}
5 changes: 3 additions & 2 deletions steps/pluginsonresponse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestPluginsOnResponseGetName(t *testing.T) {
}

func TestDoOnResponse(t *testing.T) {
err := doOnResponse(context.Background(), spec.APIProxy{}, controller.Controller{}, nil, nil, opentracing.StartSpan("test span"), fakePlugin{})
assert.Equal(t, err.Error(), "OnResponse paniced")
assert.Equal(t, doOnResponse(context.Background(), spec.APIProxy{}, controller.Controller{}, nil, nil, opentracing.StartSpan("test span"), fakePanicPlugin{}).Error(), "OnResponse paniced")
assert.Equal(t, doOnResponse(context.Background(), spec.APIProxy{}, controller.Controller{}, nil, nil, opentracing.StartSpan("test span"), fakeErrorPlugin{}).Error(), "error")
assert.Nil(t, doOnResponse(context.Background(), spec.APIProxy{}, controller.Controller{}, nil, nil, opentracing.StartSpan("test span"), fakeSuccessPlugin{}))
}
33 changes: 31 additions & 2 deletions steps/writeresponse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,42 @@
package steps

import (
"bytes"
"context"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"

opentracing "github.com/opentracing/opentracing-go"
"github.com/stretchr/testify/assert"
)

func TestWriteResponseGetName(t *testing.T) {
assert := assert.New(t)
step := WriteResponseStep{}
assert.Equal(step.GetName(), "Write Response", "step name is incorrect")
assert.Equal(t, step.GetName(), "Write Response", "step name is incorrect")
}

func TestWriteResponseDo(t *testing.T) {
step := WriteResponseStep{}
writer := httptest.NewRecorder()
response := &httptest.ResponseRecorder{
Code: 200,
HeaderMap: http.Header{
"One": []string{"two"},
"Three": []string{"four"},
},
Body: bytes.NewBuffer([]byte("this is my mock response body")),
}
err := step.Do(context.Background(), nil, writer, nil, response.Result(), opentracing.StartSpan("test span"))
defer writer.Result().Body.Close()
assert.Nil(t, err)
assert.Equal(t, writer.Result().StatusCode, 200)
assert.Equal(t, writer.Result().Status, "OK")
assert.Equal(t, len(writer.Result().Header), 2)
assert.Equal(t, writer.Result().Header.Get("one"), "two")
assert.Equal(t, writer.Result().Header.Get("three"), "four")
bodyBytes, err := ioutil.ReadAll(writer.Result().Body)
assert.Nil(t, err)
assert.Equal(t, string(bodyBytes), "this is my mock response body")
}
2 changes: 1 addition & 1 deletion travis/build-docker-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if [[ $TRAVIS_TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "uploading docker image TAG=$TRAVIS_TAG"
export DOCKER_TAG=$TRAVIS_TAG
docker build --build-arg VERSION=$DOCKER_TAG -t $DOCKER_REPO:$DOCKER_TAG .
bash ./upload-to-docker.sh
bash ./travis/upload-to-docker.sh
elif [ $TRAVIS_PULL_REQUEST == "false" ] && [ $TRAVIS_BRANCH == "master" ]; then
echo "uploading docker image BRANCH=$TRAVIS_BRANCH"
for component in latest ${TRAVIS_COMMIT::8}
Expand Down

0 comments on commit 241c2ba

Please sign in to comment.