Skip to content

Commit

Permalink
fix: test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
darkradish committed Dec 12, 2023
1 parent 14d814f commit b7be53f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pkg/auth/vault/approle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestAppRoleLogin(t *testing.T) {
t.Fatalf("expected no errors but got: %s", err)
}

cachedToken, err := utils.ReadExistingToken()
cachedToken, err := utils.ReadExistingToken(cluster.Cores[0].Client)
if err != nil {
t.Fatalf("expected cached vault token but got: %s", err)
}
Expand All @@ -30,7 +30,7 @@ func TestAppRoleLogin(t *testing.T) {
t.Fatalf("expected no errors but got: %s", err)
}

newCachedToken, err := utils.ReadExistingToken()
newCachedToken, err := utils.ReadExistingToken(cluster.Cores[0].Client)
if err != nil {
t.Fatalf("expected cached vault token but got: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/auth/vault/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestGithubLogin(t *testing.T) {
t.Fatalf("expected no errors but got: %s", err)
}

cachedToken, err := utils.ReadExistingToken()
cachedToken, err := utils.ReadExistingToken(cluster.Cores[0].Client)
if err != nil {
t.Fatalf("expected cached vault token but got: %s", err)
}
Expand All @@ -31,7 +31,7 @@ func TestGithubLogin(t *testing.T) {
t.Fatalf("expected no errors but got: %s", err)
}

newCachedToken, err := utils.ReadExistingToken()
newCachedToken, err := utils.ReadExistingToken(cluster.Cores[0].Client)
if err != nil {
t.Fatalf("expected cached vault token but got: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/auth/vault/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestKubernetesAuth(t *testing.T) {
t.Fatalf("expected no errors but got: %s", err)
}

cachedToken, err := utils.ReadExistingToken()
cachedToken, err := utils.ReadExistingToken(cluster.Cores[0].Client)
if err != nil {
t.Fatalf("expected cached vault token but got: %s", err)
}
Expand All @@ -63,7 +63,7 @@ func TestKubernetesAuth(t *testing.T) {
t.Fatalf("expected no errors but got: %s", err)
}

newCachedToken, err := utils.ReadExistingToken()
newCachedToken, err := utils.ReadExistingToken(cluster.Cores[0].Client)
if err != nil {
t.Fatalf("expected cached vault token but got: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/auth/vault/userpass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestUserPassLogin(t *testing.T) {
t.Fatalf("expected no errors but got: %s", err)
}

cachedToken, err := utils.ReadExistingToken()
cachedToken, err := utils.ReadExistingToken(cluster.Cores[0].Client)
if err != nil {
t.Fatalf("expected cached vault token but got: %s", err)
}
Expand All @@ -29,7 +29,7 @@ func TestUserPassLogin(t *testing.T) {
t.Fatalf("expected no errors but got: %s", err)
}

newCachedToken, err := utils.ReadExistingToken()
newCachedToken, err := utils.ReadExistingToken(cluster.Cores[0].Client)
if err != nil {
t.Fatalf("expected cached vault token but got: %s", err)
}
Expand Down
13 changes: 7 additions & 6 deletions pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
"testing"
"time"

"github.com/hashicorp/vault/api"
"github.com/argoproj-labs/argocd-vault-plugin/pkg/helpers"
"github.com/argoproj-labs/argocd-vault-plugin/pkg/utils"
)

func writeToken(token string) error {
func writeToken(token string, client *api.Client) error {
home, err := os.UserHomeDir()
if err != nil {
return err
Expand All @@ -28,7 +29,7 @@ func writeToken(token string) error {
"vault_token": token,
}
file, _ := json.MarshalIndent(data, "", " ")
err = os.WriteFile(filepath.Join(path, utils.GetConfigFileName()), file, 0644)
err = os.WriteFile(filepath.Join(path, utils.GetConfigFileName(client)), file, 0644)
if err != nil {
return err
}
Expand All @@ -45,9 +46,9 @@ func removeToken() error {
return nil
}

func readToken() interface{} {
func readToken(client *api.Client) interface{} {
home, _ := os.UserHomeDir()
path := filepath.Join(home, ".avp", utils.GetConfigFileName())
path := filepath.Join(home, ".avp", utils.GetConfigFileName(client))
dat, _ := os.ReadFile(path)
var result map[string]interface{}
json.Unmarshal([]byte(dat), &result)
Expand All @@ -59,7 +60,7 @@ func TestCheckExistingToken(t *testing.T) {
defer ln.Close()

t.Run("will set token if valid", func(t *testing.T) {
err := writeToken(roottoken)
err := writeToken(roottoken, client)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -90,7 +91,7 @@ func TestCheckExistingToken(t *testing.T) {
}

dir, _ := os.UserHomeDir()
expected := fmt.Sprintf("stat %s/.avp/%s: no such file or directory", dir, utils.GetConfigFileName())
expected := fmt.Sprintf("stat %s/.avp/%s: no such file or directory", dir, utils.GetConfigFileName(client))
if err.Error() != expected {
t.Errorf("expected: %s, got: %s.", expected, err.Error())
}
Expand Down

0 comments on commit b7be53f

Please sign in to comment.