37 lines
893 B
Go
37 lines
893 B
Go
|
|
package test
|
||
|
|
|
||
|
|
import (
|
||
|
|
"encoding/json"
|
||
|
|
"io"
|
||
|
|
"os"
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
"github.com/aws/aws-sdk-go-v2/service/textract"
|
||
|
|
"github.com/google/go-cmp/cmp"
|
||
|
|
"github.com/stretchr/testify/assert"
|
||
|
|
"github.com/stretchr/testify/require"
|
||
|
|
)
|
||
|
|
|
||
|
|
func GetTextractFileResponse(t testing.TB, filename string) map[string][]textract.DetectDocumentTextOutput {
|
||
|
|
file, err := os.Open(filename)
|
||
|
|
require.NoError(t, err)
|
||
|
|
defer file.Close()
|
||
|
|
|
||
|
|
decoder := json.NewDecoder(file)
|
||
|
|
var out map[string][]textract.DetectDocumentTextOutput
|
||
|
|
err = decoder.Decode(&out)
|
||
|
|
require.NoError(t, err)
|
||
|
|
|
||
|
|
return out
|
||
|
|
}
|
||
|
|
|
||
|
|
func AssertStringToReader(t testing.TB, expected string, actual io.Reader) {
|
||
|
|
actualBytes, err := io.ReadAll(actual)
|
||
|
|
require.NoError(t, err)
|
||
|
|
actualStr := string(actualBytes)
|
||
|
|
if !assert.Equal(t, expected, actualStr) {
|
||
|
|
diff := cmp.Diff(expected, actualStr)
|
||
|
|
t.Logf("Detailed diff (-expected +actual):\n%s", diff)
|
||
|
|
}
|
||
|
|
}
|