mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-04 23:16:54 +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:
@@ -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