diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/secret/SecretSource.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/secret/SecretSource.kt index 663bfc6..a48d973 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/secret/SecretSource.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/framework/ubuntu/secret/SecretSource.kt @@ -30,7 +30,7 @@ enum class SecretSourceType() { @Serializable -class SecretSupplier(private val source: SecretSourceType, val parameter: String) { +data class SecretSupplier(private val source: SecretSourceType, val parameter: String) { fun secret(): Secret { return source.secret(parameter) } diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/GrafanaAgentRepositoryKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/GrafanaAgentRepositoryKtTest.kt new file mode 100644 index 0000000..814a24a --- /dev/null +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/GrafanaAgentRepositoryKtTest.kt @@ -0,0 +1,35 @@ +package org.domaindrivenarchitecture.provs.server.infrastructure + +import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName +import org.domaindrivenarchitecture.provs.framework.ubuntu.secret.SecretSourceType +import org.domaindrivenarchitecture.provs.framework.ubuntu.secret.SecretSupplier +import org.domaindrivenarchitecture.provs.server.domain.k8s_grafana_agent.GrafanaAgentConfig +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +internal class GrafanaAgentRepositoryKtTest { + + @Test + fun findK8sGrafanaConfig_returns_config() { + // when + val config = findK8sGrafanaConfig(ConfigFileName("src/test/resources/k3s-server-config-with-grafana.yaml")) + + // then + assertEquals( + GrafanaAgentConfig( + user = "654321", + password = SecretSupplier(SecretSourceType.GOPASS, "path/to/key"), + cluster = "myclustername" + ), config + ) + } + + @Test + fun findK8sGrafanaConfig_returns_null_if_no_grafan_data_available() { + // when + val config = findK8sGrafanaConfig(ConfigFileName("src/test/resources/k3sServerConfig.yaml")) + + // then + assertEquals(null, config) + } +} \ No newline at end of file diff --git a/src/test/resources/k3s-server-config-with-grafana.yaml b/src/test/resources/k3s-server-config-with-grafana.yaml new file mode 100644 index 0000000..201ff9c --- /dev/null +++ b/src/test/resources/k3s-server-config-with-grafana.yaml @@ -0,0 +1,18 @@ +fqdn: statistics.test.meissa-gmbh.de +node: + ipv4: 162.55.164.138 + ipv6: 2a01:4f8:c010:672f::1 +certmanager: + email: admin@meissa-gmbh.de + letsencryptEndpoint: prod +echo: true +reprovision: true + + +grafana: + user: "654321" # username for the grafana data source + password: + source: "GOPASS" # PLAIN, GOPASS or PROMPT + parameter: "path/to/key" # password of the user or api key + cluster: "myclustername" # the cluster name of your choice +