Skip to content

Commit

Permalink
Add azure_helpers_test.go with getStorageAccount{Name,Key} tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-sensenich committed Jun 1, 2022
1 parent 3e2383a commit 33ebaef
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tempodb/backend/azure/azure_helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package azure

import (
"testing"

"github.com/grafana/dskit/flagext"
"github.com/stretchr/testify/assert"
)

const (
TestStorageAccountName = "foobar"
TestStorageAccountKey = "abc123"
)

// TestGetStorageAccountName* explicitly broken out into
// separate tests instead of table-driven due to usage of t.SetEnv
func TestGetStorageAccountNameInConfig(t *testing.T) {
cfg := Config{StorageAccountName: TestStorageAccountName}

actual := getStorageAccountName(&cfg)
assert.Equal(t, TestStorageAccountName, actual)
}

func TestGetStorageAccountNameInEnv(t *testing.T) {
cfg := Config{}
t.Setenv("AZURE_STORAGE_ACCOUNT", TestStorageAccountName)

actual := getStorageAccountName(&cfg)
assert.Equal(t, TestStorageAccountName, actual)
}

func TestGetStorageAccountNameNotSet(t *testing.T) {
cfg := Config{}

actual := getStorageAccountName(&cfg)
assert.Equal(t, "", actual)
}

// TestGetStorageAccountKey* explicitly broken out into
// separate tests instead of table-driven due to usage of t.SetEnv
func TestGetStorageAccountKeyInConfig(t *testing.T) {
storageAccountKeySecret := flagext.SecretWithValue(TestStorageAccountKey)
cfg := Config{StorageAccountKey: storageAccountKeySecret}

actual := getStorageAccountKey(&cfg)
assert.Equal(t, TestStorageAccountKey, actual)
}

func TestGetStorageAccountKeyInEnv(t *testing.T) {
cfg := Config{}
t.Setenv("AZURE_STORAGE_KEY", TestStorageAccountKey)

actual := getStorageAccountKey(&cfg)
assert.Equal(t, TestStorageAccountKey, actual)
}

func TestGetStorageAccountKeyNotSet(t *testing.T) {
cfg := Config{}

actual := getStorageAccountKey(&cfg)
assert.Equal(t, "", actual)
}

0 comments on commit 33ebaef

Please sign in to comment.