From 35da3ba3a034764e6358dfa3c2bfdb99ff150d54 Mon Sep 17 00:00:00 2001 From: c9s Date: Sun, 5 Dec 2021 01:11:47 +0800 Subject: [PATCH] check env vars for query related tests --- pkg/exchange/binance/ticker_test.go | 28 +++++++++++++++++++++++++--- pkg/exchange/max/ticker_test.go | 29 ++++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/pkg/exchange/binance/ticker_test.go b/pkg/exchange/binance/ticker_test.go index 9d85de607..3bdee463c 100644 --- a/pkg/exchange/binance/ticker_test.go +++ b/pkg/exchange/binance/ticker_test.go @@ -2,13 +2,21 @@ package binance import ( "context" + "os" "testing" "github.com/stretchr/testify/assert" ) func TestExchange_QueryTickers_AllSymbols(t *testing.T) { - e := New("mock_key", "mock_secret") + key := os.Getenv("BINANCE_API_KEY") + secret := os.Getenv("BINANCE_API_SECRET") + if len(key) == 0 && len(secret) == 0 { + t.Skip("api key/secret are not configured") + return + } + + e := New(key, secret) got, err := e.QueryTickers(context.Background()) if assert.NoError(t, err) { assert.True(t, len(got) > 1, "binance: attempting to get all symbol tickers, but get 1 or less") @@ -16,7 +24,14 @@ func TestExchange_QueryTickers_AllSymbols(t *testing.T) { } func TestExchange_QueryTickers_SomeSymbols(t *testing.T) { - e := New("mock_key", "mock_secret") + key := os.Getenv("BINANCE_API_KEY") + secret := os.Getenv("BINANCE_API_SECRET") + if len(key) == 0 && len(secret) == 0 { + t.Skip("api key/secret are not configured") + return + } + + e := New(key, secret) got, err := e.QueryTickers(context.Background(), "BTCUSDT", "ETHUSDT") if assert.NoError(t, err) { assert.Len(t, got, 2, "binance: attempting to get two symbols, but number of tickers do not match") @@ -24,7 +39,14 @@ func TestExchange_QueryTickers_SomeSymbols(t *testing.T) { } func TestExchange_QueryTickers_SingleSymbol(t *testing.T) { - e := New("mock_key", "mock_secret") + key := os.Getenv("BINANCE_API_KEY") + secret := os.Getenv("BINANCE_API_SECRET") + if len(key) == 0 && len(secret) == 0 { + t.Skip("api key/secret are not configured") + return + } + + e := New(key, secret) got, err := e.QueryTickers(context.Background(), "BTCUSDT") if assert.NoError(t, err) { assert.Len(t, got, 1, "binance: attempting to get one symbol, but number of tickers do not match") diff --git a/pkg/exchange/max/ticker_test.go b/pkg/exchange/max/ticker_test.go index e0d5dab9a..68defb2f6 100644 --- a/pkg/exchange/max/ticker_test.go +++ b/pkg/exchange/max/ticker_test.go @@ -2,13 +2,21 @@ package max import ( "context" + "os" "testing" "github.com/stretchr/testify/assert" ) func TestExchange_QueryTickers_AllSymbols(t *testing.T) { - e := New("mock_key", "mock_secret") + key := os.Getenv("MAX_API_KEY") + secret := os.Getenv("MAX_API_SECRET") + if len(key) == 0 && len(secret) == 0 { + t.Skip("api key/secret are not configured") + return + } + + e := New(key, secret) got, err := e.QueryTickers(context.Background()) if assert.NoError(t, err) { assert.True(t, len(got) > 1, "max: attempting to get all symbol tickers, but get 1 or less") @@ -16,7 +24,15 @@ func TestExchange_QueryTickers_AllSymbols(t *testing.T) { } func TestExchange_QueryTickers_SomeSymbols(t *testing.T) { - e := New("mock_key", "mock_secret") + key := os.Getenv("MAX_API_KEY") + secret := os.Getenv("MAX_API_SECRET") + if len(key) == 0 && len(secret) == 0 { + t.Skip("api key/secret are not configured") + return + } + + + e := New(key, secret) got, err := e.QueryTickers(context.Background(), "BTCUSDT", "ETHUSDT") if assert.NoError(t, err) { assert.Len(t, got, 2, "max: attempting to get two symbols, but number of tickers do not match") @@ -24,7 +40,14 @@ func TestExchange_QueryTickers_SomeSymbols(t *testing.T) { } func TestExchange_QueryTickers_SingleSymbol(t *testing.T) { - e := New("mock_key", "mock_secret") + key := os.Getenv("MAX_API_KEY") + secret := os.Getenv("MAX_API_SECRET") + if len(key) == 0 && len(secret) == 0 { + t.Skip("api key/secret are not configured") + return + } + + e := New(key, secret) got, err := e.QueryTickers(context.Background(), "BTCUSDT") if assert.NoError(t, err) { assert.Len(t, got, 1, "max: attempting to get 1 symbols, but number of tickers do not match")