49 lines
992 B
Go
49 lines
992 B
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 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))
|
|
|
|
plans, err := m.Plans()
|
|
assert.Nil(err)
|
|
assert.Equal(1, len(plans))
|
|
|
|
firstAction, err := m.Action(3)
|
|
assert.Nil(err)
|
|
assert.EqualValues(3, firstAction.ActionID)
|
|
}
|