Compare commits
2 Commits
c0d5a543f0
...
50bbcdc71d
| Author | SHA1 | Date | |
|---|---|---|---|
|
50bbcdc71d
|
|||
|
7ae7f294da
|
25
do.sh
25
do.sh
@@ -5,21 +5,28 @@
|
|||||||
set -Eeuo pipefail # -e "Automatic exit from bash shell script on error" -u "Treat unset variables and parameters as errors"
|
set -Eeuo pipefail # -e "Automatic exit from bash shell script on error" -u "Treat unset variables and parameters as errors"
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
echo "I am ${FUNCNAME[0]}ing"
|
echo "I am ${FUNCNAME[0]}ing"
|
||||||
go version
|
go version
|
||||||
go build
|
go build
|
||||||
}
|
}
|
||||||
|
|
||||||
test() {
|
test() {
|
||||||
_lint && _vet && _test
|
echo "I am ${FUNCNAME[0]}ing"
|
||||||
|
_lint && _vet && _test
|
||||||
}
|
}
|
||||||
|
|
||||||
run() {
|
run() {
|
||||||
test && go run main.go
|
echo "I am ${FUNCNAME[0]}ing"
|
||||||
|
fmt && test && go run main.go
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt() {
|
||||||
|
echo "I am ${FUNCNAME[0]}ing"
|
||||||
|
go fmt ./...
|
||||||
}
|
}
|
||||||
|
|
||||||
_test() {
|
_test() {
|
||||||
go test -v -coverprofile=coverage.out -covermode count ./... | tee tests.out
|
go test -v -coverprofile=coverage.out -covermode count ./... | tee tests.out
|
||||||
}
|
}
|
||||||
|
|
||||||
_testhtml() {
|
_testhtml() {
|
||||||
@@ -27,15 +34,15 @@ _testhtml() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_lint() {
|
_lint() {
|
||||||
golint -set_exit_status ./...
|
golint -set_exit_status ./...
|
||||||
}
|
}
|
||||||
|
|
||||||
_vet() {
|
_vet() {
|
||||||
go vet ./...
|
go vet ./...
|
||||||
}
|
}
|
||||||
|
|
||||||
all() {
|
all() {
|
||||||
test && build
|
fmt && test && build
|
||||||
}
|
}
|
||||||
|
|
||||||
"$@" # <- execute the task
|
"$@" # <- execute the task
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ import (
|
|||||||
type Action struct {
|
type Action struct {
|
||||||
ActionID int64
|
ActionID int64
|
||||||
ActionDescription string
|
ActionDescription string
|
||||||
|
EstimatedChunks int
|
||||||
|
CompletedChunks int
|
||||||
|
CompletedOn time.Time
|
||||||
|
PlanID int
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ CREATE TABLE IF NOT EXISTS actions(
|
|||||||
completed_on TIMESTAMP WITH TIME ZONE,
|
completed_on TIMESTAMP WITH TIME ZONE,
|
||||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||||
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||||
plan int REFERENCES plans(plan_id)
|
plan_id int REFERENCES plans(plan_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ func GetPostgresStore(db *sqlx.DB) (models.Store, error) {
|
|||||||
|
|
||||||
func (store *postgresStore) SelectActions() ([]*models.Action, error) {
|
func (store *postgresStore) SelectActions() ([]*models.Action, error) {
|
||||||
actions := make([]*models.Action, 0)
|
actions := make([]*models.Action, 0)
|
||||||
err := store.db.Select(&actions, "SELECT action_id, action_description, created_at, updated_at FROM actions")
|
err := store.db.Select(&actions, "SELECT action_id, action_description, estimated_chunks, completed_chunks, completed_on, created_at, updated_at, plan_id FROM actions")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,15 +53,26 @@ func TestSelectActions(t *testing.T) {
|
|||||||
|
|
||||||
createTime, _ := time.Parse("2006-01-02", "2020-12-31")
|
createTime, _ := time.Parse("2006-01-02", "2020-12-31")
|
||||||
updateTime, _ := time.Parse("2006-01-02", "2021-01-01")
|
updateTime, _ := time.Parse("2006-01-02", "2021-01-01")
|
||||||
|
completeTime, _ := time.Parse("2006-01-02", "2021-01-05")
|
||||||
idToUse := 1
|
idToUse := 1
|
||||||
|
estChunks := 5
|
||||||
|
compChunks := 7
|
||||||
desc := "Howdy, partner."
|
desc := "Howdy, partner."
|
||||||
|
|
||||||
str, mock := getDbMock(t)
|
str, mock := getDbMock(t)
|
||||||
|
|
||||||
rows := sqlmock.NewRows([]string{"action_id", "action_description", "created_at", "updated_at"}).
|
rows := sqlmock.NewRows([]string{
|
||||||
AddRow(idToUse, desc, createTime, updateTime).
|
"action_id",
|
||||||
AddRow(idToUse+1, desc, createTime, updateTime)
|
"action_description",
|
||||||
mock.ExpectQuery("^SELECT action_id, action_description, created_at, updated_at FROM actions$").WillReturnRows(rows)
|
"estimated_chunks",
|
||||||
|
"completed_chunks",
|
||||||
|
"completed_on",
|
||||||
|
"created_at",
|
||||||
|
"updated_at",
|
||||||
|
"plan_id"}).
|
||||||
|
AddRow(idToUse, desc, estChunks, compChunks, completeTime, createTime, updateTime, idToUse).
|
||||||
|
AddRow(idToUse+1, desc, estChunks, compChunks, completeTime, createTime, updateTime, idToUse)
|
||||||
|
mock.ExpectQuery("^SELECT action_id, action_description, estimated_chunks, completed_chunks, completed_on, created_at, updated_at, plan_id FROM actions$").WillReturnRows(rows)
|
||||||
|
|
||||||
// function under test
|
// function under test
|
||||||
actions, err := str.SelectActions()
|
actions, err := str.SelectActions()
|
||||||
@@ -72,8 +83,12 @@ func TestSelectActions(t *testing.T) {
|
|||||||
action := actions[0]
|
action := actions[0]
|
||||||
assert.EqualValues(idToUse, action.ActionID)
|
assert.EqualValues(idToUse, action.ActionID)
|
||||||
assert.Equal(desc, action.ActionDescription)
|
assert.Equal(desc, action.ActionDescription)
|
||||||
|
assert.Equal(estChunks, action.EstimatedChunks)
|
||||||
|
assert.Equal(compChunks, action.CompletedChunks)
|
||||||
|
assert.Equal(completeTime, action.CompletedOn)
|
||||||
assert.Equal(createTime, action.CreatedAt)
|
assert.Equal(createTime, action.CreatedAt)
|
||||||
assert.Equal(updateTime, action.UpdatedAt)
|
assert.Equal(updateTime, action.UpdatedAt)
|
||||||
|
assert.Equal(idToUse, action.PlanID)
|
||||||
|
|
||||||
if err := mock.ExpectationsWereMet(); err != nil {
|
if err := mock.ExpectationsWereMet(); err != nil {
|
||||||
t.Errorf("unfulfilled expectations: %s", err)
|
t.Errorf("unfulfilled expectations: %s", err)
|
||||||
@@ -101,7 +116,7 @@ func TestErrActions(t *testing.T) {
|
|||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
str, mock := getDbMock(t)
|
str, mock := getDbMock(t)
|
||||||
|
|
||||||
mock.ExpectQuery("^SELECT action_id, action_description, created_at, updated_at FROM actions$").WillReturnError(fmt.Errorf("example error"))
|
mock.ExpectQuery("^SELECT action_id, action_description, estimated_chunks, completed_chunks, completed_on, created_at, updated_at, plan_id FROM actions$").WillReturnError(fmt.Errorf("example error"))
|
||||||
// function under test
|
// function under test
|
||||||
actions, err := str.SelectActions()
|
actions, err := str.SelectActions()
|
||||||
// test results
|
// test results
|
||||||
|
|||||||
Reference in New Issue
Block a user