Merged in feature/assertions (pull request #158)
Assertions + Gen Text * assert
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
||||
documenttypes "queryorchestration/internal/document/types"
|
||||
)
|
||||
|
||||
func (s *Service) getDocumentText(ctx context.Context, doc documenttypes.File) (io.Reader, error) {
|
||||
func (s *Service) GetDocumentText(ctx context.Context, doc documenttypes.File) (io.Reader, error) {
|
||||
pagesNum, err := doc.GetPageCount(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -37,7 +37,7 @@ func TestGetDocumentText(t *testing.T) {
|
||||
|
||||
textExpectations(t, ctx, mockTextract, pdf, textractBaseOut)
|
||||
|
||||
text, err := svc.getDocumentText(ctx, pdf)
|
||||
text, err := svc.GetDocumentText(ctx, pdf)
|
||||
require.NoError(t, err)
|
||||
assertReaders(t, txtFile, text)
|
||||
})
|
||||
@@ -63,7 +63,7 @@ func TestGetDocumentText(t *testing.T) {
|
||||
).
|
||||
Return(nil, errors.New("no textract response"))
|
||||
|
||||
_, err := svc.getDocumentText(ctx, pdf)
|
||||
_, err := svc.GetDocumentText(ctx, pdf)
|
||||
require.EqualError(t, err, "no textract response")
|
||||
})
|
||||
t.Run("merged_cell_table", func(t *testing.T) {
|
||||
@@ -80,7 +80,7 @@ func TestGetDocumentText(t *testing.T) {
|
||||
|
||||
textExpectations(t, ctx, mockTextract, pdf, textractBaseOut)
|
||||
|
||||
text, err := svc.getDocumentText(ctx, pdf)
|
||||
text, err := svc.GetDocumentText(ctx, pdf)
|
||||
require.NoError(t, err)
|
||||
|
||||
assertReaders(t, txtFile, text)
|
||||
@@ -99,7 +99,7 @@ func TestGetDocumentText(t *testing.T) {
|
||||
|
||||
textExpectations(t, ctx, mockTextract, pdf, textractBaseOut)
|
||||
|
||||
text, err := svc.getDocumentText(ctx, pdf)
|
||||
text, err := svc.GetDocumentText(ctx, pdf)
|
||||
require.NoError(t, err)
|
||||
|
||||
assertReaders(t, txtFile, text)
|
||||
@@ -118,7 +118,7 @@ func TestGetDocumentText(t *testing.T) {
|
||||
|
||||
textExpectations(t, ctx, mockTextract, pdf, textractBaseOut)
|
||||
|
||||
text, err := svc.getDocumentText(ctx, pdf)
|
||||
text, err := svc.GetDocumentText(ctx, pdf)
|
||||
require.NoError(t, err)
|
||||
|
||||
assertReaders(t, txtFile, text)
|
||||
@@ -137,7 +137,7 @@ func TestGetDocumentText(t *testing.T) {
|
||||
|
||||
textExpectations(t, ctx, mockTextract, pdf, textractBaseOut)
|
||||
|
||||
text, err := svc.getDocumentText(ctx, pdf)
|
||||
text, err := svc.GetDocumentText(ctx, pdf)
|
||||
require.NoError(t, err)
|
||||
|
||||
assertReaders(t, txtFile, text)
|
||||
@@ -156,7 +156,7 @@ func TestGetDocumentText(t *testing.T) {
|
||||
|
||||
textExpectations(t, ctx, mockTextract, pdf, textractBaseOut)
|
||||
|
||||
text, err := svc.getDocumentText(ctx, pdf)
|
||||
text, err := svc.GetDocumentText(ctx, pdf)
|
||||
require.NoError(t, err)
|
||||
|
||||
assertReaders(t, txtFile, text)
|
||||
@@ -175,7 +175,7 @@ func TestGetDocumentText(t *testing.T) {
|
||||
|
||||
textExpectations(t, ctx, mockTextract, pdf, textractBaseOut)
|
||||
|
||||
text, err := svc.getDocumentText(ctx, pdf)
|
||||
text, err := svc.GetDocumentText(ctx, pdf)
|
||||
require.NoError(t, err)
|
||||
|
||||
assertReaders(t, txtFile, text)
|
||||
@@ -195,7 +195,7 @@ func TestGetDocumentText(t *testing.T) {
|
||||
|
||||
textExpectations(t, ctx, mockTextract, pdf, textractBaseOut)
|
||||
|
||||
text, err := svc.getDocumentText(ctx, pdf)
|
||||
text, err := svc.GetDocumentText(ctx, pdf)
|
||||
require.NoError(t, err)
|
||||
|
||||
assertReaders(t, txtFile, text)
|
||||
@@ -214,7 +214,7 @@ func TestGetDocumentText(t *testing.T) {
|
||||
|
||||
textExpectations(t, ctx, mockTextract, pdf, textractBaseOut)
|
||||
|
||||
text, err := svc.getDocumentText(ctx, pdf)
|
||||
text, err := svc.GetDocumentText(ctx, pdf)
|
||||
require.NoError(t, err)
|
||||
|
||||
assertReaders(t, txtFile, text)
|
||||
@@ -233,7 +233,7 @@ func TestGetDocumentText(t *testing.T) {
|
||||
|
||||
textExpectations(t, ctx, mockTextract, pdf, textractBaseOut)
|
||||
|
||||
text, err := svc.getDocumentText(ctx, pdf)
|
||||
text, err := svc.GetDocumentText(ctx, pdf)
|
||||
require.NoError(t, err)
|
||||
|
||||
assertReaders(t, txtFile, text)
|
||||
@@ -252,7 +252,7 @@ func TestGetDocumentText(t *testing.T) {
|
||||
|
||||
textExpectations(t, ctx, mockTextract, pdf, textractBaseOut)
|
||||
|
||||
text, err := svc.getDocumentText(ctx, pdf)
|
||||
text, err := svc.GetDocumentText(ctx, pdf)
|
||||
require.NoError(t, err)
|
||||
|
||||
assertReaders(t, txtFile, text)
|
||||
|
||||
@@ -34,7 +34,7 @@ func (s *Service) executeExtraction(ctx context.Context, documentId uuid.UUID) e
|
||||
return err
|
||||
}
|
||||
|
||||
text, err := s.getDocumentText(ctx, doc)
|
||||
text, err := s.GetDocumentText(ctx, doc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package documentupload_test
|
||||
|
||||
import (
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -11,6 +12,8 @@ import (
|
||||
|
||||
documentupload "queryorchestration/internal/document/upload"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -37,9 +40,26 @@ func TestUpload(t *testing.T) {
|
||||
|
||||
file := documentupload.File{
|
||||
ClientID: "client_id",
|
||||
Content: strings.NewReader("aaaaaaaaaaaa"),
|
||||
Content: strings.NewReader("abc"),
|
||||
}
|
||||
|
||||
err = svc.Upload(t.Context(), file)
|
||||
require.NoError(t, err)
|
||||
|
||||
os, err := cfg.StoreClient.ListObjects(t.Context(), &s3.ListObjectsInput{
|
||||
Bucket: &cfg.Bucket,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, os.Contents, 1)
|
||||
key := *os.Contents[0].Key
|
||||
|
||||
o, err := cfg.StoreClient.GetObject(t.Context(), &s3.GetObjectInput{
|
||||
Bucket: &cfg.Bucket,
|
||||
Key: &key,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
body, err := io.ReadAll(o.Body)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []byte("abc"), body)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user