90353d8161
Doc Clean Structure * outline * isdocclean * placeholder for clean log * versionplustesting * versionplustesting * testspassed
63 lines
1.4 KiB
Go
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)
|
|
}
|