Skip to content

Commit

Permalink
test for loading settings from custom path akka#3253
Browse files Browse the repository at this point in the history
1. don't throw RuntimeException, it fails to load config from custom path
2. clean up configs
  • Loading branch information
sfali committed Aug 31, 2024
1 parent 9882881 commit 9358d5e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ object AzureNameKeyCredential {
def apply(config: Config): AzureNameKeyCredential = {
val accountName = config.getString("account-name", "")
val accountKey = config.getString("account-key", "")
if (accountName.isEmpty) throw new RuntimeException("accountName property must be defined")
AzureNameKeyCredential(accountName, accountKey)
}
}
Expand Down
23 changes: 0 additions & 23 deletions azure-storage/src/test/resources/application-azurite.conf

This file was deleted.

22 changes: 22 additions & 0 deletions azure-storage/src/test/resources/application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
azurite {
api-version = "2024-11-04"
signing-algorithm = "HmacSHA256"
endpoint-url = "http://127.0.0.1:10000"

credentials {
authorization-type = SharedKey
account-name = "devstoreaccount1"
account-key = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
sas-token = ""
}
}

akka {
http {
client {
parsing {
max-response-reason-length = 512
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@ package akka.stream.alpakka
package azure
package storage

import akka.actor.ActorSystem
import akka.testkit.TestKit
import com.typesafe.config.ConfigFactory
import org.scalatest.BeforeAndAfterAll
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import scala.concurrent.duration._
import org.scalatest.wordspec.{AnyWordSpec, AnyWordSpecLike}

import scala.concurrent.duration._
import scala.util.{Failure, Success, Try}

class StorageSettingsSpec extends AnyWordSpec with Matchers {
class StorageSettingsSpec
extends TestKit(ActorSystem("StorageSettingsSystem"))
with AnyWordSpecLike
with Matchers
with BeforeAndAfterAll
with ScalaFutures {

private def mkSettings(more: String) =
StorageSettings(
Expand All @@ -38,6 +47,12 @@ class StorageSettingsSpec extends AnyWordSpec with Matchers {
.resolve()
)

override protected def afterAll(): Unit = {
super.afterAll()

system.terminate().futureValue
}

"StorageSettings" should {
"correctly parse config with anonymous authorization type" in {
val settings = mkSettings("")
Expand Down Expand Up @@ -92,15 +107,6 @@ class StorageSettingsSpec extends AnyWordSpec with Matchers {
}
}

"throw RuntimeException if account name is empty" in {
Try(mkSettings(""" credentials.account-name="" """)) match {
case Failure(ex) =>
ex shouldBe a[RuntimeException]
ex.getMessage shouldBe "accountName property must be defined"
case Success(_) => fail("Should have thrown exception")
}
}

"parse retry settings" in {
val settings = mkSettings("")
settings.retrySettings shouldBe RetrySettings(maxRetries = 5,
Expand Down Expand Up @@ -134,5 +140,12 @@ class StorageSettingsSpec extends AnyWordSpec with Matchers {
settings.endPointUrl shouldBe defined
settings.endPointUrl.get shouldBe "http://localhost:1234"
}

"load custom settings from a path" in {
val actual = StorageExt(system).settings("azurite")
actual.authorizationType shouldBe "SharedKey"
actual.endPointUrl shouldBe Some("http://127.0.0.1:10000")
actual.azureNameKeyCredential.accountName shouldBe "devstoreaccount1"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ package scaladsl
import akka.actor.ActorSystem
import akka.stream.Attributes
import com.dimafeng.testcontainers.ForAllTestContainer
import com.typesafe.config.ConfigFactory
import org.scalatest.Ignore

import scala.concurrent.duration._
Expand All @@ -23,10 +22,10 @@ class AzuriteIntegrationSpec extends StorageIntegrationSpec with ForAllTestConta

override lazy val container: AzuriteContainer = new AzuriteContainer()

override protected implicit val system: ActorSystem =
ActorSystem("StorageIntegrationSpec", ConfigFactory.load("application-azurite").withFallback(ConfigFactory.load()))
override protected implicit val system: ActorSystem = ActorSystem("AzuriteIntegrationSpec")

protected lazy val blobSettings: StorageSettings = StorageSettings().withEndPointUrl(container.getBlobHostAddress)
protected lazy val blobSettings: StorageSettings =
StorageExt(system).settings("azurite").withEndPointUrl(container.getBlobHostAddress)

override protected def beforeAll(): Unit = {
super.beforeAll()
Expand Down

0 comments on commit 9358d5e

Please sign in to comment.