Files
query-orchestration/internal/document/upload/get_test.go
T
Jay Brown 720a84be92 Merged in feature/doc_import (pull request #177)
integration of background processor

* integration part 1

* feature working

* fix mimetype issue
2025-08-20 19:01:13 +00:00

70 lines
1.5 KiB
Go

package documentupload_test
import (
"io"
"log"
"strings"
"testing"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/serviceconfig"
"queryorchestration/internal/serviceconfig/objectstore"
"queryorchestration/internal/test"
documentupload "queryorchestration/internal/document/upload"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type Config struct {
serviceconfig.BaseConfig
objectstore.ObjectStoreConfig
}
func TestUpload(t *testing.T) {
t.Parallel()
cfg := &Config{}
test.CreateDB(t, cfg)
acfg := test.CreateAWSContainer(t, cfg)
test.SetStoreClient(t, t.Context(), cfg, acfg.ExternalEndpoint)
test.CreateBucket(t, cfg)
err := cfg.GetDBQueries().CreateClient(t.Context(), &repository.CreateClientParams{
Clientid: "client_id",
Name: "client",
})
require.NoError(t, err)
svc := documentupload.New(cfg)
file := documentupload.File{
ClientID: "client_id",
Content: strings.NewReader("abc"),
Filename: "test.txt",
}
log.Print("test")
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)
}