@@ -16,6 +16,56 @@ import (
1616)
1717
1818func TestUploadDocument (t * testing.T ) {
19+ controller := gomock .NewController (t )
20+ assert := assert .New (t )
21+ defer controller .Finish ()
22+
23+ // ==== test setup =====
24+ entityID := uuid .New ()
25+ parentID := uuid .New ()
26+ entityToCreate := repositories.FilesystemEntry {
27+ LogicalName : "file" ,
28+ ParentFileID : parentID ,
29+ IsDocument : true ,
30+ OwnerUserId : 1 ,
31+ }
32+
33+ mockFileRepo := repMocks .NewMockIFilesystemRepository (controller )
34+ mockFileRepo .EXPECT ().CreateEntry (entityToCreate ).Return (repositories.FilesystemEntry {
35+ EntityID : entityID ,
36+ LogicalName : "file" ,
37+ ParentFileID : parentID ,
38+ IsDocument : true ,
39+ OwnerUserId : 1 ,
40+ }, nil ).Times (1 )
41+
42+ temp , _ := ioutil .TempFile (os .TempDir (), "expected" )
43+ defer os .Remove (temp .Name ())
44+
45+ mockDockerFileSystemRepo := repMocks .NewMockIUnpublishedVolumeRepository (controller )
46+ mockDockerFileSystemRepo .EXPECT ().GetFromVolume (entityID .String ()).Return (temp , nil ).Times (1 )
47+
48+ mockDepFactory := createMockDependencyFactory (controller , mockFileRepo , true )
49+ mockDepFactory .EXPECT ().GetUnpublishedVolumeRepo ().Return (mockDockerFileSystemRepo )
50+
51+ const fileContent = "Hello World"
52+
53+ form := models.ValidDocumentUploadRequest {
54+ Parent : parentID ,
55+ DocumentName : "file" ,
56+ Content : fileContent ,
57+ }
58+
59+ response := endpoints .UploadDocument (form , mockDepFactory )
60+ assert .Equal (response .Status , http .StatusOK )
61+ assert .Equal (response .Response , models.NewEntityResponse {
62+ NewID : entityID ,
63+ })
64+
65+ // check that the file was written to the docker volume
66+ actual , _ := ioutil .ReadFile (temp .Name ())
67+ assert .Equal (actual , []byte (fileContent ))
68+
1969}
2070
2171func TestGetPublishedDocument (t * testing.T ) {
0 commit comments