Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix CI generation; rename mock->dbmock
Signed-off-by: Spike Curtis <[email protected]>
  • Loading branch information
spikecurtis committed May 23, 2023
commit acd1243b2bfdcba7a0c22f1bf17d905f91c42efa
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ jobs:
run: go install golang.org/x/tools/cmd/goimports@latest
- name: Install yq
run: go run github.com/mikefarah/yq/[email protected]
- name: Install mockgen
run: go install github.com/golang/mock/[email protected]

- name: Install Protoc
run: |
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ lint/shellcheck: $(SHELL_SRC_FILES)
gen: \
coderd/database/dump.sql \
coderd/database/querier.go \
coderd/database/mock/store.go \
coderd/database/dbmock/store.go \
provisionersdk/proto/provisioner.pb.go \
provisionerd/proto/provisionerd.pb.go \
site/src/api/typesGenerated.ts \
Expand All @@ -442,7 +442,7 @@ gen/mark-fresh:
files="\
coderd/database/dump.sql \
coderd/database/querier.go \
coderd/database/mock/store.go \
coderd/database/dbmock/store.go \
provisionersdk/proto/provisioner.pb.go \
provisionerd/proto/provisionerd.pb.go \
site/src/api/typesGenerated.ts \
Expand Down Expand Up @@ -479,8 +479,8 @@ coderd/database/querier.go: coderd/database/sqlc.yaml coderd/database/dump.sql $
./coderd/database/generate.sh


coderd/database/mock/store.go: coderd/database/db.go coderd/database/querier.go
go generate ./coderd/database/mock/
coderd/database/dbmock/store.go: coderd/database/db.go coderd/database/querier.go
go generate ./coderd/database/dbmock/

provisionersdk/proto/provisioner.pb.go: provisionersdk/proto/provisioner.proto
protoc \
Expand Down
4 changes: 4 additions & 0 deletions coderd/database/dbmock/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// package dbmock contains a mocked implementation of the database.Store interface for use in tests
package dbmock

//go:generate mockgen -destination ./store.go -package dbmock github.com/coder/coder/coderd/database Store

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions coderd/database/mock/doc.go

This file was deleted.

40 changes: 20 additions & 20 deletions coderd/wsbuilder/wsbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/stretchr/testify/require"

"github.com/coder/coder/coderd/database"
"github.com/coder/coder/coderd/database/dbmock"
"github.com/coder/coder/coderd/database/dbtype"
"github.com/coder/coder/coderd/database/mock"
"github.com/coder/coder/coderd/provisionerdserver"
"github.com/coder/coder/coderd/wsbuilder"
"github.com/coder/coder/codersdk"
Expand Down Expand Up @@ -557,13 +557,13 @@ func TestWorkspaceBuildWithRichParameters(t *testing.T) {
})
}

type txExpect func(mTx *mock.MockStore)
type txExpect func(mTx *dbmock.MockStore)

func expectDB(t *testing.T, opts ...txExpect) *mock.MockStore {
func expectDB(t *testing.T, opts ...txExpect) *dbmock.MockStore {
t.Helper()
ctrl := gomock.NewController(t)
mDB := mock.NewMockStore(ctrl)
mTx := mock.NewMockStore(ctrl)
mDB := dbmock.NewMockStore(ctrl)
mTx := dbmock.NewMockStore(ctrl)

// we expect to be run in a transaction; we use mTx to record the
// "in transaction" calls.
Expand All @@ -582,7 +582,7 @@ func expectDB(t *testing.T, opts ...txExpect) *mock.MockStore {
return mDB
}

func withTemplate(mTx *mock.MockStore) {
func withTemplate(mTx *dbmock.MockStore) {
mTx.EXPECT().GetTemplateByID(gomock.Any(), templateID).
Times(1).
Return(database.Template{
Expand All @@ -593,8 +593,8 @@ func withTemplate(mTx *mock.MockStore) {
}, nil)
}

func withActiveVersion(params []database.TemplateVersionParameter) func(mTx *mock.MockStore) {
return func(mTx *mock.MockStore) {
func withActiveVersion(params []database.TemplateVersionParameter) func(mTx *dbmock.MockStore) {
return func(mTx *dbmock.MockStore) {
mTx.EXPECT().GetTemplateVersionByID(gomock.Any(), activeVersionID).
Times(1).
Return(database.TemplateVersion{
Expand Down Expand Up @@ -633,8 +633,8 @@ func withActiveVersion(params []database.TemplateVersionParameter) func(mTx *moc
}
}

func withInactiveVersion(params []database.TemplateVersionParameter) func(mTx *mock.MockStore) {
return func(mTx *mock.MockStore) {
func withInactiveVersion(params []database.TemplateVersionParameter) func(mTx *dbmock.MockStore) {
return func(mTx *dbmock.MockStore) {
mTx.EXPECT().GetTemplateVersionByID(gomock.Any(), inactiveVersionID).
Times(1).
Return(database.TemplateVersion{
Expand Down Expand Up @@ -673,7 +673,7 @@ func withInactiveVersion(params []database.TemplateVersionParameter) func(mTx *m
}
}

func withLastBuildFound(mTx *mock.MockStore) {
func withLastBuildFound(mTx *dbmock.MockStore) {
mTx.EXPECT().GetLatestWorkspaceBuildByWorkspaceID(gomock.Any(), workspaceID).
Times(1).
Return(database.WorkspaceBuild{
Expand Down Expand Up @@ -704,14 +704,14 @@ func withLastBuildFound(mTx *mock.MockStore) {
}, nil)
}

func withLastBuildNotFound(mTx *mock.MockStore) {
func withLastBuildNotFound(mTx *dbmock.MockStore) {
mTx.EXPECT().GetLatestWorkspaceBuildByWorkspaceID(gomock.Any(), workspaceID).
Times(1).
Return(database.WorkspaceBuild{}, sql.ErrNoRows)
}

func withLegacyParameters(params []database.ParameterValue) func(mTx *mock.MockStore) {
return func(mTx *mock.MockStore) {
func withLegacyParameters(params []database.ParameterValue) func(mTx *dbmock.MockStore) {
return func(mTx *dbmock.MockStore) {
c := mTx.EXPECT().ParameterValues(
gomock.Any(),
database.ParameterValuesParams{
Expand All @@ -727,8 +727,8 @@ func withLegacyParameters(params []database.ParameterValue) func(mTx *mock.MockS
}
}

func withRichParameters(params []database.WorkspaceBuildParameter) func(mTx *mock.MockStore) {
return func(mTx *mock.MockStore) {
func withRichParameters(params []database.WorkspaceBuildParameter) func(mTx *dbmock.MockStore) {
return func(mTx *dbmock.MockStore) {
c := mTx.EXPECT().GetWorkspaceBuildParameters(gomock.Any(), lastBuildID).
Times(1)
if len(params) > 0 {
Expand All @@ -747,8 +747,8 @@ func withRichParameters(params []database.WorkspaceBuildParameter) func(mTx *moc
// against it.
func expectProvisionerJob(
assertions func(job database.InsertProvisionerJobParams),
) func(mTx *mock.MockStore) {
return func(mTx *mock.MockStore) {
) func(mTx *dbmock.MockStore) {
return func(mTx *dbmock.MockStore) {
mTx.EXPECT().InsertProvisionerJob(gomock.Any(), gomock.Any()).
Times(1).
DoAndReturn(
Expand All @@ -766,8 +766,8 @@ func expectProvisionerJob(
// against it.
func expectBuild(
assertions func(job database.InsertWorkspaceBuildParams),
) func(mTx *mock.MockStore) {
return func(mTx *mock.MockStore) {
) func(mTx *dbmock.MockStore) {
return func(mTx *dbmock.MockStore) {
mTx.EXPECT().InsertWorkspaceBuild(gomock.Any(), gomock.Any()).
Times(1).
DoAndReturn(
Expand Down