Files
query-orchestration/internal/document/clean/clean_test.go
T
Michael McGuinness 90353d8161 Merged in feature/docclean (pull request #55)
Doc Clean Structure

* outline

* isdocclean

* placeholder for clean log

* versionplustesting

* versionplustesting

* testspassed
2025-02-07 12:12:51 +00:00

63 lines
1.4 KiB
Go

package documentclean
import (
"context"
"queryorchestration/internal/database"
"queryorchestration/internal/database/repository"
"queryorchestration/internal/document"
"testing"
"github.com/google/uuid"
"github.com/pashagolub/pgxmock/v3"
"github.com/stretchr/testify/assert"
)
func TestClean(t *testing.T) {
ctx := context.Background()
pool, err := pgxmock.NewPool()
if err != nil {
t.Fatalf("failed to open pgxmock database: %v", err)
}
cfg := &DocCleanConfig{}
cfg.DBPool = pool
cfg.DBQueries = repository.New(pool)
svc := Service{
cfg: cfg,
svc: &Services{
Document: document.New(cfg),
},
}
id := uuid.New()
inloc := document.Location{
Bucket: "bucket_name",
Key: "/i/am/here",
}
pool.ExpectQuery("name: GetDocumentEntry :one").WithArgs(database.MustToDBUUID(id)).WillReturnRows(
pgxmock.NewRows([]string{"documentId", "bucket", "key"}).
AddRow(database.MustToDBUUID(id), inloc.Bucket, inloc.Key),
)
pool.ExpectExec("name: AddDocumentCleanEntry :exec").WithArgs(database.MustToDBUUID(id), int32(1), inloc.Bucket, inloc.Key).
WillReturnResult(pgxmock.NewResult("", 1))
err = svc.clean(ctx, id)
assert.NoError(t, err)
}
func TestExecuteCleanTasks(t *testing.T) {
svc := Service{}
id := uuid.New()
location := document.Location{}
outloc, err := svc.executeCleanTasks(&CleanParams{
ID: id,
Location: location,
})
assert.NoError(t, err)
assert.EqualExportedValues(t, location, *outloc)
}