github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/pkg/models/status/liquidations_test.go (about) 1 package status_test 2 3 import ( 4 "testing" 5 6 "github.com/bitfinexcom/bitfinex-api-go/pkg/models/status" 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestLiqFromRaw(t *testing.T) { 11 testCases := map[string]struct { 12 data []interface{} 13 err func(*testing.T, error) 14 success func(*testing.T, interface{}) 15 }{ 16 "empty pld": { 17 data: []interface{}{}, 18 err: func(t *testing.T, got error) { 19 assert.Error(t, got) 20 }, 21 success: func(t *testing.T, got interface{}) { 22 assert.Nil(t, got) 23 }, 24 }, 25 "invalid pld": { 26 data: []interface{}{1}, 27 err: func(t *testing.T, got error) { 28 assert.Error(t, got) 29 }, 30 success: func(t *testing.T, got interface{}) { 31 assert.Nil(t, got) 32 }, 33 }, 34 "valid pld": { 35 data: []interface{}{ 36 "pos", 145400868, 1609144352338, nil, "tETHF0:USTF0", 37 -1.67288094, 730.96, nil, 1, 1, nil, 736.13, 38 }, 39 err: func(t *testing.T, got error) { 40 assert.Nil(t, got) 41 }, 42 success: func(t *testing.T, got interface{}) { 43 assert.Equal(t, got, &status.Liquidation{ 44 Symbol: "tETHF0:USTF0", 45 PositionID: 145400868, 46 MTS: 1609144352338, 47 Amount: -1.67288094, 48 BasePrice: 730.96, 49 IsMatch: 1, 50 IsMarketSold: 1, 51 PriceAcquired: 736.13, 52 }) 53 }, 54 }, 55 } 56 57 for k, v := range testCases { 58 t.Run(k, func(t *testing.T) { 59 got, err := status.LiqFromRaw(v.data) 60 v.err(t, err) 61 v.success(t, got) 62 }) 63 } 64 } 65 66 func TestLiqSnapshotFromRaw(t *testing.T) { 67 testCases := map[string]struct { 68 data [][]interface{} 69 err func(*testing.T, error) 70 success func(*testing.T, interface{}) 71 }{ 72 "empty slice": { 73 data: [][]interface{}{}, 74 err: func(t *testing.T, got error) { 75 assert.Error(t, got) 76 }, 77 success: func(t *testing.T, got interface{}) { 78 assert.Nil(t, got) 79 }, 80 }, 81 "invalid pld": { 82 data: [][]interface{}{{1}}, 83 err: func(t *testing.T, got error) { 84 assert.Error(t, got) 85 }, 86 success: func(t *testing.T, got interface{}) { 87 assert.Nil(t, got) 88 }, 89 }, 90 "valid pld": { 91 data: [][]interface{}{ 92 { 93 "pos", 145400868, 1609144352338, nil, "tETHF0:USTF0", 94 -1.67288094, 730.96, nil, 1, 1, nil, 736.13, 95 }, 96 { 97 "pos", 145400869, 1609144352338, nil, "tETHF0:USTF0", 98 -1.67288094, 730.96, nil, 1, 1, nil, 736.13, nil, 1000, 99 }, 100 }, 101 err: func(t *testing.T, got error) { 102 assert.Nil(t, got) 103 }, 104 success: func(t *testing.T, got interface{}) { 105 assert.Equal(t, got, &status.LiquidationsSnapshot{ 106 Snapshot: []*status.Liquidation{ 107 { 108 Symbol: "tETHF0:USTF0", 109 PositionID: 145400868, 110 MTS: 1609144352338, 111 Amount: -1.67288094, 112 BasePrice: 730.96, 113 IsMatch: 1, 114 IsMarketSold: 1, 115 PriceAcquired: 736.13, 116 }, 117 { 118 Symbol: "tETHF0:USTF0", 119 PositionID: 145400869, 120 MTS: 1609144352338, 121 Amount: -1.67288094, 122 BasePrice: 730.96, 123 IsMatch: 1, 124 IsMarketSold: 1, 125 PriceAcquired: 736.13, 126 }, 127 }, 128 }) 129 }, 130 }, 131 } 132 133 for k, v := range testCases { 134 t.Run(k, func(t *testing.T) { 135 got, err := status.LiqSnapshotFromRaw(v.data) 136 v.err(t, err) 137 v.success(t, got) 138 }) 139 } 140 }