mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-03 07:26:45 +00:00
CI: Fix golangci-lint linter issues, add prealloc linter and bump version depends for Go 1.18 (#915)
* Bump CI versions * Specifically set go version as 1.17.x bumps it to 1.18 * Another * Adjust AppVeyor * Part 1 of linter issues * Part 2 * Fix various linters and improvements * Part 3 * Finishing touches * Tests and EqualFold * Fix nitterinos plus bonus requester jobs bump for exchanges with large number of tests * Fix nitterinos and bump golangci-lint timeout for AppVeyor * Address nits, ensure all books are returned on err due to syncer regression * Fix the wiggins * Fix duplication * Fix nitterinos
This commit is contained in:
25
common/cache/cache_test.go
vendored
25
common/cache/cache_test.go
vendored
@@ -2,6 +2,8 @@ package cache
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common/convert"
|
||||
)
|
||||
|
||||
func TestCache(t *testing.T) {
|
||||
@@ -16,12 +18,11 @@ func TestCache(t *testing.T) {
|
||||
if v == nil {
|
||||
t.Fatal("expected cache to contain \"hello\" key")
|
||||
}
|
||||
if v.(string) != "world" {
|
||||
if convert.InterfaceToStringOrZeroValue(v) != "world" {
|
||||
t.Fatal("expected \"hello\" key to contain value \"world\"")
|
||||
}
|
||||
|
||||
r := lruCache.Remove("hello")
|
||||
if !r {
|
||||
if r := lruCache.Remove("hello"); !r {
|
||||
t.Fatal("expected \"hello\" key to be removed from cache")
|
||||
}
|
||||
|
||||
@@ -77,39 +78,39 @@ func TestAdd(t *testing.T) {
|
||||
if v == nil {
|
||||
t.Fatal("expected cache to contain \"2\" key")
|
||||
}
|
||||
if v.(int) != 2 {
|
||||
if convert.InterfaceToIntOrZeroValue(v) != 2 {
|
||||
t.Fatal("expected \"2\" key to contain value \"2\"")
|
||||
}
|
||||
k, v := lruCache.getNewest()
|
||||
if k.(int) != 2 {
|
||||
if convert.InterfaceToIntOrZeroValue(k) != 2 {
|
||||
t.Fatal("expected latest key to be 2")
|
||||
}
|
||||
if v.(int) != 2 {
|
||||
if convert.InterfaceToIntOrZeroValue(v) != 2 {
|
||||
t.Fatal("expected latest value to be 2")
|
||||
}
|
||||
lruCache.Add(3, 3)
|
||||
k, _ = lruCache.getNewest()
|
||||
if k.(int) != 3 {
|
||||
if convert.InterfaceToIntOrZeroValue(k) != 3 {
|
||||
t.Fatal("expected latest key to be 3")
|
||||
}
|
||||
k, _ = lruCache.getOldest()
|
||||
if k.(int) != 2 {
|
||||
if convert.InterfaceToIntOrZeroValue(k) != 2 {
|
||||
t.Fatal("expected oldest key to be 2")
|
||||
}
|
||||
k, v = lruCache.getOldest()
|
||||
if k.(int) != 2 {
|
||||
if convert.InterfaceToIntOrZeroValue(k) != 2 {
|
||||
t.Fatal("expected oldest key to be 2")
|
||||
}
|
||||
if v.(int) != 2 {
|
||||
if convert.InterfaceToIntOrZeroValue(v) != 2 {
|
||||
t.Fatal("expected latest value to be 2")
|
||||
}
|
||||
lruCache.Add(2, 2)
|
||||
k, _ = lruCache.getNewest()
|
||||
if k.(int) != 2 {
|
||||
if convert.InterfaceToIntOrZeroValue(k) != 2 {
|
||||
t.Fatal("expected latest key to be 2")
|
||||
}
|
||||
k, _ = lruCache.getOldest()
|
||||
if k.(int) != 3 {
|
||||
if convert.InterfaceToIntOrZeroValue(k) != 3 {
|
||||
t.Fatal("expected oldest key to be 3")
|
||||
}
|
||||
}
|
||||
|
||||
20
common/cache/lru.go
vendored
20
common/cache/lru.go
vendored
@@ -24,7 +24,9 @@ func NewLRUCache(capacity uint64) *LRU {
|
||||
func (l *LRU) Add(key, value interface{}) {
|
||||
if f, o := l.items[key]; o {
|
||||
l.l.MoveToFront(f)
|
||||
f.Value.(*item).value = value
|
||||
if v, ok := f.Value.(*item); ok {
|
||||
v.value = value
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -40,7 +42,9 @@ func (l *LRU) Add(key, value interface{}) {
|
||||
func (l *LRU) Get(key interface{}) interface{} {
|
||||
if i, f := l.items[key]; f {
|
||||
l.l.MoveToFront(i)
|
||||
return i.Value.(*item).value
|
||||
if v, ok := i.Value.(*item); ok {
|
||||
return v.value
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -48,7 +52,9 @@ func (l *LRU) Get(key interface{}) interface{} {
|
||||
// GetOldest returns the oldest entry
|
||||
func (l *LRU) getOldest() (key, value interface{}) {
|
||||
if x := l.l.Back(); x != nil {
|
||||
return x.Value.(*item).key, x.Value.(*item).value
|
||||
if v, ok := x.Value.(*item); ok {
|
||||
return v.key, v.value
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -56,7 +62,9 @@ func (l *LRU) getOldest() (key, value interface{}) {
|
||||
// GetNewest returns the newest entry
|
||||
func (l *LRU) getNewest() (key, value interface{}) {
|
||||
if x := l.l.Front(); x != nil {
|
||||
return x.Value.(*item).key, x.Value.(*item).value
|
||||
if v, ok := x.Value.(*item); ok {
|
||||
return v.key, v.value
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -99,5 +107,7 @@ func (l *LRU) removeOldestEntry() {
|
||||
// removeElement element from the cache
|
||||
func (l *LRU) removeElement(e *list.Element) {
|
||||
l.l.Remove(e)
|
||||
delete(l.items, e.Value.(*item).key)
|
||||
if v, ok := e.Value.(*item); ok {
|
||||
delete(l.items, v.key)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user