Skip to content

Commit

Permalink
Test error behavior from regular test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinav committed Apr 25, 2016
1 parent 8419a93 commit 1ca70b9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
6 changes: 5 additions & 1 deletion crossdock/client/errors/behavior.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,11 @@ func Run(s behavior.Sink, ps behavior.Params) {
"%s: response body should be informative error", tt.name)
}
if tt.wantBodyStartsWith != "" {
body := res.Body[:len(tt.wantBodyStartsWith)]
i := len(tt.wantBodyStartsWith)
if i > len(res.Body) {
i = len(res.Body)
}
body := res.Body[:i]
assert.Equal(tt.wantBodyStartsWith, body,
"%s: response body should be informative error", tt.name)
}
Expand Down
59 changes: 59 additions & 0 deletions crossdock/client/errors/behavior_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) 2016 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package errors

import (
"testing"

"github.com/yarpc/yarpc-go"
"github.com/yarpc/yarpc-go/crossdock/client/behavior"
"github.com/yarpc/yarpc-go/crossdock/server"
"github.com/yarpc/yarpc-go/encoding/json"
"github.com/yarpc/yarpc-go/transport"
"github.com/yarpc/yarpc-go/transport/http"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestRun(t *testing.T) {
rpc := yarpc.New(yarpc.Config{
Name: "yarpc-test",
Inbounds: []transport.Inbound{http.NewInbound(":8081")},
})

json.Register(rpc, json.Procedure("echo", server.EchoJSON))
json.Register(rpc, json.Procedure("unexpected-error", server.UnexpectedError))
json.Register(rpc, json.Procedure("bad-response", server.BadResponse))

require.NoError(t, rpc.Start(), "failed to start RPC server")
defer rpc.Stop()

params := behavior.ParamsFromMap{"server": "localhost"}
entries := behavior.Run(func(s behavior.Sink) {
Run(s, params)
})

for _, entry := range entries {
e := entry.(behavior.Entry)
assert.Equal(t, behavior.Passed, e.Status, e.Output)
}
}

0 comments on commit 1ca70b9

Please sign in to comment.