mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-29 23:16:51 +00:00
* ordermanager: fix residual test issue from #917 and reduce some racey action * glorious: nits; also removed functions that weren't being used and were unexported * rm: pew * linter: fix issues * glourious: nits * credentials: fix test issue with racey racey horse basey
This commit is contained in:
@@ -212,7 +212,6 @@ func TestAreCredentialsValid(t *testing.T) {
|
||||
func TestValidateAPICredentials(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var b Base
|
||||
type tester struct {
|
||||
Key string
|
||||
Secret string
|
||||
@@ -247,7 +246,8 @@ func TestValidateAPICredentials(t *testing.T) {
|
||||
{RequiresBase64DecodeSecret: true, Secret: "aGVsbG8gd29ybGQ="},
|
||||
}
|
||||
|
||||
setupBase := func(b *Base, tData *tester) {
|
||||
setupBase := func(tData *tester) *Base {
|
||||
b := &Base{}
|
||||
b.API.SetKey(tData.Key)
|
||||
b.API.SetSecret(tData.Secret)
|
||||
b.API.SetClientID(tData.ClientID)
|
||||
@@ -257,13 +257,14 @@ func TestValidateAPICredentials(t *testing.T) {
|
||||
b.API.CredentialsValidator.RequiresPEM = tData.RequiresPEM
|
||||
b.API.CredentialsValidator.RequiresClientID = tData.RequiresClientID
|
||||
b.API.CredentialsValidator.RequiresBase64DecodeSecret = tData.RequiresBase64DecodeSecret
|
||||
return b
|
||||
}
|
||||
|
||||
for x := range testCases {
|
||||
testData := &testCases[x]
|
||||
t.Run("", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
setupBase(&b, testData)
|
||||
b := setupBase(testData)
|
||||
if err := b.ValidateAPICredentials(b.API.credentials); !errors.Is(err, testData.Expected) {
|
||||
t.Errorf("Test %d: expected: %v: got %v", x+1, testData.Expected, err)
|
||||
}
|
||||
|
||||
@@ -1554,6 +1554,7 @@ func TestGenerateInternalOrderID(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDetail_Copy(t *testing.T) {
|
||||
t.Parallel()
|
||||
d := []Detail{
|
||||
{
|
||||
Exchange: "Binance",
|
||||
@@ -1577,3 +1578,56 @@ func TestDetail_Copy(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetail_CopyToPointer(t *testing.T) {
|
||||
t.Parallel()
|
||||
d := []Detail{
|
||||
{
|
||||
Exchange: "Binance",
|
||||
},
|
||||
{
|
||||
Exchange: "Binance",
|
||||
Trades: []TradeHistory{
|
||||
{Price: 1},
|
||||
},
|
||||
},
|
||||
}
|
||||
for i := range d {
|
||||
r := d[i].CopyToPointer()
|
||||
if !reflect.DeepEqual(d[i], *r) {
|
||||
t.Errorf("[%d] Copy does not contain same elements, expected: %v\ngot:%v", i, d[i], r)
|
||||
}
|
||||
if len(d[i].Trades) > 0 {
|
||||
if &d[i].Trades[0] == &r.Trades[0] {
|
||||
t.Errorf("[%d]Trades point to the same data elements", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetail_CopyPointerOrderSlice(t *testing.T) {
|
||||
t.Parallel()
|
||||
d := []*Detail{
|
||||
{
|
||||
Exchange: "Binance",
|
||||
},
|
||||
{
|
||||
Exchange: "Binance",
|
||||
Trades: []TradeHistory{
|
||||
{Price: 1},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
sliceCopy := CopyPointerOrderSlice(d)
|
||||
for i := range sliceCopy {
|
||||
if !reflect.DeepEqual(*sliceCopy[i], *d[i]) {
|
||||
t.Errorf("[%d] Copy does not contain same elements, expected: %v\ngot:%v", i, sliceCopy[i], d[i])
|
||||
}
|
||||
if len(sliceCopy[i].Trades) > 0 {
|
||||
if &sliceCopy[i].Trades[0] == &d[i].Trades[0] {
|
||||
t.Errorf("[%d]Trades point to the same data elements", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -466,7 +466,14 @@ func (d *Detail) GenerateInternalOrderID() {
|
||||
}
|
||||
}
|
||||
|
||||
// Copy will return a copy of Detail
|
||||
// CopyToPointer will return the address of a new copy of the order Detail
|
||||
// WARNING: DO NOT DEREFERENCE USE METHOD Copy().
|
||||
func (d *Detail) CopyToPointer() *Detail {
|
||||
c := d.Copy()
|
||||
return &c
|
||||
}
|
||||
|
||||
// Copy makes a full copy of underlying details NOTE: This is Addressable.
|
||||
func (d *Detail) Copy() Detail {
|
||||
c := *d
|
||||
if len(d.Trades) > 0 {
|
||||
@@ -476,6 +483,16 @@ func (d *Detail) Copy() Detail {
|
||||
return c
|
||||
}
|
||||
|
||||
// CopyPointerOrderSlice returns a copy of all order detail and returns a slice
|
||||
// of pointers.
|
||||
func CopyPointerOrderSlice(old []*Detail) []*Detail {
|
||||
copySlice := make([]*Detail, len(old))
|
||||
for x := range old {
|
||||
copySlice[x] = old[x].CopyToPointer()
|
||||
}
|
||||
return copySlice
|
||||
}
|
||||
|
||||
// String implements the stringer interface
|
||||
func (t Type) String() string {
|
||||
switch t {
|
||||
|
||||
Reference in New Issue
Block a user