forked from thrasher-corp/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
173 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package subscription | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/thrasher-corp/gocryptotrader/currency" | ||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset" | ||
) | ||
|
||
func TestListStrings(t *testing.T) { | ||
l := List{ | ||
&Subscription{ | ||
Channel: TickerChannel, | ||
Asset: asset.Spot, | ||
Pairs: currency.Pairs{ethusdcPair, btcusdtPair}, | ||
}, | ||
&Subscription{ | ||
Channel: OrderbookChannel, | ||
Pairs: currency.Pairs{ethusdcPair}, | ||
}, | ||
} | ||
exp := []string{"orderbook ETH/USDC", "ticker spot ETH/USDC,BTC/USDT"} | ||
assert.ElementsMatch(t, exp, l.Strings(), "String must return correct sorted list") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package subscription | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestNewStore exercises NewStore | ||
func TestNewStore(t *testing.T) { | ||
s := NewStore() | ||
require.IsType(t, &Store{}, s, "Must return a store ref") | ||
require.NotNil(t, s.m, "storage map must be initialised") | ||
} | ||
|
||
// TestNewStoreFromList exercises NewStoreFromList | ||
func TestNewStoreFromList(t *testing.T) { | ||
s, err := NewStoreFromList(List{}) | ||
assert.NoError(t, err, "Should not error on empty list") | ||
require.IsType(t, &Store{}, s, "Must return a store ref") | ||
l := List{ | ||
{Channel: OrderbookChannel}, | ||
{Channel: TickerChannel}, | ||
} | ||
s, err = NewStoreFromList(l) | ||
assert.NoError(t, err, "Should not error on empty list") | ||
assert.Len(t, s.m, 2, "Map should have 2 values") | ||
assert.NotNil(t, s.get(l[0]), "Should be able to get a list element") | ||
|
||
l = append(l, &Subscription{Channel: OrderbookChannel}) | ||
s, err = NewStoreFromList(l) | ||
assert.ErrorIs(t, err, ErrDuplicate, "Should error correctly on duplicates") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters