Create testNode up-front.

Theres no need to declare separate  vars for the testNode and then create it later, it can just be created up-front.
This commit is contained in:
jholdstock 2022-03-30 12:33:26 +01:00 committed by Jamie Holdstock
parent 6057c2b273
commit 5aa8f9faaf

View File

@ -136,14 +136,15 @@ func TestSetAltSignAddress(t *testing.T) {
vspClosed bool vspClosed bool
deformReq int deformReq int
addr string addr string
getRawTransactionErr error node *testNode
canTicketNotVote bool
isExistingAltSignAddr bool isExistingAltSignAddr bool
canTicketVoteErr error
wantCode int wantCode int
}{{ }{{
name: "ok", name: "ok",
addr: testAddr, addr: testAddr,
node: &testNode{
canTicketVote: true,
},
wantCode: http.StatusOK, wantCode: http.StatusOK,
}, { }, {
name: "vsp closed", name: "vsp closed",
@ -169,17 +170,23 @@ func TestSetAltSignAddress(t *testing.T) {
}, { }, {
name: "error getting raw tx from dcrd client", name: "error getting raw tx from dcrd client",
addr: testAddr, addr: testAddr,
node: &testNode{
getRawTransactionErr: errors.New("get raw transaction error"), getRawTransactionErr: errors.New("get raw transaction error"),
},
wantCode: http.StatusInternalServerError, wantCode: http.StatusInternalServerError,
}, { }, {
name: "error getting can vote from dcrd client", name: "error getting can vote from dcrd client",
addr: testAddr, addr: testAddr,
node: &testNode{
canTicketVoteErr: errors.New("can ticket vote error"), canTicketVoteErr: errors.New("can ticket vote error"),
},
wantCode: http.StatusInternalServerError, wantCode: http.StatusInternalServerError,
}, { }, {
name: "ticket can't vote", name: "ticket can't vote",
addr: testAddr, addr: testAddr,
canTicketNotVote: true, node: &testNode{
canTicketVote: false,
},
wantCode: http.StatusBadRequest, wantCode: http.StatusBadRequest,
}, { }, {
name: "hist at max", name: "hist at max",
@ -219,22 +226,16 @@ func TestSetAltSignAddress(t *testing.T) {
api.cfg.VspClosed = test.vspClosed api.cfg.VspClosed = test.vspClosed
tNode := &testNode{
canTicketVote: !test.canTicketNotVote,
canTicketVoteErr: test.canTicketVoteErr,
getRawTransactionErr: test.getRawTransactionErr,
}
w := httptest.NewRecorder() w := httptest.NewRecorder()
c, r := gin.CreateTestContext(w) c, r := gin.CreateTestContext(w)
var dcrdErr error var dcrdErr error
if test.dcrdClientErr { if test.dcrdClientErr {
tNode = nil
dcrdErr = errors.New("error") dcrdErr = errors.New("error")
} }
handle := func(c *gin.Context) { handle := func(c *gin.Context) {
c.Set(dcrdKey, tNode) c.Set(dcrdKey, test.node)
c.Set(dcrdErrorKey, dcrdErr) c.Set(dcrdErrorKey, dcrdErr)
c.Set(requestBytesKey, b[test.deformReq:]) c.Set(requestBytesKey, b[test.deformReq:])
api.setAltSignAddr(c) api.setAltSignAddr(c)