Merged in feature/localstackands3object (pull request #54)
LocalStack and S3 Objects * firstround * cleanupintegration * tidyports
This commit is contained in:
@@ -16,7 +16,6 @@ import (
|
||||
queuemock "queryorchestration/mocks/queue"
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
||||
"github.com/google/uuid"
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
@@ -82,22 +81,11 @@ func TestCreate(t *testing.T) {
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
mockStore.EXPECT().
|
||||
HeadObject(
|
||||
mock.Anything,
|
||||
mock.MatchedBy(func(in *s3.HeadObjectInput) bool {
|
||||
return *in.Bucket == bucket && *in.Key == location
|
||||
}),
|
||||
mock.Anything,
|
||||
).
|
||||
Return(&s3.HeadObjectOutput{
|
||||
ETag: &doc.Hash,
|
||||
}, nil)
|
||||
|
||||
id, err := svc.Create(ctx, &Create{
|
||||
JobID: doc.JobID,
|
||||
Location: location,
|
||||
Bucket: bucket,
|
||||
Hash: doc.Hash,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, doc.ID, id)
|
||||
@@ -164,22 +152,11 @@ func TestGetCreateParams(t *testing.T) {
|
||||
pgxmock.NewRows([]string{"id"}),
|
||||
)
|
||||
|
||||
mockStore.EXPECT().
|
||||
HeadObject(
|
||||
mock.Anything,
|
||||
mock.MatchedBy(func(in *s3.HeadObjectInput) bool {
|
||||
return *in.Bucket == bucket && *in.Key == location
|
||||
}),
|
||||
mock.Anything,
|
||||
).
|
||||
Return(&s3.HeadObjectOutput{
|
||||
ETag: &doc.Hash,
|
||||
}, nil)
|
||||
|
||||
params, err := svc.getCreateParams(ctx, &Create{
|
||||
JobID: doc.JobID,
|
||||
Location: location,
|
||||
Bucket: bucket,
|
||||
Hash: doc.Hash,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, &createDocumentParams{
|
||||
@@ -222,22 +199,11 @@ func TestGetCreateParamsExisting(t *testing.T) {
|
||||
AddRow(database.MustToDBUUID(doc.ID)),
|
||||
)
|
||||
|
||||
mockStore.EXPECT().
|
||||
HeadObject(
|
||||
mock.Anything,
|
||||
mock.MatchedBy(func(in *s3.HeadObjectInput) bool {
|
||||
return *in.Bucket == bucket && *in.Key == location
|
||||
}),
|
||||
mock.Anything,
|
||||
).
|
||||
Return(&s3.HeadObjectOutput{
|
||||
ETag: &doc.Hash,
|
||||
}, nil)
|
||||
|
||||
params, err := svc.getCreateParams(ctx, &Create{
|
||||
JobID: doc.JobID,
|
||||
Location: location,
|
||||
Bucket: bucket,
|
||||
Hash: doc.Hash,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
dbid := database.MustToDBUUID(doc.ID)
|
||||
@@ -279,18 +245,6 @@ func TestGetCreateParamsCurrentDocErr(t *testing.T) {
|
||||
pool.ExpectQuery("-- name: GetDocumentIDByHash :one").WithArgs(doc.Hash, database.MustToDBUUID(doc.JobID)).
|
||||
WillReturnError(errors.New("db err"))
|
||||
|
||||
mockStore.EXPECT().
|
||||
HeadObject(
|
||||
mock.Anything,
|
||||
mock.MatchedBy(func(in *s3.HeadObjectInput) bool {
|
||||
return *in.Bucket == bucket && *in.Key == location
|
||||
}),
|
||||
mock.Anything,
|
||||
).
|
||||
Return(&s3.HeadObjectOutput{
|
||||
ETag: &doc.Hash,
|
||||
}, nil)
|
||||
|
||||
_, err = svc.getCreateParams(ctx, &Create{
|
||||
JobID: doc.JobID,
|
||||
Location: location,
|
||||
@@ -385,3 +339,21 @@ func TestSubmitCreateExists(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, doc.ID, id)
|
||||
}
|
||||
|
||||
func TestGetJobIDFromKey(t *testing.T) {
|
||||
svc := Service{}
|
||||
|
||||
_, err := svc.GetJobIDFromKey("")
|
||||
assert.Error(t, err)
|
||||
|
||||
_, err = svc.GetJobIDFromKey("jkhaskhweuifhwhieh")
|
||||
assert.Error(t, err)
|
||||
|
||||
_, err = svc.GetJobIDFromKey("aaa/bbb/ccc")
|
||||
assert.Error(t, err)
|
||||
|
||||
id := uuid.New()
|
||||
aid, err := svc.GetJobIDFromKey(fmt.Sprintf("aaa/%s/bbb", id.String()))
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, id, aid)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user