Skip to content

Commit

Permalink
better/clearer function name
Browse files Browse the repository at this point in the history
  • Loading branch information
eikenb committed Mar 10, 2018
1 parent edb4b7f commit 68e5d2f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions request-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (rs *RequestServer) packetWorker(
handle := rs.nextRequest(request)
rpkt = sshFxpHandlePacket{pkt.id(), handle}
if pkt.hasPflags(ssh_FXF_CREAT) {
if p := request.call(rs.Handlers, pkt); !isOk(p) {
if p := request.call(rs.Handlers, pkt); !statusOk(p) {
rpkt = p // if error in write, return it
}
}
Expand Down Expand Up @@ -200,7 +200,7 @@ func (rs *RequestServer) packetWorker(
}

// True is responsePacket is an OK status packet
func isOk(rpkt responsePacket) bool {
func statusOk(rpkt responsePacket) bool {
p, ok := rpkt.(sshFxpStatusPacket)
return ok && p.StatusError.Code == ssh_FX_OK
}
Expand Down
12 changes: 8 additions & 4 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ func (h *Handlers) returnError(err error) {
handler.err = err
}

func statusOk(t *testing.T, p interface{}) {
func getStatusMsg(p interface{}) string {
pkt := p.(sshFxpStatusPacket)
return pkt.StatusError.msg
}
func checkOkStatus(t *testing.T, p interface{}) {
pkt := p.(sshFxpStatusPacket)
assert.Equal(t, pkt.StatusError.Code, uint32(ssh_FX_OK),
"sshFxpStatusPacket not OK\n", pkt.StatusError.msg)
Expand Down Expand Up @@ -153,10 +157,10 @@ func TestRequestPut(t *testing.T) {
request := testRequest("Put")
pkt := &sshFxpWritePacket{0, "a", 0, 5, []byte("file-")}
rpkt := request.call(handlers, pkt)
statusOk(t, rpkt)
checkOkStatus(t, rpkt)
pkt = &sshFxpWritePacket{1, "a", 5, 5, []byte("data.")}
rpkt = request.call(handlers, pkt)
statusOk(t, rpkt)
checkOkStatus(t, rpkt)
assert.Equal(t, "file-data.", handlers.getOutString())
}

Expand All @@ -165,7 +169,7 @@ func TestRequestCmdr(t *testing.T) {
request := testRequest("Mkdir")
pkt := fakePacket{myid: 1}
rpkt := request.call(handlers, pkt)
statusOk(t, rpkt)
checkOkStatus(t, rpkt)

handlers.returnError(errTest)
rpkt = request.call(handlers, pkt)
Expand Down

0 comments on commit 68e5d2f

Please sign in to comment.