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:
parent
6057c2b273
commit
5aa8f9faaf
@ -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",
|
||||||
@ -167,20 +168,26 @@ func TestSetAltSignAddress(t *testing.T) {
|
|||||||
addr: "DkM3ZigNyiwHrsXRjkDQ8t8tW6uKGW9g61qEkG3bMqQPQWYEf5X3J",
|
addr: "DkM3ZigNyiwHrsXRjkDQ8t8tW6uKGW9g61qEkG3bMqQPQWYEf5X3J",
|
||||||
wantCode: http.StatusBadRequest,
|
wantCode: http.StatusBadRequest,
|
||||||
}, {
|
}, {
|
||||||
name: "error getting raw tx from dcrd client",
|
name: "error getting raw tx from dcrd client",
|
||||||
addr: testAddr,
|
addr: testAddr,
|
||||||
getRawTransactionErr: errors.New("get raw transaction error"),
|
node: &testNode{
|
||||||
wantCode: http.StatusInternalServerError,
|
getRawTransactionErr: errors.New("get raw transaction error"),
|
||||||
|
},
|
||||||
|
wantCode: http.StatusInternalServerError,
|
||||||
}, {
|
}, {
|
||||||
name: "error getting can vote from dcrd client",
|
name: "error getting can vote from dcrd client",
|
||||||
addr: testAddr,
|
addr: testAddr,
|
||||||
canTicketVoteErr: errors.New("can ticket vote error"),
|
node: &testNode{
|
||||||
wantCode: http.StatusInternalServerError,
|
canTicketVoteErr: errors.New("can ticket vote error"),
|
||||||
|
},
|
||||||
|
wantCode: http.StatusInternalServerError,
|
||||||
}, {
|
}, {
|
||||||
name: "ticket can't vote",
|
name: "ticket can't vote",
|
||||||
addr: testAddr,
|
addr: testAddr,
|
||||||
canTicketNotVote: true,
|
node: &testNode{
|
||||||
wantCode: http.StatusBadRequest,
|
canTicketVote: false,
|
||||||
|
},
|
||||||
|
wantCode: http.StatusBadRequest,
|
||||||
}, {
|
}, {
|
||||||
name: "hist at max",
|
name: "hist at max",
|
||||||
addr: testAddr,
|
addr: testAddr,
|
||||||
@ -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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user