Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
AL333Z committed Sep 17, 2024
1 parent b9012fc commit 3268827
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

}
Original file line number Diff line number Diff line change
@@ -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()
)
}
}
11 changes: 11 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
Original file line number Diff line number Diff line change
@@ -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}
Expand All @@ -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. */
Expand Down

0 comments on commit 3268827

Please sign in to comment.