@@ -56,3 +56,148 @@ func TestS3TestEventMarshaling(t *testing.T) {
5656func TestS3MarshalingMalformedJSON (t * testing.T ) {
5757 test .TestMalformedJson (t , S3Event {})
5858}
59+
60+ func TestS3GlacierEventMarshaling (t * testing.T ) {
61+ // 1. read JSON from file
62+ inputJSON := test .ReadJSONFromFile (t , "./testdata/s3-glacier-event.json" )
63+
64+ // 2. de-serialize into Go object
65+ var inputEvent S3Event
66+ if err := json .Unmarshal (inputJSON , & inputEvent ); err != nil {
67+ t .Errorf ("could not unmarshal event. details: %v" , err )
68+ }
69+
70+ // 3. verify glacierEventData is correctly parsed
71+ if inputEvent .Records [0 ].GlacierEventData == nil {
72+ t .Error ("glacierEventData should not be nil for glacier restore events" )
73+ }
74+
75+ // 4. verify restoreEventData is correctly parsed
76+ if inputEvent .Records [0 ].GlacierEventData .RestoreEventData == nil {
77+ t .Error ("restoreEventData should not be nil" )
78+ }
79+
80+ // 5. serialize to JSON
81+ outputJSON , err := json .Marshal (inputEvent )
82+ if err != nil {
83+ t .Errorf ("could not marshal event. details: %v" , err )
84+ }
85+
86+ // 6. check result
87+ assert .JSONEq (t , string (inputJSON ), string (outputJSON ))
88+ }
89+
90+ func TestS3RestoreEventMarshaling (t * testing.T ) {
91+ // 1. read JSON from file
92+ inputJSON := test .ReadJSONFromFile (t , "./testdata/s3-restore-event.json" )
93+
94+ // 2. de-serialize into Go object
95+ var inputEvent S3Event
96+ if err := json .Unmarshal (inputJSON , & inputEvent ); err != nil {
97+ t .Errorf ("could not unmarshal event. details: %v" , err )
98+ }
99+
100+ // 3. verify restoreEventData is correctly parsed
101+ if inputEvent .Records [0 ].RestoreEventData == nil {
102+ t .Error ("restoreEventData should not be nil" )
103+ }
104+
105+ // 4. serialize to JSON
106+ outputJSON , err := json .Marshal (inputEvent )
107+ if err != nil {
108+ t .Errorf ("could not marshal event. details: %v" , err )
109+ }
110+
111+ // 5. check result
112+ assert .JSONEq (t , string (inputJSON ), string (outputJSON ))
113+ }
114+
115+ func TestS3IntelligentTieringEventMarshaling (t * testing.T ) {
116+ // 1. read JSON from file
117+ inputJSON := test .ReadJSONFromFile (t , "./testdata/s3-intelligenttier-event.json" )
118+
119+ // 2. de-serialize into Go object
120+ var inputEvent S3Event
121+ if err := json .Unmarshal (inputJSON , & inputEvent ); err != nil {
122+ t .Errorf ("could not unmarshal event. details: %v" , err )
123+ }
124+
125+ // 3. verify intelligentTieringEventData is correctly parsed
126+ if inputEvent .Records [0 ].IntelligentTieringEventData == nil {
127+ t .Error ("intelligentTieringEventData should not be nil for intelligent tiering events" )
128+ }
129+
130+ // 4. verify destinationAccessTier is correctly parsed
131+ if inputEvent .Records [0 ].IntelligentTieringEventData .DestinationAccessTier == "" {
132+ t .Error ("destinationAccessTier should not be empty" )
133+ }
134+
135+ // 5. serialize to JSON
136+ outputJSON , err := json .Marshal (inputEvent )
137+ if err != nil {
138+ t .Errorf ("could not marshal event. details: %v" , err )
139+ }
140+
141+ // 6. check result
142+ assert .JSONEq (t , string (inputJSON ), string (outputJSON ))
143+ }
144+
145+ func TestS3LifecycleEventMarshaling (t * testing.T ) {
146+ // 1. read JSON from file
147+ inputJSON := test .ReadJSONFromFile (t , "./testdata/s3-lifecycle-event.json" )
148+
149+ // 2. de-serialize into Go object
150+ var inputEvent S3Event
151+ if err := json .Unmarshal (inputJSON , & inputEvent ); err != nil {
152+ t .Errorf ("could not unmarshal event. details: %v" , err )
153+ }
154+
155+ // 3. verify lifecycleEventData is correctly parsed
156+ if inputEvent .Records [0 ].LifecycleEventData == nil {
157+ t .Error ("lifecycleEventData should not be nil for lifecycle events" )
158+ }
159+
160+ // 4. verify transitionEventData is correctly parsed
161+ if inputEvent .Records [0 ].LifecycleEventData .TransitionEventData == nil {
162+ t .Error ("transitionEventData should not be nil" )
163+ }
164+
165+ // 5. verify destinationStorageClass is correctly parsed
166+ if inputEvent .Records [0 ].LifecycleEventData .TransitionEventData .DestinationStorageClass == "" {
167+ t .Error ("destinationStorageClass should not be empty" )
168+ }
169+
170+ // 6. serialize to JSON
171+ outputJSON , err := json .Marshal (inputEvent )
172+ if err != nil {
173+ t .Errorf ("could not marshal event. details: %v" , err )
174+ }
175+
176+ // 7. check result
177+ assert .JSONEq (t , string (inputJSON ), string (outputJSON ))
178+ }
179+
180+ func TestS3ReplicationEventMarshaling (t * testing.T ) {
181+ // 1. read JSON from file
182+ inputJSON := test .ReadJSONFromFile (t , "./testdata/s3-replication-event.json" )
183+
184+ // 2. de-serialize into Go object
185+ var inputEvent S3Event
186+ if err := json .Unmarshal (inputJSON , & inputEvent ); err != nil {
187+ t .Errorf ("could not unmarshal event. details: %v" , err )
188+ }
189+
190+ // 3. verify replicationEventData is correctly parsed
191+ if inputEvent .Records [0 ].ReplicationEventData == nil {
192+ t .Error ("replicationEventData should not be nil for replication events" )
193+ }
194+
195+ // 4. serialize to JSON
196+ outputJSON , err := json .Marshal (inputEvent )
197+ if err != nil {
198+ t .Errorf ("could not marshal event. details: %v" , err )
199+ }
200+
201+ // 5. check result
202+ assert .JSONEq (t , string (inputJSON ), string (outputJSON ))
203+ }
0 commit comments