Skip to content

Commit

Permalink
- add file fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
KinNeko-De committed Dec 18, 2023
1 parent 125fbcb commit 7106129
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
21 changes: 5 additions & 16 deletions internal/app/file/file_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"testing"

v1 "github.com/kinneko-de/api-contract/golang/kinnekode/restaurant/file/v1"
"github.com/kinneko-de/restaurant-file-store-svc/internal/testing/fixture"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

Expand Down Expand Up @@ -47,7 +49,7 @@ func TestStoreFile(t *testing.T) {
mockStream.EXPECT().Recv().Return(metadata, nil).Times(1)
var chunk = &v1.StoreFileRequest{
File: &v1.StoreFileRequest_Chunk{
Chunk: []byte{116, 101, 115, 116}, // TODO test.txt with content "test". extract to fixture
Chunk: fixture.TextFile(),
},
}
mockStream.EXPECT().Recv().Return(chunk, nil).Times(1)
Expand All @@ -59,21 +61,8 @@ func TestStoreFile(t *testing.T) {
response.GetStoredFileMetadata().GetMediaType() == "text/plain; charset=utf-8" &&
response.GetStoredFileMetadata().GetExtension() == ".txt"
})).Return(nil).Times(1)
/*
mockStream.EXPECT().SendAndClose(&v1.StoreFileResponse{
StoredFile: &v1.StoredFile{
Id: &apiProtobuf.Uuid{Value: "test"},
Revision: 1,
},
StoredFileMetadata: &v1.StoredFileMetadata{
CreatedAt: timestamppb.Now(),
Size: 4,
MediaType: "text/plain; charset=utf-8",
Extension: ".txt",
},
})
*/

server := FileServiceServer{}
server.StoreFile(mockStream)
actualError := server.StoreFile(mockStream)
assert.Nil(t, actualError)
}
6 changes: 6 additions & 0 deletions internal/testing/fixture/file_fixture.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package fixture

// Textfile that contains the string 'test'
func TextFile() []byte {
return []byte{116, 101, 115, 116}
}

0 comments on commit 7106129

Please sign in to comment.