Skip to content

Commit

Permalink
Add S3 Batch Operations 2.0 Schema Fields to S3BatchJob/S3BatchJobTask (
Browse files Browse the repository at this point in the history
#550)

* Add S3 Batch Operations 2.0 Schema Fields

* Create s3-batch-job-event-request-2.0.json

* Update s3_batch_job_test.go

* Rename s3-batch-job-event-request.json to s3-batch-job-event-request-1.0.json

* Fix tests

* Split into S3BatchJobV2
  • Loading branch information
lyoung-confluent committed Jan 29, 2024
1 parent 58da2cc commit eae55b8
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
22 changes: 22 additions & 0 deletions events/s3_batch_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,28 @@ type S3BatchJobTask struct {
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
type S3BatchJobResponse struct {
InvocationSchemaVersion string `json:"invocationSchemaVersion"`
Expand Down
22 changes: 21 additions & 1 deletion events/s3_batch_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func TestS3BatchJobEventMarshaling(t *testing.T) {

// 1. read JSON from file
inputJSON := test.ReadJSONFromFile(t, "./testdata/s3-batch-job-event-request.json")
inputJSON := test.ReadJSONFromFile(t, "./testdata/s3-batch-job-event-request-1.0.json")

// 2. de-serialize into Go object
var inputEvent S3BatchJobEvent
Expand All @@ -31,6 +31,26 @@ func TestS3BatchJobEventMarshaling(t *testing.T) {
assert.JSONEq(t, string(inputJSON), string(outputJSON))
}

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 S3BatchJobEventV2
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
t.Errorf("could not unmarshal event. details: %v", err)
}

// 3. serialize to JSON
outputJSON, err := json.Marshal(inputEvent)
if err != nil {
t.Errorf("could not marshal event. details: %v", err)
}

// 4. check result
assert.JSONEq(t, string(inputJSON), string(outputJSON))
}

func TestS3BatchJobResponseMarshaling(t *testing.T) {

// 1. read JSON from file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"s3BucketArn": "arn:aws:s3:us-east-1:0123456788:awsexamplebucket"
}
]
}
}
19 changes: 19 additions & 0 deletions events/testdata/s3-batch-job-event-request-2.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"invocationSchemaVersion": "2.0",
"invocationId": "YXNkbGZqYWRmaiBhc2RmdW9hZHNmZGpmaGFzbGtkaGZza2RmaAo",
"job": {
"id": "f3cc4f60-61f6-4a2b-8a21-d07600c373ce",
"userArguments": {
"k1": "v1",
"k2": "v2"
}
},
"tasks": [
{
"taskId": "dGFza2lkZ29lc2hlcmUK",
"s3Key": "customerImage1.jpg",
"s3VersionId": "jbo9_jhdPEyB4RrmOxWS0kU0EoNrU_oI",
"s3Bucket": "awsexamplebucket"
}
]
}

0 comments on commit eae55b8

Please sign in to comment.