From f4b153f26f9d9d800170ea4c0ee96eb364a3062f Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Thu, 23 Dec 2021 03:37:39 +0100 Subject: [PATCH] test: force to have a reproducible context for oracle provider tests --- providers/dns/oraclecloud/oraclecloud_test.go | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/providers/dns/oraclecloud/oraclecloud_test.go b/providers/dns/oraclecloud/oraclecloud_test.go index 9caf2de2..bcd473ae 100644 --- a/providers/dns/oraclecloud/oraclecloud_test.go +++ b/providers/dns/oraclecloud/oraclecloud_test.go @@ -199,6 +199,9 @@ func TestNewDNSProvider(t *testing.T) { } func TestNewDNSProviderConfig(t *testing.T) { + envTest.ClearEnv() + defer envTest.RestoreEnv() + testCases := []struct { desc string compartmentID string @@ -206,8 +209,8 @@ func TestNewDNSProviderConfig(t *testing.T) { expected string }{ { - desc: "invalid configuration", - configurationProvider: &configProvider{}, + desc: "configuration provider error", + configurationProvider: mockConfigurationProvider("wrong-secret"), compartmentID: "123", expected: "oraclecloud: can not create client, bad configuration: x509: decryption password incorrect", }, @@ -217,8 +220,9 @@ func TestNewDNSProviderConfig(t *testing.T) { expected: "oraclecloud: OCIConfigProvider is missing", }, { - desc: "missing CompartmentID", - expected: "oraclecloud: CompartmentID is missing", + desc: "missing CompartmentID", + configurationProvider: mockConfigurationProvider("secret"), + expected: "oraclecloud: CompartmentID is missing", }, } @@ -270,6 +274,24 @@ func TestLiveCleanUp(t *testing.T) { require.NoError(t, err) } +func mockConfigurationProvider(keyPassphrase string) *configProvider { + envTest.Apply(map[string]string{ + envPrivKey: mustGeneratePrivateKey("secret"), + }) + + return &configProvider{ + values: map[string]string{ + EnvCompartmentOCID: "test", + EnvPrivKeyPass: "test", + EnvTenancyOCID: "test", + EnvUserOCID: "test", + EnvPubKeyFingerprint: "test", + EnvRegion: "test", + }, + privateKeyPassphrase: keyPassphrase, + } +} + func mustGeneratePrivateKey(pwd string) string { block, err := generatePrivateKey(pwd) if err != nil {