check env vars for query related tests

This commit is contained in:
c9s 2021-12-05 01:11:47 +08:00
parent 062f9243c6
commit 35da3ba3a0
2 changed files with 51 additions and 6 deletions

View File

@ -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")

View File

@ -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")