Files
gocryptotrader/gctscript/vm/manager_test.go
Adrian Gallagher f0d45aa1d2 golangci-lint/CI: Bump versions and introduce new linters (#798)
* golangci-lint/CI: Bump versions

Fix remaining linter issues

* Specifically set AppVeyor version

* Fix the infamous typos 👀

* Add go env cmd to AppVeyor

* Add go version cmd to AppVeyor

* Specify AppVeyor image, adjust linters

* Update go get to go install due to deprecation

* Bump golangci-lint timeout time for AppVeyor

* Change NW contract to NQ

* Address nitters

* GetRandomPair -> Pair{}

* Address nits

* Address time nitterinos plus additional tweaks

* More time inception upgrades!

* Bending time and space
2021-10-14 16:38:53 +11:00

125 lines
2.4 KiB
Go

package vm
import (
"reflect"
"sync"
"testing"
)
func TestNewManager(t *testing.T) {
t.Parallel()
type args struct {
config *Config
}
sharedConf := &Config{
AllowImports: true,
}
tests := []struct {
name string
args args
want *GctScriptManager
wantErr bool
}{
{
name: "nil config gives error",
wantErr: true,
},
{
name: "config is applied",
args: args{
config: sharedConf,
},
want: &GctScriptManager{
config: sharedConf,
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, err := NewManager(tt.args.config)
if (err != nil) != tt.wantErr {
t.Errorf("NewManager() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewManager() = %v, want %v", got, tt.want)
}
})
}
}
func TestGctScriptManagerStartStopNominal(t *testing.T) {
t.Parallel()
mgr, err := NewManager(&Config{AllowImports: true})
if err != nil {
t.Fatal(err)
}
var wg sync.WaitGroup
err = mgr.Start(&wg)
if err != nil {
t.Fatal(err)
}
if mgr.started != 1 {
t.Errorf("Manager should be started (%v)", mgr.started)
}
err = mgr.Stop()
if err != nil {
t.Fatal(err)
}
wg.Wait()
if mgr.started != 0 {
t.Errorf("Manager should be stopped, expected=%v, got %v", 0, mgr.started)
}
}
func TestGctScriptManagerGetMaxVirtualMachines(t *testing.T) {
type fields struct {
config *Config
started int32
shutdown chan struct{}
MaxVirtualMachines *uint8
}
var value uint8 = 6
tests := []struct {
name string
fields fields
want uint8
}{
{
name: "get from config",
fields: fields{
config: &Config{
MaxVirtualMachines: 7,
},
},
want: 7,
},
{
name: "get from manager",
fields: fields{
config: &Config{
MaxVirtualMachines: 7,
},
MaxVirtualMachines: &value,
},
want: 6,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
g := &GctScriptManager{
config: tt.fields.config,
started: tt.fields.started,
shutdown: tt.fields.shutdown,
MaxVirtualMachines: tt.fields.MaxVirtualMachines,
}
if got := g.GetMaxVirtualMachines(); got != tt.want {
t.Errorf("GctScriptManager.GetMaxVirtualMachines() = %v, want %v", got, tt.want)
}
})
}
}