mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-30 15:10:40 +00:00
GHA: Add additional checks for common issues (#1922)
* GHA, tests: Add additional checks for common issues These checks include: - Ensuring that all testify funcs use their formatted variants (e.g., `assert.Equalf(t, expected, actual)` instead of `assert.Equal(t, expected, actual)`). - Replacing `%s` with %q - Enforcing consistent usage of should/must wording for testify assert/require messages * Add support for checking backticked string format specifiers and fix issues * tests: Fix error comparisons * tests: Replace errors.Is(err, nil) usage with testify and automate check * refactor: Rename ExtractPort to ExtractPortOrDefault * tests: Replace assert with require for error handling in multiple test files * tests: Replace assert with require for error handling and improve assertions in data tests * tests: Fix typo in assertion message for StreamVol test * OKX: Fix GetOpenInterestAndVolumeStrike test with instrument selection and improved assertions * OKX: Revert intentional error check * Improve error message for expiry time check in GetOpenInterestAndVolumeStrike test
This commit is contained in:
@@ -40,7 +40,7 @@ func Setup(e exchange.IBotExchange) error {
|
||||
eName := e.GetName()
|
||||
exchConf, err := cfg.GetExchangeConfig(eName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetExchangeConfig(`%s`) error: %w", eName, err)
|
||||
return fmt.Errorf("GetExchangeConfig(%q) error: %w", eName, err)
|
||||
}
|
||||
e.SetDefaults()
|
||||
b := e.GetBase()
|
||||
@@ -100,10 +100,10 @@ func MockWsInstance[T any, PT interface {
|
||||
b.SkipAuthCheck = true
|
||||
b.API.AuthenticatedWebsocketSupport = true
|
||||
err := b.API.Endpoints.SetRunning("RestSpotURL", s.URL)
|
||||
require.NoError(tb, err, "Endpoints.SetRunning should not error for RestSpotURL")
|
||||
require.NoError(tb, err, "Endpoints.SetRunning must not error for RestSpotURL")
|
||||
for _, auth := range []bool{true, false} {
|
||||
err = b.Websocket.SetWebsocketURL("ws"+strings.TrimPrefix(s.URL, "http"), auth, true)
|
||||
require.NoErrorf(tb, err, "SetWebsocketURL should not error for auth: %v", auth)
|
||||
require.NoErrorf(tb, err, "SetWebsocketURL must not error for auth: %v", auth)
|
||||
}
|
||||
|
||||
// For testing we never want to use the default subscriptions; Tests of GenerateSubscriptions should be exercising it directly
|
||||
@@ -112,7 +112,7 @@ func MockWsInstance[T any, PT interface {
|
||||
b.Websocket.GenerateSubs = func() (subscription.List, error) { return subscription.List{}, nil }
|
||||
|
||||
err = b.Websocket.Connect()
|
||||
require.NoError(tb, err, "Connect should not error")
|
||||
require.NoError(tb, err, "Connect must not error")
|
||||
|
||||
return e
|
||||
}
|
||||
@@ -138,7 +138,7 @@ func FixtureToDataHandlerWithErrors(tb testing.TB, fixturePath string, reader fu
|
||||
tb.Helper()
|
||||
|
||||
fixture, err := os.Open(fixturePath)
|
||||
require.NoError(tb, err, "Opening fixture '%s' must not error", fixturePath)
|
||||
require.NoErrorf(tb, err, "Opening fixture %q must not error", fixturePath)
|
||||
defer func() {
|
||||
assert.NoError(tb, fixture.Close(), "Closing the fixture file should not error")
|
||||
}()
|
||||
|
||||
@@ -28,7 +28,7 @@ func CurryWsMockUpgrader(tb testing.TB, wsHandler WsMockFunc) http.HandlerFunc {
|
||||
func WsMockUpgrader(tb testing.TB, w http.ResponseWriter, r *http.Request, wsHandler WsMockFunc) {
|
||||
tb.Helper()
|
||||
c, err := upgrader.Upgrade(w, r, nil)
|
||||
require.NoError(tb, err, "Upgrade connection should not error")
|
||||
require.NoError(tb, err, "Upgrade connection must not error")
|
||||
defer c.Close()
|
||||
for {
|
||||
_, p, err := c.ReadMessage()
|
||||
|
||||
Reference in New Issue
Block a user