From bad459dfc472f51956270a06522b5435d9b48f13 Mon Sep 17 00:00:00 2001 From: Luca Consalvi Date: Wed, 27 Nov 2024 10:14:38 +0100 Subject: [PATCH] add config test and secret for managed identity --- src/main/terraform/container_app.tf | 5 +++ .../configuration/CosmosDBConfigTest.java | 44 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/test/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfigTest.java diff --git a/src/main/terraform/container_app.tf b/src/main/terraform/container_app.tf index bc4e510..85e48bb 100644 --- a/src/main/terraform/container_app.tf +++ b/src/main/terraform/container_app.tf @@ -47,6 +47,11 @@ resource "azurerm_container_app" "rtp-activator" { secret_name = "identity-client-id" } + env { + name = "AZURE_CLIENT_ID" + secret_name = "identity-client-id" + } + dynamic "env" { for_each = var.rtp_environment_configs content { diff --git a/src/test/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfigTest.java b/src/test/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfigTest.java new file mode 100644 index 0000000..80cef51 --- /dev/null +++ b/src/test/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfigTest.java @@ -0,0 +1,44 @@ +package it.gov.pagopa.rtp.activator.configuration; + +import com.azure.cosmos.CosmosClientBuilder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; + +import org.mockito.junit.jupiter.MockitoExtension; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.verify; + +@ExtendWith(MockitoExtension.class) +class CosmosDBConfigTest { + + @Mock + private CosmosPropertiesConfig cosmosPropertiesConfig; + + @InjectMocks + private CosmosDBConfig cosmosDBConfig; + + @BeforeEach + void setUp() { + lenient().when(cosmosPropertiesConfig.getDbName()).thenReturn("test-db"); + lenient().when(cosmosPropertiesConfig.getEndpoint()).thenReturn("https://test-endpoint:443/"); + } + + @Test + void testGetDatabaseName() { + String dbName = cosmosDBConfig.getDatabaseName(); + assertEquals("test-db", dbName); + } + + @Test + void testGetCosmosClientBuilder() { + CosmosClientBuilder builder = cosmosDBConfig.getCosmosClientBuilder(); + verify(cosmosPropertiesConfig).getEndpoint(); + assertNotNull(builder); + } +}