mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
Binance: Subscribe/unsubscribe response handling (#1444)
* Binance: Fix subscription failures ignored * Testing: Fix race on shared config singleton * Config: Privatise Global config var We should *either* use a private var *or* use an accessor, but it doesn't make sense to mix paradigms. Since GetConfig() is well established this instead removes the limited uses of direct public access and adds a Setter * Zip: Fix test failure on http mocks
This commit is contained in:
@@ -3,8 +3,12 @@ package archive
|
||||
import (
|
||||
"archive/zip"
|
||||
"errors"
|
||||
"io/fs"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestUnZip(t *testing.T) {
|
||||
@@ -33,60 +37,39 @@ func TestUnZip(t *testing.T) {
|
||||
|
||||
func TestZip(t *testing.T) {
|
||||
tempDir := t.TempDir()
|
||||
singleFile := filepath.Join("..", "..", "..", "testdata", "configtest.json")
|
||||
outFile := filepath.Join(tempDir, "out.zip")
|
||||
err := Zip(singleFile, outFile)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err := Zip(filepath.Join("..", "..", "..", "testdata", "configtest.json"), outFile)
|
||||
require.NoError(t, err, "Zip should not error")
|
||||
o, err := UnZip(outFile, tempDir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(o) != 1 {
|
||||
t.Fatalf("expected 1 files to be extracted received: %v ", len(o))
|
||||
}
|
||||
require.NoError(t, err, "UnZip should not error")
|
||||
assert.Len(t, o, 1, "Should extract 1 file")
|
||||
|
||||
folder := filepath.Join("..", "..", "..", "testdata", "http_mock")
|
||||
folder := filepath.Join("..", "..", "..", "testdata", "gctscript")
|
||||
outFolderZip := filepath.Join(tempDir, "out_folder.zip")
|
||||
err = Zip(folder, outFolderZip)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, err, "Zip should not error")
|
||||
o, err = UnZip(outFolderZip, tempDir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, err, "UnZip should not error")
|
||||
var found bool
|
||||
for i := range o {
|
||||
if filepath.Base(o[i]) == "binance.json" {
|
||||
if filepath.Base(o[i]) == "timer.gct" {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatal("could not find file in zip")
|
||||
}
|
||||
|
||||
if expected := 6; len(o) < expected {
|
||||
t.Fatalf("expected at least %v files to be extracted, received: %v ", expected, len(o))
|
||||
}
|
||||
assert.True(t, found, "Should find a gctscript in the zip")
|
||||
assert.GreaterOrEqual(t, len(o), 6, "Should extract at least 6 files")
|
||||
|
||||
folder = filepath.Join("..", "..", "..", "testdata", "invalid_file.json")
|
||||
outFolderZip = filepath.Join(tempDir, "invalid.zip")
|
||||
err = Zip(folder, outFolderZip)
|
||||
if err == nil {
|
||||
t.Fatal("expected IsNotExistError on invalid file")
|
||||
}
|
||||
err = Zip(folder, filepath.Join(tempDir, "invalid.zip"))
|
||||
assert.ErrorIs(t, err, fs.ErrNotExist, "Zip should error correctly")
|
||||
|
||||
addFilesToZip = addFilesToZipTestWrapper
|
||||
folder = filepath.Join("..", "..", "..", "testdata", "http_mock")
|
||||
outFolderZip = filepath.Join(tempDir, "error_zip.zip")
|
||||
err = Zip(folder, outFolderZip)
|
||||
if err == nil {
|
||||
t.Fatal("expected Zip() to fail due to invalid addFilesToZipTestWrapper()")
|
||||
}
|
||||
assert.ErrorContains(t, err, "specific error", "Zip should error correctly")
|
||||
}
|
||||
|
||||
func addFilesToZipTestWrapper(_ *zip.Writer, _ string, _ bool) error {
|
||||
return errors.New("error")
|
||||
return errors.New("specific error")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user