171 lines
3.6 KiB
Go
171 lines
3.6 KiB
Go
package routes_test
|
|
|
|
import (
|
|
"fmt"
|
|
"gitea.deepak.science/deepak/gogmagog/models"
|
|
)
|
|
|
|
type multiStore struct {
|
|
actions []*models.Action
|
|
plans []*models.Plan
|
|
}
|
|
|
|
type testNotFoundError struct {
|
|
error
|
|
}
|
|
|
|
func (t *testNotFoundError) NotFound() bool {
|
|
return true
|
|
}
|
|
|
|
func (ms *multiStore) SelectActions() ([]*models.Action, error) {
|
|
return ms.actions, nil
|
|
}
|
|
|
|
func (ms *multiStore) SelectActionByID(id int) (*models.Action, error) {
|
|
if len(ms.actions) < 1 {
|
|
err := &testNotFoundError{fmt.Errorf("too small")}
|
|
return nil, err
|
|
}
|
|
return ms.actions[0], nil
|
|
}
|
|
|
|
func (ms *multiStore) InsertAction(action *models.Action) (int, error) {
|
|
return int(action.ActionID), nil
|
|
}
|
|
|
|
func (ms *multiStore) UpdateAction(action *models.Action) error {
|
|
return nil
|
|
}
|
|
|
|
func (ms *multiStore) SelectPlans() ([]*models.Plan, error) {
|
|
return ms.plans, nil
|
|
}
|
|
|
|
func (ms *multiStore) SelectPlanByID(id int) (*models.Plan, error) {
|
|
if len(ms.plans) < 1 {
|
|
err := &testNotFoundError{fmt.Errorf("too small")}
|
|
return nil, err
|
|
}
|
|
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 (ms *multiStore) ConnectionLive() error {
|
|
return nil
|
|
}
|
|
|
|
func getEmptyModel() *models.Model {
|
|
ss := &multiStore{
|
|
[]*models.Action{},
|
|
[]*models.Plan{},
|
|
}
|
|
m := models.New(ss)
|
|
return m
|
|
}
|
|
func getModel(plns []*models.Plan, acts []*models.Action) *models.Model {
|
|
ss := &multiStore{
|
|
actions: acts,
|
|
plans: plns,
|
|
}
|
|
m := models.New(ss)
|
|
return m
|
|
}
|
|
|
|
func (e *errorStore) SelectActions() ([]*models.Action, error) {
|
|
return nil, e.error
|
|
}
|
|
|
|
func (e *errorStore) SelectActionByID(id int) (*models.Action, error) {
|
|
return nil, e.error
|
|
}
|
|
|
|
func (e *errorStore) InsertAction(action *models.Action) (int, error) {
|
|
return 0, e.error
|
|
}
|
|
|
|
func (e *errorStore) UpdateAction(action *models.Action) error {
|
|
return e.error
|
|
}
|
|
|
|
func (e *errorStore) SelectPlans() ([]*models.Plan, error) {
|
|
return nil, e.error
|
|
}
|
|
|
|
func (e *errorStore) SelectPlanByID(id int) (*models.Plan, error) {
|
|
return nil, e.error
|
|
}
|
|
|
|
func (e *errorStore) InsertPlan(plan *models.Plan) (int, error) {
|
|
return 0, e.error
|
|
}
|
|
|
|
func (e *errorStore) SelectActionsByPlanID(plan *models.Plan) ([]*models.Action, error) {
|
|
return nil, e.error
|
|
}
|
|
|
|
func (e *errorStore) ConnectionLive() error {
|
|
return e.error
|
|
}
|
|
|
|
type errorStore struct {
|
|
error error
|
|
}
|
|
|
|
func getErrorModel(errorMsg string) *models.Model {
|
|
e := &errorStore{error: fmt.Errorf(errorMsg)}
|
|
return models.New(e)
|
|
}
|
|
|
|
func (e *onlyCreateStore) SelectActions() ([]*models.Action, error) {
|
|
return nil, e.error
|
|
}
|
|
|
|
func (e *onlyCreateStore) SelectActionByID(id int) (*models.Action, error) {
|
|
return nil, e.error
|
|
}
|
|
|
|
func (e *onlyCreateStore) InsertAction(action *models.Action) (int, error) {
|
|
return int(action.ActionID), nil
|
|
}
|
|
|
|
func (e *onlyCreateStore) UpdateAction(action *models.Action) error {
|
|
return nil
|
|
}
|
|
|
|
func (e *onlyCreateStore) SelectPlans() ([]*models.Plan, error) {
|
|
return nil, e.error
|
|
}
|
|
|
|
func (e *onlyCreateStore) SelectPlanByID(id int) (*models.Plan, error) {
|
|
return nil, e.error
|
|
}
|
|
|
|
func (e *onlyCreateStore) InsertPlan(plan *models.Plan) (int, error) {
|
|
return int(plan.PlanID), nil
|
|
}
|
|
|
|
func (e *onlyCreateStore) SelectActionsByPlanID(plan *models.Plan) ([]*models.Action, error) {
|
|
return nil, e.error
|
|
}
|
|
|
|
func (e *onlyCreateStore) ConnectionLive() error {
|
|
return e.error
|
|
}
|
|
|
|
type onlyCreateStore struct {
|
|
error error
|
|
}
|
|
|
|
func getErrorOnGetModel(errorMsg string) *models.Model {
|
|
e := &onlyCreateStore{error: fmt.Errorf(errorMsg)}
|
|
return models.New(e)
|
|
}
|