Merged in feature/e2etest (pull request #74)
Feature/e2etest * e2etest * testcleanups
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package document
|
||||
|
||||
import (
|
||||
"context"
|
||||
"queryorchestration/internal/database"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type DocumentInList struct {
|
||||
ID uuid.UUID
|
||||
Bucket string
|
||||
Key string
|
||||
}
|
||||
|
||||
func (s *Service) ListByJobId(ctx context.Context, id uuid.UUID) ([]*DocumentInList, error) {
|
||||
documents, err := s.cfg.GetDBQueries().ListDocumentsByJobId(ctx, database.MustToDBUUID(id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
docs := make([]*DocumentInList, len(documents))
|
||||
for i, doc := range documents {
|
||||
docs[i] = &DocumentInList{
|
||||
ID: database.MustToUUID(doc.ID),
|
||||
Bucket: doc.Bucket,
|
||||
Key: doc.Key,
|
||||
}
|
||||
}
|
||||
|
||||
return docs, nil
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package document_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestListByJobId(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
pool, err := pgxmock.NewPool()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := document.New(cfg)
|
||||
|
||||
jobId := uuid.New()
|
||||
doc := []*document.DocumentInList{
|
||||
{
|
||||
ID: uuid.New(),
|
||||
Bucket: "bucketone",
|
||||
Key: "keyone",
|
||||
},
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: ListDocumentsByJobId :many").WithArgs(database.MustToDBUUID(jobId)).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "bucket", "key"}).
|
||||
AddRow(database.MustToDBUUID(doc[0].ID), doc[0].Bucket, doc[0].Key),
|
||||
)
|
||||
|
||||
adoc, err := svc.ListByJobId(ctx, jobId)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, doc, adoc)
|
||||
}
|
||||
Reference in New Issue
Block a user