TestEvents checks that metadata sent using the client is propagated to the corresponding s3 event
(ctx context.Context, oc nodes.StorageClient, req *test.RunTestsRequest, dsConf *object.DataSource)
| 249 | |
| 250 | // TestEvents checks that metadata sent using the client is propagated to the corresponding s3 event |
| 251 | func (h *Handler) TestEvents(ctx context.Context, oc nodes.StorageClient, req *test.RunTestsRequest, dsConf *object.DataSource) (*test.TestResult, error) { |
| 252 | |
| 253 | result := test.NewTestResult("Events Metadata Propagation") |
| 254 | |
| 255 | opts := minio.StatObjectOptions{} |
| 256 | opts.Set(common.PydioContextUserKey, common.PydioSystemUsername) |
| 257 | //authCtx := context.WithValue(context.Background(), common.PydioContextUserKey, common.PydioSystemUsername) |
| 258 | authCtx := propagator.NewContext(context.Background(), map[string]string{common.PydioContextUserKey: common.PydioSystemUsername}) |
| 259 | listenCtx, cancel := context.WithCancel(authCtx) |
| 260 | defer cancel() |
| 261 | |
| 262 | result.Log("Setting up events listener") |
| 263 | eventChan, e := oc.BucketNotifications(listenCtx, dsConf.ObjectsBucket, "", []string{string(notification.ObjectCreatedAll)}) |
| 264 | if e != nil { |
| 265 | return result, e |
| 266 | } |
| 267 | wg := &sync.WaitGroup{} |
| 268 | wg.Add(1) |
| 269 | var receivedInfo notification.Info |
| 270 | go func() { |
| 271 | defer wg.Done() |
| 272 | for { |
| 273 | select { |
| 274 | case i := <-eventChan: |
| 275 | receivedInfo = i.(notification.Info) |
| 276 | return |
| 277 | case <-time.After(10 * time.Second): |
| 278 | fmt.Println("Breaking after timeout - No Events returned!") |
| 279 | return |
| 280 | } |
| 281 | } |
| 282 | }() |
| 283 | key := uuid.New() + ".txt" |
| 284 | content := uuid.New() |
| 285 | <-time.After(3 * time.Second) |
| 286 | if _, e = oc.PutObject(authCtx, dsConf.ObjectsBucket, key, strings.NewReader(content), int64(len(content)), models.PutMeta{}); e != nil { |
| 287 | return result, e |
| 288 | } |
| 289 | |
| 290 | result.Log("PutObject Passed") |
| 291 | defer oc.RemoveObject(authCtx, dsConf.ObjectsBucket, key) |
| 292 | |
| 293 | wg.Wait() |
| 294 | cancel() |
| 295 | |
| 296 | fmt.Println("Finished listening, checking event info: ", receivedInfo) |
| 297 | result.Log("Finished listening, checking event info: ", receivedInfo) |
| 298 | if receivedInfo.Records == nil || len(receivedInfo.Records) == 0 { |
| 299 | return result, errors.New("NotificationInfo is empty") |
| 300 | } |
| 301 | metaFound := false |
| 302 | for _, r := range receivedInfo.Records { |
| 303 | k, e := url.QueryUnescape(r.S3.Object.Key) |
| 304 | if e != nil { |
| 305 | continue |
| 306 | } |
| 307 | if k == key { |
| 308 | if v, ok := r.RequestParameters[common.PydioContextUserKey]; ok && v == common.PydioSystemUsername { |
nothing calls this directly
no test coverage detected