Skip to content

Commit eae55b8

Browse files
Add S3 Batch Operations 2.0 Schema Fields to S3BatchJob/S3BatchJobTask (#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
1 parent 58da2cc commit eae55b8

4 files changed

+63
-2
lines changed

events/s3_batch_job.go

+22
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,28 @@ type S3BatchJobTask struct {
2323
S3BucketARN string `json:"s3BucketArn"`
2424
}
2525

26+
// S3BatchJobEventV2 encapsulates the detail of a s3 batch job
27+
type S3BatchJobEventV2 struct {
28+
InvocationSchemaVersion string `json:"invocationSchemaVersion"`
29+
InvocationID string `json:"invocationId"`
30+
Job S3BatchJobV2 `json:"job"`
31+
Tasks []S3BatchJobTaskV2 `json:"tasks"`
32+
}
33+
34+
// S3BatchJobV2 whichs have the job id
35+
type S3BatchJobV2 struct {
36+
ID string `json:"id"`
37+
UserArguments map[string]string `json:"userArguments"`
38+
}
39+
40+
// S3BatchJobTaskV2 represents one task in the s3 batch job and have all task details
41+
type S3BatchJobTaskV2 struct {
42+
TaskID string `json:"taskId"`
43+
S3Key string `json:"s3Key"`
44+
S3VersionID string `json:"s3VersionId"`
45+
S3Bucket string `json:"s3Bucket"`
46+
}
47+
2648
// S3BatchJobResponse is the response of a iven s3 batch job with the results
2749
type S3BatchJobResponse struct {
2850
InvocationSchemaVersion string `json:"invocationSchemaVersion"`

events/s3_batch_job_test.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
func TestS3BatchJobEventMarshaling(t *testing.T) {
1414

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

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

34+
func TestS3BatchJobEventV2Marshaling(t *testing.T) {
35+
// 1. read JSON from file
36+
inputJSON := test.ReadJSONFromFile(t, "./testdata/s3-batch-job-event-request-2.0.json")
37+
38+
// 2. de-serialize into Go object
39+
var inputEvent S3BatchJobEventV2
40+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
41+
t.Errorf("could not unmarshal event. details: %v", err)
42+
}
43+
44+
// 3. serialize to JSON
45+
outputJSON, err := json.Marshal(inputEvent)
46+
if err != nil {
47+
t.Errorf("could not marshal event. details: %v", err)
48+
}
49+
50+
// 4. check result
51+
assert.JSONEq(t, string(inputJSON), string(outputJSON))
52+
}
53+
3454
func TestS3BatchJobResponseMarshaling(t *testing.T) {
3555

3656
// 1. read JSON from file

events/testdata/s3-batch-job-event-request.json events/testdata/s3-batch-job-event-request-1.0.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"s3BucketArn": "arn:aws:s3:us-east-1:0123456788:awsexamplebucket"
1313
}
1414
]
15-
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"invocationSchemaVersion": "2.0",
3+
"invocationId": "YXNkbGZqYWRmaiBhc2RmdW9hZHNmZGpmaGFzbGtkaGZza2RmaAo",
4+
"job": {
5+
"id": "f3cc4f60-61f6-4a2b-8a21-d07600c373ce",
6+
"userArguments": {
7+
"k1": "v1",
8+
"k2": "v2"
9+
}
10+
},
11+
"tasks": [
12+
{
13+
"taskId": "dGFza2lkZ29lc2hlcmUK",
14+
"s3Key": "customerImage1.jpg",
15+
"s3VersionId": "jbo9_jhdPEyB4RrmOxWS0kU0EoNrU_oI",
16+
"s3Bucket": "awsexamplebucket"
17+
}
18+
]
19+
}

0 commit comments

Comments
 (0)