github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/pkg/models/stats/stats_test.go (about) 1 package stats_test 2 3 import ( 4 "testing" 5 6 "github.com/bitfinexcom/bitfinex-api-go/pkg/models/stats" 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestNewStatsFromRaw(t *testing.T) { 12 t.Run("invalid arguments", func(t *testing.T) { 13 payload := []interface{}{1573554000000} 14 15 got, err := stats.FromRaw(payload) 16 require.NotNil(t, err) 17 require.Nil(t, got) 18 }) 19 20 t.Run("valid arguments", func(t *testing.T) { 21 payload := []interface{}{1573554000000, 25957.94278561} 22 23 got, err := stats.FromRaw(payload) 24 require.Nil(t, err) 25 26 expected := &stats.Stat{ 27 Period: 1573554000000, 28 Volume: 25957.94278561, 29 } 30 assert.Equal(t, expected, got) 31 }) 32 } 33 34 func TestNewStatsSnapshotFromRaw(t *testing.T) { 35 t.Run("invalid arguments #1", func(t *testing.T) { 36 payload := []interface{}{} 37 38 got, err := stats.SnapshotFromRaw(payload) 39 require.NotNil(t, err) 40 require.Nil(t, got) 41 }) 42 43 t.Run("invalid arguments #2", func(t *testing.T) { 44 payload := []interface{}{1573554000000} 45 46 got, err := stats.SnapshotFromRaw(payload) 47 require.NotNil(t, err) 48 require.Nil(t, got) 49 }) 50 51 t.Run("valid arguments", func(t *testing.T) { 52 payload := []interface{}{ 53 []interface{}{1573554000000, 25957.94278561}, 54 []interface{}{1573553940000, 25964.29056204}, 55 } 56 57 got, err := stats.SnapshotFromRaw(payload) 58 require.Nil(t, err) 59 60 expected := []*stats.Stat{ 61 { 62 Period: 1573554000000, 63 Volume: 25957.94278561, 64 }, 65 { 66 Period: 1573553940000, 67 Volume: 25964.29056204, 68 }, 69 } 70 assert.Equal(t, expected, got) 71 }) 72 }