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