diff --git a/backend/endpoints/tests/filesystem_test.go b/backend/endpoints/tests/filesystem_test.go index a00336b2..1c276d67 100644 --- a/backend/endpoints/tests/filesystem_test.go +++ b/backend/endpoints/tests/filesystem_test.go @@ -146,7 +146,9 @@ func TestValidGetChildren(t *testing.T) { // createMockDependencyFactory just constructs an instance of a dependency factory mock func createMockDependencyFactory(controller *gomock.Controller, mockFileRepo *repMocks.MockIFilesystemRepository, needsLogger bool) *mocks.MockDependencyFactory { mockDepFactory := mocks.NewMockDependencyFactory(controller) - mockDepFactory.EXPECT().GetFilesystemRepo().Return(mockFileRepo) + if mockFileRepo != nil { + mockDepFactory.EXPECT().GetFilesystemRepo().Return(mockFileRepo) + } if needsLogger { log := logger.OpenLog("new log") diff --git a/backend/endpoints/tests/volume_test.go b/backend/endpoints/tests/volume_test.go index a2d86482..65da3454 100644 --- a/backend/endpoints/tests/volume_test.go +++ b/backend/endpoints/tests/volume_test.go @@ -19,6 +19,32 @@ func TestUploadDocument(t *testing.T) { } func TestGetPublishedDocument(t *testing.T) { + controller := gomock.NewController(t) + assert := assert.New(t) + defer controller.Finish() + + // ==== test setup ===== + entityID := uuid.New() + + tempFile, _ := ioutil.TempFile(os.TempDir(), "expected") + if _, err := tempFile.WriteString("hello world"); err != nil { + panic(err) + } + tempFile.Seek(0, 0) + defer os.Remove(tempFile.Name()) + + mockDockerFileSystemRepo := repMocks.NewMockIPublishedVolumeRepository(controller) + mockDockerFileSystemRepo.EXPECT().GetFromVolume(entityID.String()).Return(tempFile, nil).Times(1) + + mockDepFactory := createMockDependencyFactory(controller, nil, true) + mockDepFactory.EXPECT().GetPublishedVolumeRepo().Return(mockDockerFileSystemRepo) + + // // ==== test execution ===== + form := models.ValidGetPublishedDocumentRequest{DocumentID: entityID} + response := endpoints.GetPublishedDocument(form, mockDepFactory) + + assert.Equal(response.Status, http.StatusOK) + assert.Equal(response.Response, []byte("{\"Contents\": hello world}")) } func TestUploadImage(t *testing.T) {