Skip to content

Commit

Permalink
fixing UT
Browse files Browse the repository at this point in the history
  • Loading branch information
zoxpx committed Apr 15, 2024
1 parent f9fde71 commit 527629b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions vault/vault_cooldowns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package vault
import (
"net/http"
"net/http/httptest"
"os"
"path"
"testing"
"time"

Expand All @@ -24,7 +26,21 @@ var (
}
)

func setupK8sTests(t *testing.T) {
if _, err := os.Stat("/var/run/secrets/kubernetes.io/serviceaccount/token"); os.IsNotExist(err) {
tokFile := "/var/run/secrets/kubernetes.io/serviceaccount/token"

t.Logf("Creating dummy token file: %s", tokFile)

err := os.MkdirAll(path.Dir(tokFile), 0755)
require.NoError(t, err)
_, err = os.OpenFile(tokFile, os.O_RDONLY|os.O_CREATE, 0666) // "touch" the file
require.NoError(t, err)
}
}

func TestVaultK8sHappyPath(t *testing.T) {
setupK8sTests(t)
var (
mockReplies = []string{
"login", "mounts", // vault-client.New
Expand Down Expand Up @@ -94,6 +110,7 @@ func TestVaultK8sHappyPath(t *testing.T) {
}

func TestVaultCooldown(t *testing.T) {
setupK8sTests(t)
var (
mockReplies = []string{
"login", "mounts", // vault-client.New
Expand Down Expand Up @@ -174,6 +191,7 @@ func TestVaultCooldown(t *testing.T) {
}

func TestVaultK8sDisabledCooldown(t *testing.T) {
setupK8sTests(t)
var (
mockReplies = []string{
"login", "mounts", // vault-client.New
Expand Down

0 comments on commit 527629b

Please sign in to comment.