2025-04-22 14:40:16 +00:00
|
|
|
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"
|
|
|
|
|
)
|
|
|
|
|
|
2025-04-25 17:02:50 +00:00
|
|
|
func GetTextractFileResponse(t testing.TB, filename string) []map[string]*textract.AnalyzeDocumentOutput {
|
2025-04-22 14:40:16 +00:00
|
|
|
file, err := os.Open(filename)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
|
|
decoder := json.NewDecoder(file)
|
2025-04-25 17:02:50 +00:00
|
|
|
var out []map[string]*textract.AnalyzeDocumentOutput
|
2025-04-22 14:40:16 +00:00
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|