Skip to content

Commit

Permalink
Misc
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Jun 15, 2016
1 parent bef5648 commit 48fcdf9
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions crossdock/client/errorstchout/behavior.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ func Run(t crossdock.T) {
{
name: "happy path",
procedure: "echo",
body: []byte{},
body: []byte("{}"),
headers: []byte("{}"),
validate: func(res3 []byte, isAppErr bool, err error) {
assert.NoError(err, "is not error")
assert.False(isAppErr, "malformed body must not be application error")
err, ok := err.(tchannel.SystemError)
assert.True(ok, "malformed body must produce system error")
Expand All @@ -76,6 +77,7 @@ func Run(t crossdock.T) {
body: []byte{},
headers: []byte("{}"),
validate: func(res3 []byte, isAppErr bool, err error) {
assert.Error(err, "is error")
assert.False(isAppErr, "missing procedure must not produce an application error")
err, ok := err.(tchannel.SystemError)
assert.True(ok, "missing procedure must produce system error")
Expand All @@ -93,6 +95,7 @@ func Run(t crossdock.T) {
body: []byte{},
headers: []byte("{}"),
validate: func(res3 []byte, isAppErr bool, err error) {
assert.Error(err, "is error")
assert.False(isAppErr, "no-such-procedure must not produce application error")
err, ok := err.(tchannel.SystemError)
assert.True(ok, "no-such-procedure must produce system error")
Expand All @@ -110,6 +113,7 @@ func Run(t crossdock.T) {
body: []byte("{}"),
headers: []byte("{}"),
validate: func(res3 []byte, isAppErr bool, err error) {
assert.Error(err, "is error")
assert.False(isAppErr, "bad-response must not produce an application error")
err, ok := err.(tchannel.SystemError)
assert.True(ok, "bad-response must produce system error")
Expand All @@ -127,6 +131,7 @@ func Run(t crossdock.T) {
body: []byte("{}"),
headers: []byte("{}"),
validate: func(res3 []byte, isAppErr bool, err error) {
assert.Error(err, "is error")
assert.False(isAppErr, "unexpected-error procedure must not produce application error")
err, ok := err.(tchannel.SystemError)
assert.True(ok, "unexpected-error procedure must produce system error")
Expand All @@ -145,42 +150,37 @@ func Run(t crossdock.T) {
peer := ch.Peers().Add(serverHostPort)

for _, tt := range tests {
(func(tt test) {
var res2, res3 []byte
var headers map[string]string

t.Tag("case", tt.name)
var res2, res3 []byte
var headers map[string]string

ctx, cancel := json.NewContext(time.Second)
defer cancel()
t.Tag("case", tt.name)
t.Tag("procedure", tt.procedure)

ctx = json.WithHeaders(ctx, headers)
ctx, cancel := json.NewContext(time.Second)
defer cancel()

as := "json"
call, err := peer.BeginCall(
ctx,
serviceName,
tt.procedure,
&tchannel.CallOptions{Format: tchannel.Format(as)},
)
fatals.NoError(err, "could not begin call")
ctx = json.WithHeaders(ctx, headers)

err = tchannel.NewArgWriter(call.Arg2Writer()).Write(tt.headers)
fatals.NoError(err, "could not write request headers")
call, err := peer.BeginCall(
ctx,
serviceName,
tt.procedure,
&tchannel.CallOptions{Format: tchannel.Format("json")},
)
fatals.NoError(err, "could not begin call")

err = tchannel.NewArgWriter(call.Arg3Writer()).Write(tt.body)
fatals.NoError(err, "could not write request body")
err = tchannel.NewArgWriter(call.Arg2Writer()).Write(tt.headers)
fatals.NoError(err, "could not write request headers")

err = tchannel.NewArgReader(call.Response().Arg2Reader()).Read(&res2)
if err != nil {
tt.validate(res3, false, err)
return
}

isAppErr := call.Response().ApplicationError()
err = tchannel.NewArgWriter(call.Arg3Writer()).Write(tt.body)
fatals.NoError(err, "could not write request body")

err = tchannel.NewArgReader(call.Response().Arg2Reader()).Read(&res2)
isAppErr := call.Response().ApplicationError()
if err != nil {
err = tchannel.NewArgReader(call.Response().Arg3Reader()).Read(&res3)
tt.validate(res3, isAppErr, err)
})(tt)
}

tt.validate(res3, isAppErr, err)
}
}

0 comments on commit 48fcdf9

Please sign in to comment.