Try and clean up a failed primary instance creation

This commit is contained in:
Marc Di Luzio 2020-06-03 12:31:52 +01:00
parent 78774329a8
commit a0657b32e7
3 changed files with 53 additions and 10 deletions

View file

@ -2,6 +2,8 @@ package game
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewWorld(t *testing.T) {
@ -24,3 +26,19 @@ func TestWorld_CreateInstance(t *testing.T) {
t.Errorf("Incorrect number of instances created")
}
}
func TestWorld_DestroyInstance(t *testing.T) {
world := NewWorld()
a := world.CreateInstance()
b := world.CreateInstance()
err := world.DestroyInstance(a)
assert.NoError(t, err, "Error returned from instance destroy")
// Basic duplicate check
if len(world.Instances) != 1 {
t.Error("Too many instances left in world")
} else if _, ok := world.Instances[b]; !ok {
t.Error("Remaining instance is incorrect")
}
}