mcs delete bucket event notification api (#36)

Co-authored-by: Lenin Alevski <alevsk.8772@gmail.com>
This commit is contained in:
César Nieto
2020-04-07 09:27:25 -07:00
committed by GitHub
parent b390ce309a
commit e0bb098e47
10 changed files with 619 additions and 4 deletions

View File

@@ -39,16 +39,22 @@ func (mc minioClientMock) getBucketNotification(bucketName string) (bucketNotifi
//// Mock mc S3Client functions ////
var mcAddNotificationConfigMock func(arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error
var mcRemoveNotificationConfigMock func(arn string) *probe.Error
// Define a mock struct of mc S3Client interface implementation
type s3ClientMock struct {
}
// implements mc.S3Client.AddNotificationConfigMock(ctx)
// implements mc.S3Client.AddNotificationConfigMock()
func (c s3ClientMock) addNotificationConfig(arn string, events []string, prefix, suffix string, ignoreExisting bool) *probe.Error {
return mcAddNotificationConfigMock(arn, events, prefix, suffix, ignoreExisting)
}
// implements mc.S3Client.DeleteBucketEventNotification()
func (c s3ClientMock) removeNotificationConfig(arn string) *probe.Error {
return mcRemoveNotificationConfigMock(arn)
}
func TestAddBucketNotification(t *testing.T) {
assert := assert.New(t)
// mock minIO client
@@ -92,6 +98,29 @@ func TestAddBucketNotification(t *testing.T) {
}
}
func TestDeleteBucketNotification(t *testing.T) {
assert := assert.New(t)
// mock minIO client
client := s3ClientMock{}
function := "deleteBucketEventNotification()"
// Test-1: deleteBucketEventNotification() delete a bucket event notification
testArn := "arn:minio:sqs::test:postgresql"
mcRemoveNotificationConfigMock = func(arn string) *probe.Error {
return nil
}
if err := deleteBucketEventNotification(client, testArn); err != nil {
t.Errorf("Failed on %s:, error occurred: %s", function, err.Error())
}
// Test-3 deleteBucketEventNotification() S3Client.DeleteBucketEventNotification returns an error and is handled correctly
mcRemoveNotificationConfigMock = func(arn string) *probe.Error {
return probe.NewError(errors.New("error"))
}
if err := deleteBucketEventNotification(client, testArn); assert.Error(err) {
assert.Equal("error", err.Error())
}
}
func TestListBucketEvents(t *testing.T) {
assert := assert.New(t)
// mock minIO client