Skip to content

Commit

Permalink
refactor(dir): remove loadUserPath func
Browse files Browse the repository at this point in the history
Signed-off-by: Jason <[email protected]>
  • Loading branch information
JasonTheDeveloper committed Sep 3, 2024
1 parent 26a0706 commit 46c35d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
8 changes: 0 additions & 8 deletions dir/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@ const (

var userConfigDir = os.UserConfigDir // for unit test

// loadUserPath function defines UserConfigDir and UserLibexecDir.
func loadUserPath() {
UserConfigDir = ""
UserLibexecDir = ""

_ = userLibexecDirPath()
}

// userConfigDirPath returns the user level {NOTATION_CONFIG} path.
func userConfigDirPath() string {
if UserConfigDir == "" {
Expand Down
27 changes: 12 additions & 15 deletions dir/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,21 @@ package dir

import (
"os"
"path/filepath"
"testing"
)

func mockGetUserConfig() (string, error) {
return "/path/", nil
}

func Test_loadPath(t *testing.T) {
wantDir := filepath.FromSlash("/path/notation")
userConfigDir = mockGetUserConfig
loadUserPath()
if UserConfigDir != wantDir {
t.Fatalf(`loadPath() UserConfigDir is incorrect. got: %q, want: %q`, UserConfigDir, wantDir)
}

if UserLibexecDir != UserConfigDir {
t.Fatalf(`loadPath() UserLibexecDir is incorrect. got: %q, want: %q`, UserLibexecDir, wantDir)
}
func setup() {
UserConfigDir = ""
UserLibexecDir = ""
}

func Test_UserConfigDirPath(t *testing.T) {
userConfigDir = mockGetUserConfig
setup()
got := userConfigDirPath()
if got != "/path/notation" {
t.Fatalf(`UserConfigDirPath() = %q, want "/path/notation"`, got)
Expand All @@ -47,7 +39,7 @@ func Test_UserConfigDirPath(t *testing.T) {
func Test_NoHomeVariable(t *testing.T) {
t.Setenv("HOME", "")
t.Setenv("XDG_CONFIG_HOME", "")
UserConfigDir = ""
setup()
userConfigDir = os.UserConfigDir
got := userConfigDirPath()
if got != "notation" {
Expand All @@ -57,6 +49,7 @@ func Test_NoHomeVariable(t *testing.T) {

func Test_UserLibexecDirPath(t *testing.T) {
userConfigDir = mockGetUserConfig
setup()
got := userLibexecDirPath()
if got != "/path/notation" {
t.Fatalf(`UserConfigDirPath() = %q, want "/path/notation"`, got)
Expand All @@ -65,7 +58,9 @@ func Test_UserLibexecDirPath(t *testing.T) {

func TestLocalKeyPath(t *testing.T) {
userConfigDir = mockGetUserConfig
loadUserPath()
setup()
_ = userConfigDirPath()
_ = userLibexecDirPath()
gotKeyPath, gotCertPath := LocalKeyPath("web")
if gotKeyPath != "localkeys/web.key" {
t.Fatalf(`LocalKeyPath() gotKeyPath = %q, want "localkeys/web.key"`, gotKeyPath)
Expand All @@ -77,7 +72,9 @@ func TestLocalKeyPath(t *testing.T) {

func TestX509TrustStoreDir(t *testing.T) {
userConfigDir = mockGetUserConfig
loadUserPath()
setup()
_ = userConfigDirPath()
_ = userLibexecDirPath()
if got := X509TrustStoreDir("ca", "web"); got != "truststore/x509/ca/web" {
t.Fatalf(`X509TrustStoreDir() = %q, want "truststore/x509/ca/web"`, got)
}
Expand Down

0 comments on commit 46c35d4

Please sign in to comment.