-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathDeleteS3ObjectTests.cpp
More file actions
145 lines (123 loc) · 5.95 KB
/
DeleteS3ObjectTests.cpp
File metadata and controls
145 lines (123 loc) · 5.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
#include <array>
#include "S3TestsFixture.h"
#include "processors/DeleteS3Object.h"
#include "unit/TestUtils.h"
namespace {
using DeleteS3ObjectTestsFixture = FlowProcessorS3TestsFixture<minifi::aws::processors::DeleteS3Object>;
using org::apache::nifi::minifi::test::utils::verifyLogLinePresenceInPollTime;
TEST_CASE_METHOD(DeleteS3ObjectTestsFixture, "Test AWS credential setting", "[awsCredentials]") {
setBucket();
SECTION("Test property credentials") {
setAccesKeyCredentialsInProcessor();
}
SECTION("Test credentials setting from AWS Credentials service") {
setAccessKeyCredentialsInController();
setCredentialsService();
}
SECTION("Test credentials file setting") {
setCredentialFile(s3_processor);
}
SECTION("Test credentials file setting from AWS Credentials service") {
setCredentialFile(aws_credentials_service);
setCredentialsService();
}
SECTION("Test credentials setting using default credential chain") {
setUseDefaultCredentialsChain(s3_processor);
}
SECTION("Test credentials setting from AWS Credentials service using default credential chain") {
setUseDefaultCredentialsChain(aws_credentials_service);
setCredentialsService();
}
test_controller.runSession(plan, true);
REQUIRE(mock_s3_request_sender_ptr->getCredentials().GetAWSAccessKeyId() == "key");
REQUIRE(mock_s3_request_sender_ptr->getCredentials().GetAWSSecretKey() == "secret");
}
TEST_CASE_METHOD(DeleteS3ObjectTestsFixture, "Test required property not set", "[awsS3Config]") {
SECTION("Test credentials not set") {
}
SECTION("Test no bucket is set") {
setAccesKeyCredentialsInProcessor();
}
SECTION("Test no object key is set") {
setRequiredProperties();
plan->setDynamicProperty(update_attribute, "filename", "");
}
REQUIRE_THROWS_AS(test_controller.runSession(plan, true), minifi::Exception);
}
TEST_CASE_METHOD(DeleteS3ObjectTestsFixture, "Non blank validator tests") {
setRequiredProperties();
CHECK_FALSE(plan->setProperty(s3_processor, "Region", ""));
}
TEST_CASE_METHOD(DeleteS3ObjectTestsFixture, "Test proxy setting", "[awsS3Proxy]") {
setRequiredProperties();
SECTION("Use proxy configuration service") {
setProxy(true);
}
SECTION("Use processor properties") {
setProxy(false);
}
test_controller.runSession(plan, true);
checkProxySettings();
}
TEST_CASE_METHOD(DeleteS3ObjectTestsFixture, "Test success case with default values", "[awsS3DeleteSuccess]") {
setRequiredProperties();
test_controller.runSession(plan, true);
REQUIRE(mock_s3_request_sender_ptr->delete_object_request.GetBucket() == "testBucket");
REQUIRE(mock_s3_request_sender_ptr->delete_object_request.GetKey() == INPUT_FILENAME);
REQUIRE(!mock_s3_request_sender_ptr->delete_object_request.VersionIdHasBeenSet());
REQUIRE(verifyLogLinePresenceInPollTime(std::chrono::seconds(3), "Successfully deleted S3 object"));
}
TEST_CASE_METHOD(DeleteS3ObjectTestsFixture, "Test version setting", "[awsS3DeleteWithVersion]") {
setRequiredProperties();
plan->setDynamicProperty(update_attribute, "s3.version", "v1");
plan->setProperty(s3_processor, "Version", "${s3.version}");
test_controller.runSession(plan, true);
REQUIRE(mock_s3_request_sender_ptr->delete_object_request.GetVersionId() == "v1");
REQUIRE(mock_s3_request_sender_ptr->delete_object_request.VersionIdHasBeenSet());
REQUIRE(verifyLogLinePresenceInPollTime(std::chrono::seconds(3), "Successfully deleted S3 object"));
}
TEST_CASE_METHOD(DeleteS3ObjectTestsFixture, "Test optional client configuration values", "[awsS3DeleteOptionalClientConfig]") {
setRequiredProperties();
plan->setProperty(s3_processor, "Region", minifi::aws::processors::region::US_EAST_1);
plan->setProperty(s3_processor, "Communications Timeout", "10 Sec");
plan->setDynamicProperty(update_attribute, "test.endpoint", "http://localhost:1234");
plan->setProperty(s3_processor, "Endpoint Override URL", "${test.endpoint}");
test_controller.runSession(plan, true);
REQUIRE(mock_s3_request_sender_ptr->getClientConfig().region == minifi::aws::processors::region::US_EAST_1);
REQUIRE(mock_s3_request_sender_ptr->getClientConfig().connectTimeoutMs == 10000);
REQUIRE(mock_s3_request_sender_ptr->getClientConfig().endpointOverride == "http://localhost:1234");
}
TEST_CASE_METHOD(DeleteS3ObjectTestsFixture, "Test failure case", "[awsS3DeleteFailure]") {
auto log_failure = plan->addProcessor(
"LogAttribute",
"LogFailure",
core::Relationship("failure", "d"));
plan->addConnection(s3_processor, core::Relationship("failure", "d"), log_failure);
setRequiredProperties();
plan->setProperty(s3_processor, "Version", "v1");
log_failure->setAutoTerminatedRelationships(std::array{core::Relationship("success", "d")});
mock_s3_request_sender_ptr->setDeleteObjectResult(false);
test_controller.runSession(plan, true);
REQUIRE(mock_s3_request_sender_ptr->delete_object_request.GetBucket() == "testBucket");
REQUIRE(mock_s3_request_sender_ptr->delete_object_request.GetKey() == INPUT_FILENAME);
REQUIRE(mock_s3_request_sender_ptr->delete_object_request.GetVersionId() == "v1");
REQUIRE(verifyLogLinePresenceInPollTime(std::chrono::seconds(3), "Failed to delete S3 object"));
}
} // namespace