Merged in feature/richname (pull request #112)
Standardised rich name for Files * tests
This commit is contained in:
@@ -5,9 +5,11 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
"queryorchestration/internal/serviceconfig/objectstore"
|
||||
queuemock "queryorchestration/mocks/queue"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -39,9 +41,12 @@ func TestCreate(t *testing.T) {
|
||||
ClientID: clientId,
|
||||
Hash: "example_hash",
|
||||
}
|
||||
location := document.Location{
|
||||
Bucket: "example_bucket",
|
||||
Key: "/i/am/here",
|
||||
bucket := "example_bucket"
|
||||
key := objectstore.BucketKey{
|
||||
ClientID: doc.ClientID,
|
||||
CreatedAt: time.Now().UTC(),
|
||||
EntityID: uuid.New(),
|
||||
Location: objectstore.Import,
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: GetDocumentIDByHash :one").WithArgs(doc.Hash, doc.ClientID).WillReturnRows(
|
||||
@@ -53,7 +58,7 @@ func TestCreate(t *testing.T) {
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(doc.ID),
|
||||
)
|
||||
pool.ExpectExec("name: AddDocumentEntry :exec").WithArgs(doc.ID, location.Bucket, location.Key).
|
||||
pool.ExpectExec("name: AddDocumentEntry :exec").WithArgs(doc.ID, bucket, key.String()).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(doc.ID).
|
||||
@@ -81,9 +86,9 @@ func TestCreate(t *testing.T) {
|
||||
Return(&sqs.SendMessageOutput{}, nil)
|
||||
|
||||
id, err := svc.Create(ctx, &Create{
|
||||
ClientID: doc.ClientID,
|
||||
Location: location,
|
||||
Hash: doc.Hash,
|
||||
Hash: doc.Hash,
|
||||
Key: key,
|
||||
Bucket: bucket,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, doc.ID, id)
|
||||
@@ -104,9 +109,12 @@ func TestGetCreateParams(t *testing.T) {
|
||||
ClientID: "hello",
|
||||
Hash: "example_hash",
|
||||
}
|
||||
location := document.Location{
|
||||
Bucket: "example_bucket",
|
||||
Key: "/i/am/here",
|
||||
bucket := "example_bucket"
|
||||
key := objectstore.BucketKey{
|
||||
ClientID: doc.ClientID,
|
||||
CreatedAt: time.Now().UTC(),
|
||||
EntityID: uuid.New(),
|
||||
Location: objectstore.Import,
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: GetDocumentIDByHash :one").WithArgs(doc.Hash, doc.ClientID).WillReturnRows(
|
||||
@@ -114,15 +122,15 @@ func TestGetCreateParams(t *testing.T) {
|
||||
)
|
||||
|
||||
params, err := svc.getCreateParams(ctx, &Create{
|
||||
ClientID: doc.ClientID,
|
||||
Location: location,
|
||||
Hash: doc.Hash,
|
||||
Hash: doc.Hash,
|
||||
Bucket: bucket,
|
||||
Key: key,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, &createDocumentParams{
|
||||
ClientID: doc.ClientID,
|
||||
Hash: doc.Hash,
|
||||
Location: location,
|
||||
Hash: doc.Hash,
|
||||
Bucket: bucket,
|
||||
Key: key,
|
||||
}, params)
|
||||
}
|
||||
|
||||
@@ -142,9 +150,12 @@ func TestGetCreateParamsExisting(t *testing.T) {
|
||||
ClientID: "hello",
|
||||
Hash: "example_hash",
|
||||
}
|
||||
location := document.Location{
|
||||
Bucket: "example_bucket",
|
||||
Key: "/i/am/here",
|
||||
bucket := "example_bucket"
|
||||
key := objectstore.BucketKey{
|
||||
ClientID: doc.ClientID,
|
||||
CreatedAt: time.Now().UTC(),
|
||||
EntityID: uuid.New(),
|
||||
Location: objectstore.Import,
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: GetDocumentIDByHash :one").WithArgs(doc.Hash, doc.ClientID).WillReturnRows(
|
||||
@@ -153,17 +164,17 @@ func TestGetCreateParamsExisting(t *testing.T) {
|
||||
)
|
||||
|
||||
params, err := svc.getCreateParams(ctx, &Create{
|
||||
ClientID: doc.ClientID,
|
||||
Location: location,
|
||||
Hash: doc.Hash,
|
||||
Bucket: bucket,
|
||||
Key: key,
|
||||
Hash: doc.Hash,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
dbid := doc.ID
|
||||
assert.Equal(t, &createDocumentParams{
|
||||
ID: &dbid,
|
||||
ClientID: doc.ClientID,
|
||||
Hash: doc.Hash,
|
||||
Location: location,
|
||||
ID: &dbid,
|
||||
Hash: doc.Hash,
|
||||
Bucket: bucket,
|
||||
Key: key,
|
||||
}, params)
|
||||
}
|
||||
|
||||
@@ -182,17 +193,20 @@ func TestGetCreateParamsCurrentDocErr(t *testing.T) {
|
||||
ClientID: "hello",
|
||||
Hash: "example_hash",
|
||||
}
|
||||
location := document.Location{
|
||||
Bucket: "example_bucket",
|
||||
Key: "/i/am/here",
|
||||
bucket := "example_bucket"
|
||||
key := objectstore.BucketKey{
|
||||
ClientID: doc.ClientID,
|
||||
CreatedAt: time.Now().UTC(),
|
||||
EntityID: uuid.New(),
|
||||
Location: objectstore.Import,
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: GetDocumentIDByHash :one").WithArgs(doc.Hash, doc.ClientID).
|
||||
WillReturnError(errors.New("db err"))
|
||||
|
||||
_, err = svc.getCreateParams(ctx, &Create{
|
||||
ClientID: doc.ClientID,
|
||||
Location: location,
|
||||
Bucket: bucket,
|
||||
Key: key,
|
||||
})
|
||||
assert.Error(t, err)
|
||||
}
|
||||
@@ -213,9 +227,12 @@ func TestSubmitCreate(t *testing.T) {
|
||||
ClientID: "hello",
|
||||
Hash: "example_hash",
|
||||
}
|
||||
location := document.Location{
|
||||
Bucket: "example_bucket",
|
||||
Key: "/i/am/here",
|
||||
bucket := "example_bucket"
|
||||
key := objectstore.BucketKey{
|
||||
ClientID: doc.ClientID,
|
||||
CreatedAt: time.Now().UTC(),
|
||||
EntityID: uuid.New(),
|
||||
Location: objectstore.Import,
|
||||
}
|
||||
|
||||
pool.ExpectBegin()
|
||||
@@ -224,14 +241,14 @@ func TestSubmitCreate(t *testing.T) {
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(doc.ID),
|
||||
)
|
||||
pool.ExpectExec("name: AddDocumentEntry :exec").WithArgs(doc.ID, location.Bucket, location.Key).
|
||||
pool.ExpectExec("name: AddDocumentEntry :exec").WithArgs(doc.ID, bucket, key.String()).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
id, err := svc.submitCreate(ctx, &createDocumentParams{
|
||||
ClientID: doc.ClientID,
|
||||
Location: location,
|
||||
Hash: doc.Hash,
|
||||
Hash: doc.Hash,
|
||||
Bucket: bucket,
|
||||
Key: key,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, doc.ID, id)
|
||||
@@ -253,22 +270,25 @@ func TestSubmitCreateExists(t *testing.T) {
|
||||
ClientID: "hello",
|
||||
Hash: "example_hash",
|
||||
}
|
||||
location := document.Location{
|
||||
Bucket: "example_bucket",
|
||||
Key: "/i/am/here",
|
||||
bucket := "example_bucket"
|
||||
key := objectstore.BucketKey{
|
||||
ClientID: doc.ClientID,
|
||||
CreatedAt: time.Now().UTC(),
|
||||
EntityID: uuid.New(),
|
||||
Location: objectstore.Import,
|
||||
}
|
||||
|
||||
pool.ExpectBegin()
|
||||
pool.ExpectExec("name: AddDocumentEntry :exec").WithArgs(doc.ID, location.Bucket, location.Key).
|
||||
pool.ExpectExec("name: AddDocumentEntry :exec").WithArgs(doc.ID, bucket, key.String()).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
docid := doc.ID
|
||||
id, err := svc.submitCreate(ctx, &createDocumentParams{
|
||||
ID: &docid,
|
||||
ClientID: doc.ClientID,
|
||||
Location: location,
|
||||
Hash: doc.Hash,
|
||||
ID: &docid,
|
||||
Hash: doc.Hash,
|
||||
Bucket: bucket,
|
||||
Key: key,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, doc.ID, id)
|
||||
|
||||
Reference in New Issue
Block a user