Skip to content

Commit c266d79

Browse files
committed
fix test bug
1 parent d25f9ba commit c266d79

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

pkg/exchange/coinbase/exchange_test.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ package coinbase
22

33
import (
44
"context"
5+
"os"
6+
"regexp"
7+
"strings"
58
"testing"
69
"time"
710

811
"github.com/stretchr/testify/assert"
912

1013
"github.com/c9s/bbgo/pkg/fixedpoint"
1114
"github.com/c9s/bbgo/pkg/testing/httptesting"
12-
"github.com/c9s/bbgo/pkg/testutil"
1315
"github.com/c9s/bbgo/pkg/types"
1416
)
1517

@@ -427,7 +429,7 @@ func TestExchange_QueryWithdrawHistory(t *testing.T) {
427429
}
428430

429431
func getExchangeOrSkip(t *testing.T) (*Exchange, func()) {
430-
key, secret, passphrase, ok := testutil.IntegrationTestWithPassphraseConfigured(t, "COINBASE")
432+
key, secret, passphrase, ok := IntegrationTestWithPassphraseConfigured(t, "COINBASE")
431433
ex := New(key, secret, passphrase, 0)
432434
isRecording, saveRecord := httptesting.RunHttpTestWithRecorder(t, ex.client.HttpClient, "testdata/"+t.Name()+".json")
433435

@@ -438,3 +440,24 @@ func getExchangeOrSkip(t *testing.T) (*Exchange, func()) {
438440

439441
return ex, saveRecord
440442
}
443+
444+
// copied from testutil, or tests for other exchanges will fail
445+
func IntegrationTestWithPassphraseConfigured(t *testing.T, prefix string) (key, secret, passphrase string, ok bool) {
446+
var hasKey, hasSecret, hasPassphrase bool
447+
448+
prefix = strings.ToUpper(prefix)
449+
key, hasKey = os.LookupEnv(prefix + "_API_KEY")
450+
secret, hasSecret = os.LookupEnv(prefix + "_API_SECRET")
451+
passphrase, hasPassphrase = os.LookupEnv(prefix + "_API_PASSPHRASE")
452+
ok = hasKey && hasSecret && hasPassphrase && os.Getenv("TEST_"+prefix) == "1"
453+
if ok {
454+
t.Logf(prefix+" api integration test enabled, key = %s, secret = %s, passphrase= %s", maskSecret(key), maskSecret(secret), maskSecret(passphrase))
455+
}
456+
return key, secret, passphrase, ok
457+
}
458+
459+
func maskSecret(s string) string {
460+
re := regexp.MustCompile(`\b(\w{4})\w+\b`)
461+
s = re.ReplaceAllString(s, "$1******")
462+
return s
463+
}

pkg/exchange/coinbase/stream_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"testing"
1010
"time"
1111

12-
"github.com/c9s/bbgo/pkg/testutil"
1312
"github.com/c9s/bbgo/pkg/types"
1413
"github.com/stretchr/testify/assert"
1514
)
@@ -378,7 +377,7 @@ func getTestStreamOrSkip(t *testing.T) *Stream {
378377
t.Skip("skip test for CI")
379378
}
380379

381-
key, secret, passphrase, ok := testutil.IntegrationTestWithPassphraseConfigured(t, "COINBASE")
380+
key, secret, passphrase, ok := IntegrationTestWithPassphraseConfigured(t, "COINBASE")
382381
if !ok {
383382
t.Skip("COINBASE_* env vars not set")
384383
}

pkg/testutil/auth.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ func IntegrationTestWithPassphraseConfigured(t *testing.T, prefix string) (key,
3434
ok = hasKey && hasSecret && hasPassphrase && os.Getenv("TEST_"+prefix) == "1"
3535
if ok {
3636
t.Logf(prefix+" api integration test enabled, key = %s, secret = %s, passphrase= %s", maskSecret(key), maskSecret(secret), maskSecret(passphrase))
37+
} else {
38+
t.Skipf(prefix + " api key is not configured, skipping integration test")
3739
}
3840

3941
return key, secret, passphrase, ok

0 commit comments

Comments
 (0)