我有一个错误"无法加载凭据";当我将quarkus从1.13.2升级到2.X.X时,我的兴趣测试
LambdaIntegTest.class:
@Testcontainers
@QuarkusTest
@QuarkusTestResource(ContainerRessource.class)
class LambdaIntegTest {
@Test
void test() throws Exception {
String s3Event = oneS3event();
String out = LambdaClient.invokeJson(String.class, s3Event);
assertThat(out).isEqualTo("Success");
}
ContainerRessource.class:
public class ContainerRessource implements QuarkusTestResourceLifecycleManager {
private static final LocalStackContainer LOCAL_STACK_CONTAINER;
static {
DockerImageName localstackImage = DockerImageName.parse("localstack/localstack:0.11.3");
LOCAL_STACK_CONTAINER = new LocalStackContainer(localstackImage)
.withServices(S3);
}
@Override
public Map<String, String> start() {
LOCAL_STACK_CONTAINER.start();
innitS3();
return Map.ofEntries(
entry("aws.region", LOCAL_STACK_CONTAINER.getRegion()),
entry("s3.url.override", LOCAL_STACK_CONTAINER.getEndpointOverride(S3).toString()),
entry("aws.accessKeyId", LOCAL_STACK_CONTAINER.getAccessKey()),
entry("aws.secretAccessKey", LOCAL_STACK_CONTAINER.getSecretKey()));
}
@Override
public void stop() {
LOCAL_STACK_CONTAINER.stop();
}
}
我有试着把应用程序中的凭据。属性,但我有同样的错误。我的测试工作与Quarkus 1.13.2
我也有一个本地测试:
@QuarkusIntegrationTest
public class LambdaNativeTest extends LambdaIntegTest {
}
它成功了。
我找到了一个解决方案,如果我们手动设置凭证,在系统属性中它工作。方法start()的修改如下:
@Override
public Map<String, String> start() {
LOCAL_STACK_CONTAINER.start();
innitS3();
System.setProperty("aws.accessKeyId", LOCAL_STACK_CONTAINER.getAccessKey());
System.setProperty("aws.secretAccessKey", LOCAL_STACK_CONTAINER.getSecretKey());
return Map.ofEntries(
entry("aws.region", LOCAL_STACK_CONTAINER.getRegion()),
entry("s3.url.override", LOCAL_STACK_CONTAINER.getEndpointOverride(S3).toString()),
entry("aws.accessKeyId", LOCAL_STACK_CONTAINER.getAccessKey()),
entry("aws.secretAccessKey", LOCAL_STACK_CONTAINER.getSecretKey()));
}
QuarkusTestResourceLifecycleManager.start()的Javadoc说:'@返回应该为运行测试设置的系统属性映射'
似乎这对@QuarkusTest不起作用