diff --git a/aws/sqs/integration/src/test/scala/com/commercetools/queue/sqs/SqsClientSuite.scala b/aws/sqs/integration/src/test/scala/com/commercetools/queue/sqs/SqsClientSuite.scala index 5f8d0a0..8e5ccd4 100644 --- a/aws/sqs/integration/src/test/scala/com/commercetools/queue/sqs/SqsClientSuite.scala +++ b/aws/sqs/integration/src/test/scala/com/commercetools/queue/sqs/SqsClientSuite.scala @@ -17,20 +17,43 @@ package com.commercetools.queue.sqs import cats.effect.{IO, Resource} +import cats.implicits.{catsSyntaxOption, catsSyntaxTuple2Semigroupal} import com.commercetools.queue.QueueClient import com.commercetools.queue.aws.sqs.SQSClient import com.commercetools.queue.testkit.QueueClientSuite -import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider +import software.amazon.awssdk.auth.credentials.{AnonymousCredentialsProvider, AwsBasicCredentials, StaticCredentialsProvider} import software.amazon.awssdk.regions.Region import java.net.URI +import scala.jdk.CollectionConverters.CollectionHasAsScala class SqsClientSuite extends QueueClientSuite { + private def config = + booleanOrDefault("AWS_SQS_USE_EMULATOR", default = true).ifM( + ifTrue = + IO.pure((Region.EU_WEST_1, AnonymousCredentialsProvider.create(), Some(new URI("http://localhost:4566")))), + ifFalse = for { + awsRegion <- string("AWS_SQS_REGION") + region <- Region + .regions() + .asScala + .find(_.id == awsRegion) + .liftTo[IO](new IllegalArgumentException(s"Cannot find any suitable AWS region from $awsRegion value!")) + credentials <- (string("AWS_SQS_ACCESS_KEY"), string("AWS_SQS_ACCESS_SECRET")).mapN((accessKey, accessSecret) => + StaticCredentialsProvider.create( + AwsBasicCredentials.create(accessKey, accessSecret) + )) + } yield (region, credentials, None) + ) + override def client: Resource[IO, QueueClient[IO]] = - SQSClient[IO]( - Region.EU_WEST_1, - AnonymousCredentialsProvider.create(), - endpoint = Some(new URI("http://localhost:4566"))) + config.toResource.flatMap { case (region, credentials, endpoint) => + SQSClient[IO]( + region, + credentials, + endpoint = endpoint + ) + } } diff --git a/azure/service-bus/integration/src/test/scala/com/commercetools/queue/servicebus/ServiceBusClientSuite.scala b/azure/service-bus/integration/src/test/scala/com/commercetools/queue/servicebus/ServiceBusClientSuite.scala new file mode 100644 index 0000000..680c2c7 --- /dev/null +++ b/azure/service-bus/integration/src/test/scala/com/commercetools/queue/servicebus/ServiceBusClientSuite.scala @@ -0,0 +1,36 @@ +/* + * Copyright 2024 Commercetools GmbH + * + * 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. + */ + +package com.commercetools.queue.servicebus + +import cats.effect.{IO, Resource} +import com.azure.identity.AzureCliCredentialBuilder +import com.commercetools.queue.QueueClient +import com.commercetools.queue.azure.servicebus.ServiceBusClient +import com.commercetools.queue.testkit.QueueClientSuite + +class ServiceBusClientSuite extends QueueClientSuite { + + private def config = string("AZURE_SERVICEBUS_NAMESPACE") + + override def client: Resource[IO, QueueClient[IO]] = + config.toResource.flatMap { namespace => + ServiceBusClient[IO]( + namespace = namespace, + credentials = new AzureCliCredentialBuilder().build() + ) + } +} diff --git a/build.sbt b/build.sbt index 79bd82d..4e27473 100644 --- a/build.sbt +++ b/build.sbt @@ -113,6 +113,17 @@ lazy val azureServiceBus = crossProject(JVMPlatform) ) .dependsOn(core, testkit % Test) +lazy val azureServiceBusIt = project + .in(file("azure/service-bus/integration")) + .enablePlugins(NoPublishPlugin) + .settings(commonSettings) + .settings( + libraryDependencies ++= List( + "com.azure" % "azure-identity" % "1.11.1" + ) + ) + .dependsOn(azureServiceBus.jvm % Test, testkit.jvm % Test) + lazy val awsSQS = crossProject(JVMPlatform) .crossType(CrossType.Pure) .in(file("aws/sqs")) diff --git a/gcp/pubsub/integration/src/test/scala/com/commercetools/queue/pubsub/PubSubClientSuite.scala b/gcp/pubsub/integration/src/test/scala/com/commercetools/queue/pubsub/PubSubClientSuite.scala index 2df944d..459ad9e 100644 --- a/gcp/pubsub/integration/src/test/scala/com/commercetools/queue/pubsub/PubSubClientSuite.scala +++ b/gcp/pubsub/integration/src/test/scala/com/commercetools/queue/pubsub/PubSubClientSuite.scala @@ -26,7 +26,18 @@ class PubSubClientSuite extends QueueClientSuite { override val queueUpdateSupported = false + private def config = + booleanOrDefault("GCP_PUBSUB_USE_EMULATOR", default = true).ifM( + ifTrue = IO.pure(("test-project", NoCredentialsProvider.create(), Some("http://localhost:8042"))), + ifFalse = for { + project <- string("GCP_PUBSUB_PROJECT") + credentials = NoCredentialsProvider.create() // TODO + } yield (project, credentials, None) + ) + override def client: Resource[IO, QueueClient[IO]] = - PubSubClient("test-project", NoCredentialsProvider.create(), endpoint = Some("http://localhost:8042")) + config.toResource.flatMap { case (project, credentials, endpoint) => + PubSubClient(project, credentials, endpoint = endpoint) + } } diff --git a/testkit/src/main/scala/com/commercetools/queue/testkit/QueueClientSuite.scala b/testkit/src/main/scala/com/commercetools/queue/testkit/QueueClientSuite.scala index 6acef18..79db935 100644 --- a/testkit/src/main/scala/com/commercetools/queue/testkit/QueueClientSuite.scala +++ b/testkit/src/main/scala/com/commercetools/queue/testkit/QueueClientSuite.scala @@ -1,6 +1,6 @@ package com.commercetools.queue.testkit -import cats.effect.std.Random +import cats.effect.std.{Env, Random} import cats.effect.{IO, Ref, Resource} import cats.implicits.{catsSyntaxApplicativeId, catsSyntaxOptionId} import com.commercetools.queue.{Decision, Message, QueueClient, QueueConfiguration} @@ -16,6 +16,16 @@ import scala.concurrent.duration._ */ abstract class QueueClientSuite extends CatsEffectSuite { + def optBoolean(varName: String): IO[Option[Boolean]] = + optString(varName).map(_.map(_.toBoolean)) + def booleanOrDefault(varName: String, default: Boolean): IO[Boolean] = + optBoolean(varName).map(_.getOrElse(default)) + + def optString(varName: String): IO[Option[String]] = + Env[IO].get(varName) + def string(varName: String): IO[String] = + optString(varName).flatMap(_.map(IO.pure).getOrElse(IO.raiseError(new RuntimeException(s"'$varName' is required")))) + val queueUpdateSupported: Boolean = true /** Provide a way to acquire a queue client for the provider under test. */