From 8268ac1d32acf56b5b35f5c58a279b109b6518aa Mon Sep 17 00:00:00 2001 From: "zenix.huang" Date: Tue, 12 Mar 2024 17:48:55 +0900 Subject: [PATCH] fix: skip test when run in github action --- .github/workflows/go.yml | 1 + pkg/exchange/binance/exchange_test.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index aabc3cfc6..a4e40e5c2 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -20,6 +20,7 @@ jobs: go-version: - "1.20" env: + GITHUB_CI: true MYSQL_DATABASE: bbgo MYSQL_USER: "root" MYSQL_PASSWORD: "root" # pragma: allowlist secret diff --git a/pkg/exchange/binance/exchange_test.go b/pkg/exchange/binance/exchange_test.go index e757d883c..79ffe7b8c 100644 --- a/pkg/exchange/binance/exchange_test.go +++ b/pkg/exchange/binance/exchange_test.go @@ -2,6 +2,7 @@ package binance import ( "context" + "os" "strings" "testing" @@ -22,6 +23,12 @@ func Test_new(t *testing.T) { assert.NotEmpty(t, ex) ctx := context.Background() ticker, err := ex.QueryTicker(ctx, "btcusdt") - assert.NotEmpty(t, ticker) - assert.NoError(t, err) + if len(os.Getenv("GITHUB_CI")) > 0 { + // Github action runs in the US, and therefore binance api is not accessible + assert.Empty(t, ticker) + assert.Error(t, err) + } else { + assert.NotEmpty(t, ticker) + assert.NoError(t, err) + } }