@@ -2,14 +2,16 @@ package coinbase
22
33import (
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
429431func 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+ }
0 commit comments