Compare commits
4 Commits
169afed5c9
...
4708a2b8ff
| Author | SHA1 | Date | |
|---|---|---|---|
|
4708a2b8ff
|
|||
|
4989848335
|
|||
|
d02d48e7c8
|
|||
|
2a3d789292
|
@@ -8,6 +8,7 @@ import (
|
||||
type Plan struct {
|
||||
PlanID int64 `json:"plan_id"`
|
||||
PlanDate *time.Time `json:"plan_date"`
|
||||
UserID int64 `json:"user_id"`
|
||||
}
|
||||
|
||||
// Plans returns all plans in the model.
|
||||
|
||||
@@ -79,7 +79,8 @@ func postPlanFunc(m *models.Model) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
plan := &models.Plan{PlanDate: p.PlanDate}
|
||||
// Map the fields we allow to be set to the plan to be created.
|
||||
plan := &models.Plan{PlanDate: p.PlanDate, UserID: p.UserID}
|
||||
id, err := m.AddPlan(plan)
|
||||
if err != nil {
|
||||
serverError(w, err)
|
||||
|
||||
@@ -37,7 +37,7 @@ func TestOnePlan(t *testing.T) {
|
||||
// set up
|
||||
assert := assert.New(t)
|
||||
planDate, _ := time.Parse("2006-01-02", "2021-01-01")
|
||||
p := &models.Plan{PlanID: 6, PlanDate: &planDate}
|
||||
p := &models.Plan{PlanID: 6, PlanDate: &planDate, UserID: 3}
|
||||
m := getEmptyModel()
|
||||
m.AddPlan(p)
|
||||
router := routes.NewPlanRouter(m)
|
||||
@@ -55,7 +55,8 @@ func TestOnePlan(t *testing.T) {
|
||||
expected := `[
|
||||
{
|
||||
"plan_id": 1,
|
||||
"plan_date": "2021-01-01T00:00:00Z"
|
||||
"plan_date": "2021-01-01T00:00:00Z",
|
||||
"user_id": 3
|
||||
}
|
||||
]`
|
||||
assert.JSONEq(expected, rr.Body.String())
|
||||
@@ -109,7 +110,7 @@ func TestOnePlanByID(t *testing.T) {
|
||||
// set up
|
||||
assert := assert.New(t)
|
||||
planDate, _ := time.Parse("2006-01-02", "2021-01-01")
|
||||
p := &models.Plan{PlanID: 6, PlanDate: &planDate}
|
||||
p := &models.Plan{PlanID: 6, PlanDate: &planDate, UserID: 3}
|
||||
m := getEmptyModel()
|
||||
m.AddPlan(p)
|
||||
router := routes.NewPlanRouter(m)
|
||||
@@ -126,7 +127,8 @@ func TestOnePlanByID(t *testing.T) {
|
||||
// We pass in the date as a time.time so it makes sense that it comes back with a midnight timestamp.
|
||||
expected := `{
|
||||
"plan_id": 1,
|
||||
"plan_date": "2021-01-01T00:00:00Z"
|
||||
"plan_date": "2021-01-01T00:00:00Z",
|
||||
"user_id": 3
|
||||
}`
|
||||
assert.JSONEq(expected, rr.Body.String())
|
||||
contentType := rr.Header().Get("Content-Type")
|
||||
|
||||
@@ -17,7 +17,7 @@ func TestCreatePlanRoute(t *testing.T) {
|
||||
// set up
|
||||
assert := assert.New(t)
|
||||
planDate, _ := time.Parse("2006-01-02", "2021-01-01")
|
||||
p := &models.Plan{PlanID: 6, PlanDate: &planDate}
|
||||
p := &models.Plan{PlanID: 6, PlanDate: &planDate, UserID: 3}
|
||||
m := getEmptyModel()
|
||||
m.AddPlan(p)
|
||||
router := routes.NewPlanRouter(m)
|
||||
@@ -36,7 +36,8 @@ func TestCreatePlanRoute(t *testing.T) {
|
||||
expected := `{
|
||||
"created_plan": {
|
||||
"plan_id": 2,
|
||||
"plan_date": "2021-01-01T00:00:00Z"
|
||||
"plan_date": "2021-01-01T00:00:00Z",
|
||||
"user_id": 3
|
||||
},
|
||||
"id": 2
|
||||
}`
|
||||
@@ -49,13 +50,14 @@ func TestPureJSON(t *testing.T) {
|
||||
// set up
|
||||
assert := assert.New(t)
|
||||
planDate, _ := time.Parse("2006-01-02", "2021-01-01")
|
||||
p := &models.Plan{PlanID: 1, PlanDate: &planDate}
|
||||
p := &models.Plan{PlanID: 1, PlanDate: &planDate, UserID: 3}
|
||||
m := getEmptyModel()
|
||||
m.AddPlan(p)
|
||||
router := routes.NewPlanRouter(m)
|
||||
data := []byte(`{
|
||||
"plan_date": "2021-01-01T00:00:00Z",
|
||||
"plan_id": 1
|
||||
"plan_id": 1,
|
||||
"user_id": 3
|
||||
}`)
|
||||
req, _ := http.NewRequest("POST", "/", bytes.NewBuffer(data))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
@@ -71,6 +73,7 @@ func TestPureJSON(t *testing.T) {
|
||||
expected := `{
|
||||
"created_plan": {
|
||||
"plan_id": 2,
|
||||
"user_id": 3,
|
||||
"plan_date": "2021-01-01T00:00:00Z"
|
||||
},
|
||||
"id": 2
|
||||
|
||||
@@ -21,7 +21,10 @@ func (e *errorStore) InsertAction(action *models.Action) (int, error) {
|
||||
}
|
||||
|
||||
func (e *errorStore) UpdateAction(action *models.Action) error {
|
||||
return e.error
|
||||
if e.errorOnInsert {
|
||||
return e.error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *errorStore) SelectPlans() ([]*models.Plan, error) {
|
||||
|
||||
@@ -31,6 +31,8 @@ func TestErrorActionMethods(t *testing.T) {
|
||||
replacementAction := &models.Action{}
|
||||
err = str.UpdateAction(replacementAction)
|
||||
assert.NotNil(err)
|
||||
err = str2.UpdateAction(replacementAction)
|
||||
assert.Nil(err)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
CREATE TABLE IF NOT EXISTS users(
|
||||
user_id serial PRIMARY KEY,
|
||||
username VARCHAR(50) NOT NULL UNIQUE,
|
||||
display_name VARCHAR (100) NOT NULL,
|
||||
password bytea,
|
||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS plans(
|
||||
plan_id serial PRIMARY KEY,
|
||||
plan_date DATE NOT NULL,
|
||||
user_id int REFERENCES users(user_id),
|
||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL
|
||||
);
|
||||
@@ -16,16 +26,6 @@ CREATE TABLE IF NOT EXISTS actions(
|
||||
plan_id int REFERENCES plans(plan_id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS users(
|
||||
user_id serial PRIMARY KEY,
|
||||
username VARCHAR(50) NOT NULL UNIQUE,
|
||||
display_name VARCHAR (100) NOT NULL,
|
||||
password bytea,
|
||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL
|
||||
);
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION trigger_set_timestamp()
|
||||
RETURNS TRIGGER AS $set_updated$
|
||||
BEGIN
|
||||
|
||||
@@ -99,7 +99,7 @@ func (store *postgresStore) UpdateAction(action *models.Action) error {
|
||||
|
||||
func (store *postgresStore) SelectPlans() ([]*models.Plan, error) {
|
||||
plans := make([]*models.Plan, 0)
|
||||
err := store.db.Select(&plans, "SELECT plan_id, plan_date FROM plans")
|
||||
err := store.db.Select(&plans, "SELECT plan_id, plan_date, user_id FROM plans")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func (store *postgresStore) SelectPlans() ([]*models.Plan, error) {
|
||||
|
||||
func (store *postgresStore) SelectPlanByID(id int) (*models.Plan, error) {
|
||||
plan := models.Plan{}
|
||||
err := store.db.Get(&plan, store.db.Rebind("SELECT plan_id, plan_date FROM plans WHERE plan_id = ?"), id)
|
||||
err := store.db.Get(&plan, store.db.Rebind("SELECT plan_id, plan_date, user_id FROM plans WHERE plan_id = ?"), id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -116,10 +116,10 @@ func (store *postgresStore) SelectPlanByID(id int) (*models.Plan, error) {
|
||||
}
|
||||
|
||||
func (store *postgresStore) InsertPlan(plan *models.Plan) (int, error) {
|
||||
queryString := store.db.Rebind("INSERT INTO plans (plan_date) VALUES (?) RETURNING plan_id")
|
||||
queryString := store.db.Rebind("INSERT INTO plans (plan_date, user_id) VALUES (?, ?) RETURNING plan_id")
|
||||
tx := store.db.MustBegin()
|
||||
var id int
|
||||
err := tx.Get(&id, queryString, plan.PlanDate)
|
||||
err := tx.Get(&id, queryString, plan.PlanDate, plan.UserID)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return -1, err
|
||||
|
||||
176
store/postgres_plan_test.go
Normal file
176
store/postgres_plan_test.go
Normal file
@@ -0,0 +1,176 @@
|
||||
package store_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gitea.deepak.science/deepak/gogmagog/models"
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestSelectPlans(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
currentTime := time.Now()
|
||||
idToUse := 1
|
||||
userIDToUse := 2
|
||||
|
||||
str, mock := getDbMock(t)
|
||||
|
||||
rows := sqlmock.NewRows([]string{"plan_id", "plan_date", "user_id"}).AddRow(idToUse, currentTime, userIDToUse)
|
||||
mock.ExpectQuery("^SELECT plan_id, plan_date, user_id FROM plans$").WillReturnRows(rows)
|
||||
|
||||
plans, err := str.SelectPlans()
|
||||
assert.Nil(err)
|
||||
assert.Equal(1, len(plans))
|
||||
plan := plans[0]
|
||||
assert.EqualValues(idToUse, plan.PlanID)
|
||||
assert.Equal(currentTime, *plan.PlanDate)
|
||||
assert.EqualValues(userIDToUse, plan.UserID)
|
||||
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("unfulfilled expectations: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectPlanByID(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
currentTime := time.Now()
|
||||
idToUse := 1
|
||||
userIDToUse := 2
|
||||
|
||||
str, mock := getDbMock(t)
|
||||
|
||||
rows := sqlmock.NewRows([]string{"plan_id", "plan_date", "user_id"}).AddRow(idToUse, currentTime, userIDToUse)
|
||||
mock.ExpectQuery("^SELECT plan_id, plan_date, user_id FROM plans WHERE plan_id = \\$1$").WithArgs(idToUse).WillReturnRows(rows)
|
||||
|
||||
plan, err := str.SelectPlanByID(idToUse)
|
||||
assert.Nil(err)
|
||||
assert.EqualValues(idToUse, plan.PlanID)
|
||||
assert.Equal(currentTime, *plan.PlanDate)
|
||||
assert.EqualValues(userIDToUse, plan.UserID)
|
||||
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("unfulfilled expectations: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInsertPlan(t *testing.T) {
|
||||
// setup
|
||||
assert := assert.New(t)
|
||||
|
||||
str, mock := getDbMock(t)
|
||||
planDate, _ := time.Parse("2006-01-02", "2021-01-01")
|
||||
userID := 2
|
||||
|
||||
plan := &models.Plan{PlanDate: &planDate, UserID: int64(userID)}
|
||||
|
||||
idToUse := 8
|
||||
|
||||
rows := sqlmock.NewRows([]string{"plan_id"}).AddRow(8)
|
||||
|
||||
mock.ExpectBegin()
|
||||
mock.ExpectQuery(`^INSERT INTO plans \(plan_date, user_id\) VALUES \(\$1, \$2\) RETURNING plan_id$`).
|
||||
WithArgs(planDate, userID).
|
||||
WillReturnRows(rows)
|
||||
mock.ExpectCommit()
|
||||
|
||||
// function under test
|
||||
insertedId, err := str.InsertPlan(plan)
|
||||
// check results
|
||||
assert.Nil(err)
|
||||
assert.EqualValues(idToUse, insertedId)
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("unfulfilled expectations: %s", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestInsertPlanErr(t *testing.T) {
|
||||
// setup
|
||||
assert := assert.New(t)
|
||||
|
||||
str, mock := getDbMock(t)
|
||||
planDate, _ := time.Parse("2006-01-02", "2021-01-01")
|
||||
userID := 2
|
||||
plan := &models.Plan{PlanDate: &planDate, UserID: 2}
|
||||
|
||||
mock.ExpectBegin()
|
||||
mock.ExpectQuery(`^INSERT INTO plans \(plan_date, user_id\) VALUES \(\$1, \$2\) RETURNING plan_id$`).
|
||||
WithArgs(planDate, userID).
|
||||
WillReturnError(fmt.Errorf("example error"))
|
||||
mock.ExpectRollback()
|
||||
|
||||
// function under test
|
||||
_, err := str.InsertPlan(plan)
|
||||
// check results
|
||||
assert.NotNil(err)
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("unfulfilled expectations: %s", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestInsertPlanCommitErr(t *testing.T) {
|
||||
// setup
|
||||
assert := assert.New(t)
|
||||
|
||||
str, mock := getDbMock(t)
|
||||
planDate, _ := time.Parse("2006-01-02", "2021-01-01")
|
||||
userID := 2
|
||||
plan := &models.Plan{PlanDate: &planDate, UserID: int64(userID)}
|
||||
idToUse := 8
|
||||
|
||||
rows := sqlmock.NewRows([]string{"plan_id"}).AddRow(idToUse)
|
||||
|
||||
mock.ExpectBegin()
|
||||
mock.ExpectQuery(`^INSERT INTO plans \(plan_date, user_id\) VALUES \(\$1, \$2\) RETURNING plan_id$`).
|
||||
WithArgs(planDate, userID).
|
||||
WillReturnRows(rows)
|
||||
mock.ExpectCommit().WillReturnError(fmt.Errorf("another error example"))
|
||||
|
||||
// function under test
|
||||
_, err := str.InsertPlan(plan)
|
||||
// check results
|
||||
assert.NotNil(err)
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("unfulfilled expectations: %s", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestErrPlanByID(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
idToUse := 1
|
||||
|
||||
str, mock := getDbMock(t)
|
||||
|
||||
mock.ExpectQuery(`^SELECT plan_id, plan_date, user_id FROM plans WHERE plan_id = \$1$`).WithArgs(idToUse).WillReturnError(fmt.Errorf("example error"))
|
||||
|
||||
plan, err := str.SelectPlanByID(idToUse)
|
||||
assert.NotNil(err)
|
||||
assert.Nil(plan)
|
||||
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("unfulfilled expectations: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestErrPlans(t *testing.T) {
|
||||
// set up tests
|
||||
assert := assert.New(t)
|
||||
str, mock := getDbMock(t)
|
||||
|
||||
mock.ExpectQuery(`^SELECT plan_id, plan_date, user_id FROM plans$`).WillReturnError(fmt.Errorf("example error"))
|
||||
// function under test
|
||||
plans, err := str.SelectPlans()
|
||||
// test results
|
||||
assert.Nil(plans)
|
||||
assert.NotNil(err)
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("unfulfilled expectations: %s", err)
|
||||
}
|
||||
}
|
||||
@@ -24,149 +24,6 @@ func getDbMock(t *testing.T) (models.Store, sqlmock.Sqlmock) {
|
||||
return str, mock
|
||||
}
|
||||
|
||||
func TestSelectPlans(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
currentTime := time.Now()
|
||||
idToUse := 1
|
||||
|
||||
str, mock := getDbMock(t)
|
||||
|
||||
rows := sqlmock.NewRows([]string{"plan_id", "plan_date"}).AddRow(idToUse, currentTime)
|
||||
mock.ExpectQuery("^SELECT plan_id, plan_date FROM plans$").WillReturnRows(rows)
|
||||
|
||||
plans, err := str.SelectPlans()
|
||||
assert.Nil(err)
|
||||
assert.Equal(1, len(plans))
|
||||
plan := plans[0]
|
||||
assert.EqualValues(idToUse, plan.PlanID)
|
||||
assert.Equal(currentTime, *plan.PlanDate)
|
||||
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("unfulfilled expectations: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectPlanByID(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
currentTime := time.Now()
|
||||
idToUse := 1
|
||||
|
||||
str, mock := getDbMock(t)
|
||||
|
||||
rows := sqlmock.NewRows([]string{"plan_id", "plan_date"}).AddRow(idToUse, currentTime)
|
||||
mock.ExpectQuery("^SELECT plan_id, plan_date FROM plans WHERE plan_id = \\$1$").WithArgs(idToUse).WillReturnRows(rows)
|
||||
|
||||
plan, err := str.SelectPlanByID(idToUse)
|
||||
assert.Nil(err)
|
||||
assert.EqualValues(idToUse, plan.PlanID)
|
||||
assert.Equal(currentTime, *plan.PlanDate)
|
||||
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("unfulfilled expectations: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInsertPlan(t *testing.T) {
|
||||
// setup
|
||||
assert := assert.New(t)
|
||||
|
||||
str, mock := getDbMock(t)
|
||||
planDate, _ := time.Parse("2006-01-02", "2021-01-01")
|
||||
plan := &models.Plan{PlanDate: &planDate}
|
||||
|
||||
idToUse := 8
|
||||
|
||||
rows := sqlmock.NewRows([]string{"plan_id"}).AddRow(8)
|
||||
|
||||
mock.ExpectBegin()
|
||||
mock.ExpectQuery("^INSERT INTO plans \\(plan_date\\) VALUES \\(\\$1\\) RETURNING plan_id$").
|
||||
WithArgs(planDate).
|
||||
WillReturnRows(rows)
|
||||
mock.ExpectCommit()
|
||||
|
||||
// function under test
|
||||
insertedId, err := str.InsertPlan(plan)
|
||||
// check results
|
||||
assert.Nil(err)
|
||||
assert.EqualValues(idToUse, insertedId)
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("unfulfilled expectations: %s", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestInsertPlanErr(t *testing.T) {
|
||||
// setup
|
||||
assert := assert.New(t)
|
||||
|
||||
str, mock := getDbMock(t)
|
||||
planDate, _ := time.Parse("2006-01-02", "2021-01-01")
|
||||
plan := &models.Plan{PlanDate: &planDate}
|
||||
|
||||
mock.ExpectBegin()
|
||||
mock.ExpectQuery("^INSERT INTO plans \\(plan_date\\) VALUES \\(\\$1\\) RETURNING plan_id$").
|
||||
WithArgs(planDate).
|
||||
WillReturnError(fmt.Errorf("example error"))
|
||||
mock.ExpectRollback()
|
||||
|
||||
// function under test
|
||||
_, err := str.InsertPlan(plan)
|
||||
// check results
|
||||
assert.NotNil(err)
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("unfulfilled expectations: %s", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestInsertPlanCommitErr(t *testing.T) {
|
||||
// setup
|
||||
assert := assert.New(t)
|
||||
|
||||
str, mock := getDbMock(t)
|
||||
planDate, _ := time.Parse("2006-01-02", "2021-01-01")
|
||||
plan := &models.Plan{PlanDate: &planDate}
|
||||
|
||||
idToUse := 8
|
||||
|
||||
rows := sqlmock.NewRows([]string{"plan_id"}).AddRow(idToUse)
|
||||
|
||||
mock.ExpectBegin()
|
||||
mock.ExpectQuery("^INSERT INTO plans \\(plan_date\\) VALUES \\(\\$1\\) RETURNING plan_id$").
|
||||
WithArgs(planDate).
|
||||
WillReturnRows(rows)
|
||||
mock.ExpectCommit().WillReturnError(fmt.Errorf("another error example"))
|
||||
|
||||
// function under test
|
||||
_, err := str.InsertPlan(plan)
|
||||
// check results
|
||||
assert.NotNil(err)
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("unfulfilled expectations: %s", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestErrPlanByID(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
idToUse := 1
|
||||
|
||||
str, mock := getDbMock(t)
|
||||
|
||||
mock.ExpectQuery("^SELECT plan_id, plan_date FROM plans WHERE plan_id = \\$1$").WithArgs(idToUse).WillReturnError(fmt.Errorf("example error"))
|
||||
|
||||
plan, err := str.SelectPlanByID(idToUse)
|
||||
assert.NotNil(err)
|
||||
assert.Nil(plan)
|
||||
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("unfulfilled expectations: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectActions(t *testing.T) {
|
||||
// set up test
|
||||
assert := assert.New(t)
|
||||
@@ -338,22 +195,6 @@ func TestSelectActionById(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestErrPlans(t *testing.T) {
|
||||
// set up tests
|
||||
assert := assert.New(t)
|
||||
str, mock := getDbMock(t)
|
||||
|
||||
mock.ExpectQuery("^SELECT plan_id, plan_date FROM plans$").WillReturnError(fmt.Errorf("example error"))
|
||||
// function under test
|
||||
plans, err := str.SelectPlans()
|
||||
// test results
|
||||
assert.Nil(plans)
|
||||
assert.NotNil(err)
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("unfulfilled expectations: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestErrActions(t *testing.T) {
|
||||
// set up tests
|
||||
assert := assert.New(t)
|
||||
|
||||
Reference in New Issue
Block a user