From b94adbed0e47c0679922332463322e2872fcc0a6 Mon Sep 17 00:00:00 2001 From: Luke Young Date: Fri, 26 Jan 2024 19:53:45 -0800 Subject: [PATCH] Split into S3BatchJobV2 --- events/s3_batch_job.go | 28 ++++++++++++++++--- events/s3_batch_job_test.go | 6 ++-- .../s3-batch-job-event-request-2.0.json | 6 ++-- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/events/s3_batch_job.go b/events/s3_batch_job.go index c84f45a2..183ec907 100644 --- a/events/s3_batch_job.go +++ b/events/s3_batch_job.go @@ -12,8 +12,7 @@ type S3BatchJobEvent struct { // S3BatchJob whichs have the job id type S3BatchJob struct { - ID string `json:"id"` - UserArguments map[string]string `json:"userArguments,omitempty"` + ID string `json:"id"` } // S3BatchJobTask represents one task in the s3 batch job and have all task details @@ -21,8 +20,29 @@ type S3BatchJobTask struct { TaskID string `json:"taskId"` S3Key string `json:"s3Key"` S3VersionID string `json:"s3VersionId"` - S3Bucket string `json:"s3Bucket,omitempty"` - S3BucketARN string `json:"s3BucketArn,omitempty"` + S3BucketARN string `json:"s3BucketArn"` +} + +// S3BatchJobEventV2 encapsulates the detail of a s3 batch job +type S3BatchJobEventV2 struct { + InvocationSchemaVersion string `json:"invocationSchemaVersion"` + InvocationID string `json:"invocationId"` + Job S3BatchJobV2 `json:"job"` + Tasks []S3BatchJobTaskV2 `json:"tasks"` +} + +// S3BatchJobV2 whichs have the job id +type S3BatchJobV2 struct { + ID string `json:"id"` + UserArguments map[string]string `json:"userArguments"` +} + +// S3BatchJobTaskV2 represents one task in the s3 batch job and have all task details +type S3BatchJobTaskV2 struct { + TaskID string `json:"taskId"` + S3Key string `json:"s3Key"` + S3VersionID string `json:"s3VersionId"` + S3Bucket string `json:"s3Bucket"` } // S3BatchJobResponse is the response of a iven s3 batch job with the results diff --git a/events/s3_batch_job_test.go b/events/s3_batch_job_test.go index fd14ddd4..3067c256 100644 --- a/events/s3_batch_job_test.go +++ b/events/s3_batch_job_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestS3BatchJobEventMarshalingSchema1(t *testing.T) { +func TestS3BatchJobEventMarshaling(t *testing.T) { // 1. read JSON from file inputJSON := test.ReadJSONFromFile(t, "./testdata/s3-batch-job-event-request-1.0.json") @@ -31,12 +31,12 @@ func TestS3BatchJobEventMarshalingSchema1(t *testing.T) { assert.JSONEq(t, string(inputJSON), string(outputJSON)) } -func TestS3BatchJobEventMarshalingSchema2(t *testing.T) { +func TestS3BatchJobEventV2Marshaling(t *testing.T) { // 1. read JSON from file inputJSON := test.ReadJSONFromFile(t, "./testdata/s3-batch-job-event-request-2.0.json") // 2. de-serialize into Go object - var inputEvent S3BatchJobEvent + var inputEvent S3BatchJobEventV2 if err := json.Unmarshal(inputJSON, &inputEvent); err != nil { t.Errorf("could not unmarshal event. details: %v", err) } diff --git a/events/testdata/s3-batch-job-event-request-2.0.json b/events/testdata/s3-batch-job-event-request-2.0.json index 3e2c3d7a..738339cc 100644 --- a/events/testdata/s3-batch-job-event-request-2.0.json +++ b/events/testdata/s3-batch-job-event-request-2.0.json @@ -11,9 +11,9 @@ "tasks": [ { "taskId": "dGFza2lkZ29lc2hlcmUK", - "s3Key": "prefix/dataset/dataset.20231222.json.gz", - "s3VersionId": "1", - "s3Bucket": "powertools-dataset" + "s3Key": "customerImage1.jpg", + "s3VersionId": "jbo9_jhdPEyB4RrmOxWS0kU0EoNrU_oI", + "s3Bucket": "awsexamplebucket" } ] }