gogmagog/models/models_test.go
Deepak 1c3555d8b7
All checks were successful
gitea-deepak/gogmagog/pipeline/head This commit looks good
Removed multistore
2021-01-12 18:46:24 -06:00

84 lines
1.6 KiB
Go

package models_test
import (
"gitea.deepak.science/deepak/gogmagog/models"
"gitea.deepak.science/deepak/gogmagog/store"
"github.com/stretchr/testify/assert"
"testing"
)
func TestModelActions(t *testing.T) {
assert := assert.New(t)
a1 := &models.Action{ActionID: 3}
a2 := &models.Action{ActionID: 4}
p := &models.Plan{PlanID: 6}
str, _ := store.GetInMemoryStore()
str.InsertAction(a1)
str.InsertPlan(p)
m := models.New(str)
actions, err := m.Actions()
assert.Nil(err)
assert.Equal(1, len(actions))
firstAction, err := m.Action(1)
assert.Nil(err)
assert.EqualValues(1, firstAction.ActionID)
actionID, err := m.AddAction(a2)
assert.Nil(err)
assert.EqualValues(2, actionID)
err = m.SaveAction(a1)
assert.Nil(err)
}
func TestModelPlanMethods(t *testing.T) {
assert := assert.New(t)
a1 := &models.Action{ActionID: 3, PlanID: 1}
a2 := &models.Action{ActionID: 4}
p := &models.Plan{}
str, _ := store.GetInMemoryStore()
str.InsertPlan(p)
str.InsertAction(a1)
str.InsertAction(a2)
m := models.New(str)
plans, err := m.Plans()
assert.Nil(err)
assert.Equal(1, len(plans))
firstPlan, err := m.Plan(1)
assert.Nil(err)
assert.EqualValues(1, firstPlan.PlanID)
actions, err := m.GetActions(firstPlan)
assert.Nil(err)
assert.Equal(1, len(actions))
planId, err := m.AddPlan(&models.Plan{})
assert.Nil(err)
assert.EqualValues(2, planId)
}
func TestModelHealthy(t *testing.T) {
assert := assert.New(t)
str, _ := store.GetInMemoryStore()
m := models.New(str)
err := m.Healthy()
assert.Nil(err)
}
func TestNilModelUnhealthy(t *testing.T) {
assert := assert.New(t)
m := models.New(nil)
err := m.Healthy()
assert.NotNil(err)
}