2016-08-05 01:01:58 -04:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2016 Minio, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-08-05 01:01:58 -04:00
|
|
|
|
2016-09-10 05:23:28 -04:00
|
|
|
import (
|
2016-09-29 01:46:19 -04:00
|
|
|
"fmt"
|
2016-10-12 04:03:50 -04:00
|
|
|
"net"
|
2016-09-10 05:23:28 -04:00
|
|
|
"reflect"
|
2016-10-12 04:03:50 -04:00
|
|
|
"strconv"
|
2016-09-10 05:23:28 -04:00
|
|
|
"testing"
|
2016-09-16 17:26:05 -04:00
|
|
|
"time"
|
2016-09-10 05:23:28 -04:00
|
|
|
)
|
|
|
|
|
2016-09-16 17:26:05 -04:00
|
|
|
// Test InitEventNotifier with faulty disks
|
|
|
|
func TestInitEventNotifierFaultyDisks(t *testing.T) {
|
|
|
|
// Prepare for tests
|
|
|
|
rootPath, err := newTestConfig("us-east-1")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Init Test config failed")
|
|
|
|
}
|
|
|
|
// remove the root folder after the test ends.
|
|
|
|
defer removeAll(rootPath)
|
|
|
|
|
2016-10-18 15:49:24 -04:00
|
|
|
disks, err := getRandomDisks(1)
|
2016-09-16 17:26:05 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Unable to create directories for FS backend. ", err)
|
|
|
|
}
|
2016-10-18 15:49:24 -04:00
|
|
|
defer removeAll(disks[0])
|
|
|
|
endpoints, err := parseStorageEndPoints(disks, 0)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
obj, _, err := initObjectLayer(endpoints, nil)
|
2016-09-16 17:26:05 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Unable to initialize FS backend.", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
bucketName := "bucket"
|
|
|
|
if err := obj.MakeBucket(bucketName); err != nil {
|
|
|
|
t.Fatal("Unexpected error:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fs := obj.(fsObjects)
|
|
|
|
fsstorage := fs.storage.(*posix)
|
|
|
|
|
|
|
|
listenARN := "arn:minio:sns:us-east-1:1:listen"
|
|
|
|
queueARN := "arn:minio:sqs:us-east-1:1:redis"
|
|
|
|
|
|
|
|
// Write a notification.xml in the disk
|
|
|
|
notificationXML := "<NotificationConfiguration>"
|
|
|
|
notificationXML += "<TopicConfiguration><Event>s3:ObjectRemoved:*</Event><Event>s3:ObjectRemoved:*</Event><Topic>" + listenARN + "</Topic></TopicConfiguration>"
|
|
|
|
notificationXML += "<QueueConfiguration><Event>s3:ObjectRemoved:*</Event><Event>s3:ObjectRemoved:*</Event><Queue>" + queueARN + "</Queue></QueueConfiguration>"
|
|
|
|
notificationXML += "</NotificationConfiguration>"
|
|
|
|
if err := fsstorage.AppendFile(minioMetaBucket, bucketConfigPrefix+"/"+bucketName+"/"+bucketNotificationConfig, []byte(notificationXML)); err != nil {
|
|
|
|
t.Fatal("Unexpected error:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test initEventNotifier() with faulty disks
|
|
|
|
for i := 1; i <= 5; i++ {
|
|
|
|
fs.storage = newNaughtyDisk(fsstorage, map[int]error{i: errFaultyDisk}, nil)
|
|
|
|
if err := initEventNotifier(fs); errorCause(err) != errFaultyDisk {
|
|
|
|
t.Fatal("Unexpected error:", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// InitEventNotifierWithAMQP - tests InitEventNotifier when AMQP is not prepared
|
|
|
|
func TestInitEventNotifierWithAMQP(t *testing.T) {
|
|
|
|
// initialize the server and obtain the credentials and root.
|
|
|
|
// credentials are necessary to sign the HTTP request.
|
|
|
|
rootPath, err := newTestConfig("us-east-1")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Init Test config failed")
|
|
|
|
}
|
|
|
|
// remove the root folder after the test ends.
|
|
|
|
defer removeAll(rootPath)
|
|
|
|
|
2016-10-18 15:49:24 -04:00
|
|
|
disks, err := getRandomDisks(1)
|
|
|
|
defer removeAll(disks[0])
|
2016-09-16 17:26:05 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Unable to create directories for FS backend. ", err)
|
|
|
|
}
|
2016-10-18 15:49:24 -04:00
|
|
|
endpoints, err := parseStorageEndPoints(disks, 0)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
fs, _, err := initObjectLayer(endpoints, nil)
|
2016-09-16 17:26:05 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Unable to initialize FS backend.", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
serverConfig.SetAMQPNotifyByID("1", amqpNotify{Enable: true})
|
|
|
|
if err := initEventNotifier(fs); err == nil {
|
|
|
|
t.Fatal("AMQP config didn't fail.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// InitEventNotifierWithElasticSearch - test InitEventNotifier when ElasticSearch is not ready
|
|
|
|
func TestInitEventNotifierWithElasticSearch(t *testing.T) {
|
|
|
|
// initialize the server and obtain the credentials and root.
|
|
|
|
// credentials are necessary to sign the HTTP request.
|
|
|
|
rootPath, err := newTestConfig("us-east-1")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Init Test config failed")
|
|
|
|
}
|
|
|
|
// remove the root folder after the test ends.
|
|
|
|
defer removeAll(rootPath)
|
|
|
|
|
2016-10-18 15:49:24 -04:00
|
|
|
disks, err := getRandomDisks(1)
|
|
|
|
defer removeAll(disks[0])
|
2016-09-16 17:26:05 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Unable to create directories for FS backend. ", err)
|
|
|
|
}
|
2016-10-18 15:49:24 -04:00
|
|
|
endpoints, err := parseStorageEndPoints(disks, 0)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
fs, _, err := initObjectLayer(endpoints, nil)
|
2016-09-16 17:26:05 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Unable to initialize FS backend.", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
serverConfig.SetElasticSearchNotifyByID("1", elasticSearchNotify{Enable: true})
|
|
|
|
if err := initEventNotifier(fs); err == nil {
|
|
|
|
t.Fatal("ElasticSearch config didn't fail.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// InitEventNotifierWithRedis - test InitEventNotifier when Redis is not ready
|
|
|
|
func TestInitEventNotifierWithRedis(t *testing.T) {
|
|
|
|
// initialize the server and obtain the credentials and root.
|
|
|
|
// credentials are necessary to sign the HTTP request.
|
|
|
|
rootPath, err := newTestConfig("us-east-1")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Init Test config failed")
|
|
|
|
}
|
|
|
|
// remove the root folder after the test ends.
|
|
|
|
defer removeAll(rootPath)
|
|
|
|
|
2016-10-18 15:49:24 -04:00
|
|
|
disks, err := getRandomDisks(1)
|
|
|
|
defer removeAll(disks[0])
|
2016-09-16 17:26:05 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Unable to create directories for FS backend. ", err)
|
|
|
|
}
|
2016-10-18 15:49:24 -04:00
|
|
|
endpoints, err := parseStorageEndPoints(disks, 0)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
fs, _, err := initObjectLayer(endpoints, nil)
|
2016-09-16 17:26:05 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Unable to initialize FS backend.", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
serverConfig.SetRedisNotifyByID("1", redisNotify{Enable: true})
|
|
|
|
if err := initEventNotifier(fs); err == nil {
|
|
|
|
t.Fatal("Redis config didn't fail.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-12 04:03:50 -04:00
|
|
|
type TestPeerRPCServerData struct {
|
|
|
|
serverType string
|
|
|
|
testServer TestServer
|
|
|
|
}
|
2016-09-16 17:26:05 -04:00
|
|
|
|
2016-10-12 04:03:50 -04:00
|
|
|
func (s *TestPeerRPCServerData) Setup(t *testing.T) {
|
|
|
|
s.testServer = StartTestPeersRPCServer(t, s.serverType)
|
2016-09-16 17:26:05 -04:00
|
|
|
|
2016-10-12 04:03:50 -04:00
|
|
|
// setup port and minio addr
|
|
|
|
_, portStr, err := net.SplitHostPort(s.testServer.Server.Listener.Addr().String())
|
2016-09-16 17:26:05 -04:00
|
|
|
if err != nil {
|
2016-10-12 04:03:50 -04:00
|
|
|
t.Fatalf("Initialisation error: %v", err)
|
2016-09-16 17:26:05 -04:00
|
|
|
}
|
2016-10-12 04:03:50 -04:00
|
|
|
globalMinioPort, err = strconv.Atoi(portStr)
|
2016-09-16 17:26:05 -04:00
|
|
|
if err != nil {
|
2016-10-12 04:03:50 -04:00
|
|
|
t.Fatalf("Initialisation error: %v", err)
|
2016-09-16 17:26:05 -04:00
|
|
|
}
|
2016-10-12 04:03:50 -04:00
|
|
|
globalMinioAddr = getLocalAddress(
|
|
|
|
s.testServer.SrvCmdCfg,
|
|
|
|
)
|
|
|
|
|
|
|
|
// initialize the peer client(s)
|
|
|
|
initGlobalS3Peers(s.testServer.Disks)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *TestPeerRPCServerData) TearDown() {
|
|
|
|
s.testServer.Stop()
|
|
|
|
_ = removeAll(s.testServer.Root)
|
|
|
|
for _, d := range s.testServer.Disks {
|
2016-10-18 15:49:24 -04:00
|
|
|
_ = removeAll(d.path)
|
2016-09-16 17:26:05 -04:00
|
|
|
}
|
2016-10-12 04:03:50 -04:00
|
|
|
}
|
2016-09-16 17:26:05 -04:00
|
|
|
|
2016-10-12 04:03:50 -04:00
|
|
|
func TestSetNGetBucketNotification(t *testing.T) {
|
|
|
|
s := TestPeerRPCServerData{serverType: "XL"}
|
|
|
|
|
|
|
|
// setup and teardown
|
|
|
|
s.Setup(t)
|
|
|
|
defer s.TearDown()
|
|
|
|
|
|
|
|
bucketName := getRandomBucketName()
|
|
|
|
|
|
|
|
obj := s.testServer.Obj
|
|
|
|
if err := initEventNotifier(obj); err != nil {
|
|
|
|
t.Fatal("Unexpected error:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
globalEventNotifier.SetBucketNotificationConfig(bucketName, ¬ificationConfig{})
|
|
|
|
nConfig := globalEventNotifier.GetBucketNotificationConfig(bucketName)
|
|
|
|
if nConfig == nil {
|
|
|
|
t.Errorf("Notification expected to be set, but notification not set.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(nConfig, ¬ificationConfig{}) {
|
|
|
|
t.Errorf("Mismatching notification configs.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInitEventNotifier(t *testing.T) {
|
|
|
|
s := TestPeerRPCServerData{serverType: "XL"}
|
|
|
|
|
|
|
|
// setup and teardown
|
|
|
|
s.Setup(t)
|
|
|
|
defer s.TearDown()
|
|
|
|
|
|
|
|
// test if empty object layer arg. returns expected error.
|
|
|
|
if err := initEventNotifier(nil); err == nil || err != errInvalidArgument {
|
|
|
|
t.Fatalf("initEventNotifier returned unexpected error value - %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
obj := s.testServer.Obj
|
|
|
|
bucketName := getRandomBucketName()
|
|
|
|
// declare sample configs
|
|
|
|
filterRules := []filterRule{
|
|
|
|
{
|
|
|
|
Name: "prefix",
|
|
|
|
Value: "minio",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "suffix",
|
|
|
|
Value: "*.jpg",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
sampleSvcCfg := ServiceConfig{
|
|
|
|
[]string{"s3:ObjectRemoved:*", "s3:ObjectCreated:*"},
|
|
|
|
filterStruct{
|
|
|
|
keyFilter{filterRules},
|
|
|
|
},
|
|
|
|
"1",
|
|
|
|
}
|
|
|
|
sampleNotifCfg := notificationConfig{
|
|
|
|
QueueConfigs: []queueConfig{
|
|
|
|
{
|
|
|
|
ServiceConfig: sampleSvcCfg,
|
|
|
|
QueueARN: "testqARN",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
sampleListenCfg := []listenerConfig{
|
|
|
|
{
|
|
|
|
TopicConfig: topicConfig{ServiceConfig: sampleSvcCfg,
|
|
|
|
TopicARN: "testlARN"},
|
|
|
|
TargetServer: globalMinioAddr,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// create bucket
|
2016-09-16 17:26:05 -04:00
|
|
|
if err := obj.MakeBucket(bucketName); err != nil {
|
|
|
|
t.Fatal("Unexpected error:", err)
|
|
|
|
}
|
|
|
|
|
2016-10-12 04:03:50 -04:00
|
|
|
// bucket is created, now writing should not give errors.
|
|
|
|
if err := persistNotificationConfig(bucketName, &sampleNotifCfg, obj); err != nil {
|
|
|
|
t.Fatal("Unexpected error:", err)
|
|
|
|
}
|
2016-09-16 17:26:05 -04:00
|
|
|
|
2016-10-12 04:03:50 -04:00
|
|
|
if err := persistListenerConfig(bucketName, sampleListenCfg, obj); err != nil {
|
|
|
|
t.Fatal("Unexpected error:", err)
|
|
|
|
}
|
2016-09-16 17:26:05 -04:00
|
|
|
|
2016-10-12 04:03:50 -04:00
|
|
|
// test event notifier init
|
|
|
|
if err := initEventNotifier(obj); err != nil {
|
|
|
|
t.Fatal("Unexpected error:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// fetch bucket configs and verify
|
|
|
|
ncfg := globalEventNotifier.GetBucketNotificationConfig(bucketName)
|
|
|
|
if ncfg == nil {
|
|
|
|
t.Error("Bucket notification was not present for ", bucketName)
|
|
|
|
}
|
|
|
|
if len(ncfg.QueueConfigs) != 1 || ncfg.QueueConfigs[0].QueueARN != "testqARN" {
|
|
|
|
t.Error("Unexpected bucket notification found - ", *ncfg)
|
|
|
|
}
|
|
|
|
if globalEventNotifier.GetExternalTarget("testqARN") != nil {
|
|
|
|
t.Error("A logger was not expected to be found as it was not enabled in the config.")
|
|
|
|
}
|
|
|
|
|
|
|
|
lcfg := globalEventNotifier.GetBucketListenerConfig(bucketName)
|
|
|
|
if lcfg == nil {
|
|
|
|
t.Error("Bucket listener was not present for ", bucketName)
|
|
|
|
}
|
|
|
|
if len(lcfg) != 1 || lcfg[0].TargetServer != globalMinioAddr || lcfg[0].TopicConfig.TopicARN != "testlARN" {
|
|
|
|
t.Error("Unexpected listener config found - ", lcfg[0])
|
|
|
|
}
|
|
|
|
if globalEventNotifier.GetInternalTarget("testlARN") == nil {
|
|
|
|
t.Error("A listen logger was not found.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestListenBucketNotification(t *testing.T) {
|
|
|
|
s := TestPeerRPCServerData{serverType: "XL"}
|
|
|
|
// setup and teardown
|
|
|
|
s.Setup(t)
|
|
|
|
defer s.TearDown()
|
|
|
|
|
|
|
|
// test initialisation
|
|
|
|
obj := s.testServer.Obj
|
|
|
|
|
|
|
|
bucketName := "bucket"
|
|
|
|
objectName := "object"
|
|
|
|
|
|
|
|
// Create the bucket to listen on
|
|
|
|
if err := obj.MakeBucket(bucketName); err != nil {
|
2016-09-16 17:26:05 -04:00
|
|
|
t.Fatal("Unexpected error:", err)
|
|
|
|
}
|
|
|
|
|
2016-10-21 04:25:17 -04:00
|
|
|
listenARN := fmt.Sprintf("%s:%s:1:%s-%s",
|
|
|
|
minioTopic,
|
|
|
|
serverConfig.GetRegion(),
|
|
|
|
snsTypeMinio,
|
|
|
|
s.testServer.Server.Listener.Addr(),
|
|
|
|
)
|
2016-10-12 04:03:50 -04:00
|
|
|
lcfg := listenerConfig{
|
2016-10-21 04:25:17 -04:00
|
|
|
TopicConfig: topicConfig{
|
2016-10-12 04:03:50 -04:00
|
|
|
ServiceConfig{
|
|
|
|
[]string{"s3:ObjectRemoved:*", "s3:ObjectCreated:*"},
|
|
|
|
filterStruct{},
|
|
|
|
"0",
|
|
|
|
},
|
|
|
|
listenARN,
|
|
|
|
},
|
2016-10-21 04:25:17 -04:00
|
|
|
TargetServer: globalMinioAddr,
|
2016-10-12 04:03:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// write listener config to storage layer
|
|
|
|
lcfgs := []listenerConfig{lcfg}
|
|
|
|
if err := persistListenerConfig(bucketName, lcfgs, obj); err != nil {
|
|
|
|
t.Fatalf("Test Setup error: %v", err)
|
|
|
|
}
|
|
|
|
|
2016-09-16 17:26:05 -04:00
|
|
|
// Init event notifier
|
2016-10-12 04:03:50 -04:00
|
|
|
if err := initEventNotifier(obj); err != nil {
|
2016-09-16 17:26:05 -04:00
|
|
|
t.Fatal("Unexpected error:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the config is loaded
|
2016-10-12 04:03:50 -04:00
|
|
|
listenerCfg := globalEventNotifier.GetBucketListenerConfig(bucketName)
|
|
|
|
if listenerCfg == nil {
|
|
|
|
t.Fatal("Cannot load bucket listener config")
|
2016-09-16 17:26:05 -04:00
|
|
|
}
|
2016-10-12 04:03:50 -04:00
|
|
|
if len(listenerCfg) != 1 {
|
|
|
|
t.Fatal("Listener config is not correctly loaded. Exactly one listener config is expected")
|
2016-09-16 17:26:05 -04:00
|
|
|
}
|
|
|
|
|
2016-10-12 04:03:50 -04:00
|
|
|
// Check if topic ARN is correct
|
|
|
|
if listenerCfg[0].TopicConfig.TopicARN != listenARN {
|
|
|
|
t.Fatal("Configured topic ARN is incorrect.")
|
2016-09-16 17:26:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new notification event channel.
|
|
|
|
nEventCh := make(chan []NotificationEvent)
|
|
|
|
// Close the listener channel.
|
|
|
|
defer close(nEventCh)
|
2016-10-12 04:03:50 -04:00
|
|
|
// Add events channel for listener.
|
|
|
|
if err := globalEventNotifier.AddListenerChan(listenARN, nEventCh); err != nil {
|
|
|
|
t.Fatalf("Test Setup error: %v", err)
|
|
|
|
}
|
|
|
|
// Remove listen channel after the writer has closed or the
|
|
|
|
// client disconnected.
|
|
|
|
defer globalEventNotifier.RemoveListenerChan(listenARN)
|
2016-09-16 17:26:05 -04:00
|
|
|
|
|
|
|
// Fire an event notification
|
|
|
|
go eventNotify(eventData{
|
|
|
|
Type: ObjectRemovedDelete,
|
|
|
|
Bucket: bucketName,
|
|
|
|
ObjInfo: ObjectInfo{
|
|
|
|
Bucket: bucketName,
|
|
|
|
Name: objectName,
|
|
|
|
},
|
|
|
|
ReqParams: map[string]string{
|
|
|
|
"sourceIPAddress": "localhost:1337",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
// Wait for the event notification here, if nothing is received within 30 seconds,
|
|
|
|
// test error will be fired
|
|
|
|
select {
|
|
|
|
case n := <-nEventCh:
|
|
|
|
// Check that received event
|
|
|
|
if len(n) == 0 {
|
2016-10-04 03:09:21 -04:00
|
|
|
t.Fatal("Unexpected error occurred")
|
2016-09-16 17:26:05 -04:00
|
|
|
}
|
|
|
|
if n[0].S3.Object.Key != objectName {
|
|
|
|
t.Fatalf("Received wrong object name in notification, expected %s, received %s", n[0].S3.Object.Key, objectName)
|
|
|
|
}
|
|
|
|
break
|
2016-10-12 04:03:50 -04:00
|
|
|
case <-time.After(3 * time.Second):
|
2016-09-16 17:26:05 -04:00
|
|
|
break
|
|
|
|
}
|
2016-10-12 04:03:50 -04:00
|
|
|
|
2016-09-16 17:26:05 -04:00
|
|
|
}
|
2016-09-29 01:46:19 -04:00
|
|
|
|
2016-10-12 04:03:50 -04:00
|
|
|
func TestAddRemoveBucketListenerConfig(t *testing.T) {
|
|
|
|
s := TestPeerRPCServerData{serverType: "XL"}
|
2016-09-29 01:46:19 -04:00
|
|
|
|
2016-10-12 04:03:50 -04:00
|
|
|
// setup and teardown
|
|
|
|
s.Setup(t)
|
|
|
|
defer s.TearDown()
|
|
|
|
|
|
|
|
// test code
|
|
|
|
obj := s.testServer.Obj
|
2016-09-29 01:46:19 -04:00
|
|
|
if err := initEventNotifier(obj); err != nil {
|
2016-10-12 04:03:50 -04:00
|
|
|
t.Fatalf("Failed to initialize event notifier: %v", err)
|
2016-09-29 01:46:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make a bucket to store topicConfigs.
|
|
|
|
randBucket := getRandomBucketName()
|
|
|
|
if err := obj.MakeBucket(randBucket); err != nil {
|
2016-10-12 04:03:50 -04:00
|
|
|
t.Fatalf("Failed to make bucket %s", randBucket)
|
2016-09-29 01:46:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add a topicConfig to an empty notificationConfig.
|
|
|
|
accountID := fmt.Sprintf("%d", time.Now().UTC().UnixNano())
|
2016-10-12 04:03:50 -04:00
|
|
|
accountARN := fmt.Sprintf(
|
|
|
|
"arn:minio:sqs:%s:%s:listen-%s",
|
|
|
|
serverConfig.GetRegion(),
|
|
|
|
accountID,
|
|
|
|
globalMinioAddr,
|
|
|
|
)
|
|
|
|
|
|
|
|
// Make topic configuration
|
|
|
|
filterRules := []filterRule{
|
|
|
|
{
|
|
|
|
Name: "prefix",
|
|
|
|
Value: "minio",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "suffix",
|
|
|
|
Value: "*.jpg",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
sampleTopicCfg := topicConfig{
|
2016-09-29 01:46:19 -04:00
|
|
|
TopicARN: accountARN,
|
2016-10-12 04:03:50 -04:00
|
|
|
ServiceConfig: ServiceConfig{
|
|
|
|
[]string{"s3:ObjectRemoved:*", "s3:ObjectCreated:*"},
|
|
|
|
filterStruct{
|
|
|
|
keyFilter{filterRules},
|
2016-09-29 01:46:19 -04:00
|
|
|
},
|
2016-10-12 04:03:50 -04:00
|
|
|
"sns-" + accountID,
|
2016-09-29 01:46:19 -04:00
|
|
|
},
|
|
|
|
}
|
2016-10-12 04:03:50 -04:00
|
|
|
sampleListenerCfg := &listenerConfig{
|
|
|
|
TopicConfig: sampleTopicCfg,
|
|
|
|
TargetServer: globalMinioAddr,
|
|
|
|
}
|
2016-09-29 01:46:19 -04:00
|
|
|
testCases := []struct {
|
2016-10-12 04:03:50 -04:00
|
|
|
lCfg *listenerConfig
|
2016-09-29 01:46:19 -04:00
|
|
|
expectedErr error
|
|
|
|
}{
|
2016-10-12 04:03:50 -04:00
|
|
|
{sampleListenerCfg, nil},
|
2016-09-29 01:46:19 -04:00
|
|
|
{nil, errInvalidArgument},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range testCases {
|
2016-10-12 04:03:50 -04:00
|
|
|
err := AddBucketListenerConfig(randBucket, test.lCfg, obj)
|
2016-09-29 01:46:19 -04:00
|
|
|
if err != test.expectedErr {
|
2016-10-12 04:03:50 -04:00
|
|
|
t.Errorf(
|
|
|
|
"Test %d: Failed with error %v, expected to fail with %v",
|
|
|
|
i+1, err, test.expectedErr,
|
|
|
|
)
|
2016-09-29 01:46:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-12 04:03:50 -04:00
|
|
|
// test remove listener actually removes a listener
|
|
|
|
RemoveBucketListenerConfig(randBucket, sampleListenerCfg, obj)
|
|
|
|
// since it does not return errors we fetch the config and
|
|
|
|
// check
|
|
|
|
lcSlice := globalEventNotifier.GetBucketListenerConfig(randBucket)
|
|
|
|
if len(lcSlice) != 0 {
|
|
|
|
t.Errorf("Remove Listener Config Test: did not remove listener config - %v",
|
|
|
|
lcSlice)
|
|
|
|
}
|
2016-09-29 01:46:19 -04:00
|
|
|
}
|