86 lines
1.8 KiB
Go
86 lines
1.8 KiB
Go
package models_test
|
|
|
|
import (
|
|
"gitea.deepak.science/deepak/gogmagog/models"
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
)
|
|
|
|
type multiStore struct {
|
|
actions []*models.Action
|
|
plans []*models.Plan
|
|
}
|
|
|
|
func (ms *multiStore) SelectActions() ([]*models.Action, error) {
|
|
return ms.actions, nil
|
|
}
|
|
|
|
func (ms *multiStore) SelectActionByID(id int) (*models.Action, error) {
|
|
return ms.actions[0], nil
|
|
}
|
|
|
|
func (ms *multiStore) SelectPlans() ([]*models.Plan, error) {
|
|
return ms.plans, nil
|
|
}
|
|
|
|
func (ms *multiStore) SelectPlanByID(id int) (*models.Plan, error) {
|
|
return ms.plans[0], nil
|
|
}
|
|
|
|
func (ms *multiStore) InsertPlan(plan *models.Plan) (int, error) {
|
|
return int(plan.PlanID), nil
|
|
}
|
|
|
|
func (ms *multiStore) SelectActionsByPlanID(plan *models.Plan) ([]*models.Action, error) {
|
|
return ms.actions, nil
|
|
}
|
|
|
|
func TestModelActions(t *testing.T) {
|
|
assert := assert.New(t)
|
|
a1 := &models.Action{ActionID: 3}
|
|
a2 := &models.Action{ActionID: 4}
|
|
p := &models.Plan{PlanID: 6}
|
|
ss := &multiStore{
|
|
[]*models.Action{a1, a2},
|
|
[]*models.Plan{p}}
|
|
m := models.New(ss)
|
|
|
|
actions, err := m.Actions()
|
|
assert.Nil(err)
|
|
assert.Equal(2, len(actions))
|
|
|
|
firstAction, err := m.Action(3)
|
|
assert.Nil(err)
|
|
assert.EqualValues(3, firstAction.ActionID)
|
|
|
|
}
|
|
|
|
func TestModelPlanMethods(t *testing.T) {
|
|
assert := assert.New(t)
|
|
a1 := &models.Action{ActionID: 3}
|
|
a2 := &models.Action{ActionID: 4}
|
|
p := &models.Plan{PlanID: 6}
|
|
|
|
ss := &multiStore{
|
|
[]*models.Action{a1, a2},
|
|
[]*models.Plan{p},
|
|
}
|
|
m := models.New(ss)
|
|
|
|
plans, err := m.Plans()
|
|
assert.Nil(err)
|
|
assert.Equal(1, len(plans))
|
|
|
|
firstPlan, err := m.Plan(6)
|
|
assert.Nil(err)
|
|
assert.EqualValues(6, firstPlan.PlanID)
|
|
|
|
actions, err := m.GetActions(firstPlan)
|
|
assert.Nil(err)
|
|
assert.Equal(2, len(actions))
|
|
|
|
planId, err := m.AddPlan(p)
|
|
assert.Nil(err)
|
|
assert.EqualValues(6, planId)
|
|
}
|