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:
Adrian Gallagher
2025-05-28 12:26:51 +10:00
committed by GitHub
parent 1e5739dffa
commit a5b638bfb7
165 changed files with 2565 additions and 4626 deletions

View File

@@ -4,6 +4,7 @@ import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
"github.com/thrasher-corp/gocryptotrader/config"
)
@@ -15,9 +16,8 @@ func TestSetupConnectionManager(t *testing.T) {
}
m, err := setupConnectionManager(&config.ConnectionMonitorConfig{})
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
assert.NoError(t, err)
if m == nil {
t.Error("expected manager")
}
@@ -26,13 +26,11 @@ func TestSetupConnectionManager(t *testing.T) {
func TestConnectionMonitorIsRunning(t *testing.T) {
t.Parallel()
m, err := setupConnectionManager(&config.ConnectionMonitorConfig{})
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
assert.NoError(t, err)
err = m.Start()
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
assert.NoError(t, err)
if !m.IsRunning() {
t.Error("expected true")
}
@@ -49,13 +47,11 @@ func TestConnectionMonitorIsRunning(t *testing.T) {
func TestConnectionMonitorStart(t *testing.T) {
t.Parallel()
m, err := setupConnectionManager(&config.ConnectionMonitorConfig{})
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
assert.NoError(t, err)
err = m.Start()
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
assert.NoError(t, err)
err = m.Start()
if !errors.Is(err, ErrSubSystemAlreadyStarted) {
t.Errorf("error '%v', expected '%v'", err, ErrSubSystemAlreadyStarted)
@@ -74,17 +70,14 @@ func TestConnectionMonitorStop(t *testing.T) {
t.Errorf("error '%v', expected '%v'", err, errConnectionCheckerIsNil)
}
m, err := setupConnectionManager(&config.ConnectionMonitorConfig{})
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
assert.NoError(t, err)
err = m.Start()
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
assert.NoError(t, err)
err = m.Stop()
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
assert.NoError(t, err)
err = m.Stop()
if !errors.Is(err, ErrSubSystemNotStarted) {
t.Errorf("error '%v', expected '%v'", err, ErrSubSystemNotStarted)
@@ -99,13 +92,11 @@ func TestConnectionMonitorStop(t *testing.T) {
func TestConnectionMonitorIsOnline(t *testing.T) {
t.Parallel()
m, err := setupConnectionManager(&config.ConnectionMonitorConfig{})
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
assert.NoError(t, err)
err = m.Start()
if !errors.Is(err, nil) {
t.Errorf("error '%v', expected '%v'", err, nil)
}
assert.NoError(t, err)
// If someone runs this offline, who are we to fail them?
m.IsOnline()
err = m.Stop()