Adds tests for inmemory store

This commit is contained in:
Deepak Mallubhotla 2021-01-31 12:26:39 -06:00
parent b9cea2347c
commit 6ad0112683
Signed by: deepak
GPG Key ID: 64BF53A3369104E7
2 changed files with 38 additions and 3 deletions

View File

@ -114,9 +114,10 @@ func (store *inMemoryStore) InsertCurrentPlan(currentPlan *models.CurrentPlan, u
if err == nil {
return fmt.Errorf("Can't insert primary plan")
}
if err != sql.ErrNoRows {
return err
}
// actually impossible, but at this point it must be a not found error.
// if err != sql.ErrNoRows {
// return err
// }
store.currentPlans = append(store.currentPlans, &models.CurrentPlan{PlanID: int64(currentPlan.PlanID), UserID: int64(userID)})
return nil

View File

@ -105,3 +105,37 @@ func TestInMemoryUserMethods(t *testing.T) {
_, err = str.SelectUserByUsername("bad username")
assert.NotNil(err)
}
func TestInMemoryCurrentPlanMethods(t *testing.T) {
assert := assert.New(t)
str, _ := store.GetInMemoryStore()
userID := 10
cp1 := &models.CurrentPlan{PlanID: 1}
cp2 := &models.CurrentPlan{PlanID: 2}
err := str.UpdateCurrentPlan(cp1, userID)
assert.NotNil(err)
err = str.InsertCurrentPlan(cp1, userID)
assert.Nil(err)
receivedCp, err := str.SelectCurrentPlan(userID)
assert.Nil(err)
assert.EqualValues(1, receivedCp.PlanID)
_, err = str.SelectCurrentPlan(userID + 1)
assert.NotNil(err)
str.InsertCurrentPlan(cp2, userID)
assert.NotNil(err)
err = str.UpdateCurrentPlan(cp2, userID)
assert.Nil(err)
receivedCp, err = str.SelectCurrentPlan(userID)
assert.Nil(err)
assert.EqualValues(2, receivedCp.PlanID)
}