Skip to content

Commit

Permalink
Generate ssclientmock package
Browse files Browse the repository at this point in the history
  • Loading branch information
sevein committed May 14, 2024
1 parent af090f3 commit 770e4a3
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 15 deletions.
3 changes: 2 additions & 1 deletion hack/ccp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ gen: gen-mocks gen-sqlc gen-enums gen-buf

gen-mocks: # @HELP Generate mocks.
gen-mocks: $(MOCKGEN)
mockgen -typed -source=./internal/store/store.go -destination=./internal/store/fake/mock_store.go -package=fake Store
mockgen -typed -source=./internal/store/store.go -destination=./internal/store/storemock/mock_store.go -package=storemock Store
mockgen -typed -source=./internal/ssclient/ssclient.go -destination=./internal/ssclient/ssclientmock/mock_ssclient.go -package=ssclientmock Client

gen-sqlc: # @HELP Generate sqlc code.
gen-sqlc: $(SQLC)
Expand Down
6 changes: 3 additions & 3 deletions hack/ccp/internal/controller/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
// This method does not rely on the activeTransfer watched directory. It does
// not prompt the user to accept the transfer because we go directly into the
// next chain link.
func StartTransfer(sharedDir, tmpDir, name, path string) error {
func StartTransfer(ssclient ssclient.Client, sharedDir, tmpDir, name, path string) error {
destRel, destAbs, src := determineTransferPaths(sharedDir, tmpDir, name, path)
fmt.Println(destRel, destAbs, src)

copyFromTransferSources(nil)
copyFromTransferSources(ssclient, []string{path}, destRel)

tsrc, tdst := "", ""
dst, err := moveToInternalSharedDir(sharedDir, tsrc, tdst)
Expand Down Expand Up @@ -147,7 +147,7 @@ func moveToInternalSharedDir(sharedDir, path, dest string) (_ string, err error)
}
}

func copyFromTransferSources(c ssclient.Client) {
func copyFromTransferSources(c ssclient.Client, paths []string, destRel string) {
// - processing_location = storage_service.get_first_location(purpose="CP")
// - transfer_sources = storage_service.get_location(purpose="TS")
// - _default_transfer_source_location_uuid
Expand Down
4 changes: 2 additions & 2 deletions hack/ccp/internal/controller/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"gotest.tools/v3/fs"

"github.com/artefactual/archivematica/hack/ccp/internal/store"
fakestore "github.com/artefactual/archivematica/hack/ccp/internal/store/fake"
"github.com/artefactual/archivematica/hack/ccp/internal/store/storemock"
"github.com/artefactual/archivematica/hack/ccp/internal/workflow"
)

Expand Down Expand Up @@ -69,7 +69,7 @@ func TestTaskBackend(t *testing.T) {
},
})

s := fakestore.NewMockStore(gomock.NewController(t))
s := storemock.NewMockStore(gomock.NewController(t))
s.EXPECT().CreateTasks(gomock.Any(), gomock.Cond(func(tt any) bool {
tasks := tt.([]*store.Task)
return len(tasks) <= batchSize // It should never exceed the batch size.
Expand Down
12 changes: 6 additions & 6 deletions hack/ccp/internal/ssclient/ssclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import (
"gotest.tools/v3/assert/cmp"

"github.com/artefactual/archivematica/hack/ccp/internal/ssclient"
"github.com/artefactual/archivematica/hack/ccp/internal/store/fake"
"github.com/artefactual/archivematica/hack/ccp/internal/store/storemock"
)

func TestClient(t *testing.T) {
t.Parallel()

tests := map[string]struct {
store func(rec *fake.MockStoreMockRecorder)
store func(rec *storemock.MockStoreMockRecorder)
server httpmock.Mocker
client func(t *testing.T, c ssclient.Client)
}{
Expand Down Expand Up @@ -64,7 +64,7 @@ func TestClient(t *testing.T) {
//

"ReadDefaultLocation returns the default AS location": {
store: func(rec *fake.MockStoreMockRecorder) {
store: func(rec *storemock.MockStoreMockRecorder) {
// It looks up the pipeline ID in the store.
expectStoreReadPipelineID(rec)
},
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestClient(t *testing.T) {
//

"ListLocations returns a list of locations": {
store: func(rec *fake.MockStoreMockRecorder) {
store: func(rec *storemock.MockStoreMockRecorder) {
// It looks up the pipeline ID in the store.
expectStoreReadPipelineID(rec)
},
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestClient(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()

store := fake.NewMockStore(gomock.NewController(t))
store := storemock.NewMockStore(gomock.NewController(t))
if tc.store != nil {
tc.store(store.EXPECT())
}
Expand All @@ -210,7 +210,7 @@ func TestClient(t *testing.T) {
}
}

func expectStoreReadPipelineID(rec *fake.MockStoreMockRecorder) {
func expectStoreReadPipelineID(rec *storemock.MockStoreMockRecorder) {
rec.
ReadPipelineID(mockutil.Context()).
Return(uuid.MustParse("fb2b8866-6f39-4616-b6cd-fa73193a3b05"), nil).
Expand Down
197 changes: 197 additions & 0 deletions hack/ccp/internal/ssclient/ssclientmock/mock_ssclient.go

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

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

0 comments on commit 770e4a3

Please sign in to comment.