Merged in feature/document (pull request #36)

Document CRUD

* doccreate

* dochashlocandget

* depsandtodo
This commit is contained in:
Michael McGuinness
2025-01-24 16:12:25 +00:00
parent 4ec1d51a12
commit b16ff55afa
31 changed files with 381 additions and 82 deletions
+46
View File
@@ -0,0 +1,46 @@
package document_test
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 TestGet(t *testing.T) {
ctx := context.Background()
pool, err := pgxmock.NewPool()
if err != nil {
t.Fatalf("failed to open pgxmock database: %v", err)
}
queries := repository.New(pool)
db := &database.Connection{
Queries: queries,
Pool: pool,
}
svc := document.New(db)
doc := document.Document{
ID: uuid.New(),
JobID: uuid.New(),
Hash: "example_hash",
Location: "example_location",
}
pool.ExpectQuery("name: GetDocument :one").WithArgs(database.MustToDBUUID(doc.ID)).
WillReturnRows(
pgxmock.NewRows([]string{"id", "jobId", "hash", "location"}).
AddRow(database.MustToDBUUID(doc.ID), database.MustToDBUUID(doc.JobID), doc.Hash, doc.Location),
)
adoc, err := svc.Get(ctx, doc.ID)
assert.Nil(t, err)
assert.Equal(t, &doc, adoc)
}