Skip to content

Commit dda69a8

Browse files
authored
wrote test for TestGetPublishedDocument (#348)
1 parent e1fa716 commit dda69a8

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

backend/endpoints/tests/filesystem_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ func TestValidGetChildren(t *testing.T) {
146146
// createMockDependencyFactory just constructs an instance of a dependency factory mock
147147
func createMockDependencyFactory(controller *gomock.Controller, mockFileRepo *repMocks.MockIFilesystemRepository, needsLogger bool) *mocks.MockDependencyFactory {
148148
mockDepFactory := mocks.NewMockDependencyFactory(controller)
149-
mockDepFactory.EXPECT().GetFilesystemRepo().Return(mockFileRepo)
149+
if mockFileRepo != nil {
150+
mockDepFactory.EXPECT().GetFilesystemRepo().Return(mockFileRepo)
151+
}
150152

151153
if needsLogger {
152154
log := logger.OpenLog("new log")

backend/endpoints/tests/volume_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,32 @@ func TestUploadDocument(t *testing.T) {
1919
}
2020

2121
func TestGetPublishedDocument(t *testing.T) {
22+
controller := gomock.NewController(t)
23+
assert := assert.New(t)
24+
defer controller.Finish()
25+
26+
// ==== test setup =====
27+
entityID := uuid.New()
28+
29+
tempFile, _ := ioutil.TempFile(os.TempDir(), "expected")
30+
if _, err := tempFile.WriteString("hello world"); err != nil {
31+
panic(err)
32+
}
33+
tempFile.Seek(0, 0)
34+
defer os.Remove(tempFile.Name())
35+
36+
mockDockerFileSystemRepo := repMocks.NewMockIPublishedVolumeRepository(controller)
37+
mockDockerFileSystemRepo.EXPECT().GetFromVolume(entityID.String()).Return(tempFile, nil).Times(1)
38+
39+
mockDepFactory := createMockDependencyFactory(controller, nil, true)
40+
mockDepFactory.EXPECT().GetPublishedVolumeRepo().Return(mockDockerFileSystemRepo)
41+
42+
// // ==== test execution =====
43+
form := models.ValidGetPublishedDocumentRequest{DocumentID: entityID}
44+
response := endpoints.GetPublishedDocument(form, mockDepFactory)
45+
46+
assert.Equal(response.Status, http.StatusOK)
47+
assert.Equal(response.Response, []byte("{\"Contents\": hello world}"))
2248
}
2349

2450
func TestUploadImage(t *testing.T) {

0 commit comments

Comments
 (0)