From 17a8f8c8c5056477b93e1d8bd693edcd8dd149c1 Mon Sep 17 00:00:00 2001 From: aniket866 Date: Wed, 24 Jun 2026 01:02:22 +0530 Subject: [PATCH 1/2] fix : Cross-Platform-Path Signed-off-by: aniket866 --- pkg/config/localconfig.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/config/localconfig.go b/pkg/config/localconfig.go index 1e5eeda6..d02bfb92 100644 --- a/pkg/config/localconfig.go +++ b/pkg/config/localconfig.go @@ -3,7 +3,7 @@ package config import ( "fmt" "os" - "path" + "path/filepath" "slices" configUtil "github.com/microcks/microcks-cli/pkg/util" @@ -109,7 +109,7 @@ func DefaultConfigDir() (string, error) { return "", nil } - configDir = path.Join(homeDir, ".config", "microcks") + configDir = filepath.Join(homeDir, ".config", "microcks") return configDir, nil } @@ -130,7 +130,7 @@ func DefaultLocalConfigPath() (string, error) { if err != nil { return "", err } - return path.Join(dir, "config"), nil + return filepath.Join(dir, "config"), nil } // DefaultLocalWatchPath returns the local watch configuration path. @@ -139,7 +139,7 @@ func DefaultLocalWatchPath() (string, error) { if err != nil { return "", err } - return path.Join(dir, "watch"), nil + return filepath.Join(dir, "watch"), nil } // ValidateLocalConfig validates the local configuration. @@ -155,7 +155,7 @@ func ValidateLocalConfig(config LocalConfig) error { // WriteLocalConfig writes a new local configuration file. func WriteLocalConfig(config LocalConfig, configPath string) error { - err := os.MkdirAll(path.Dir(configPath), os.ModePerm) + err := os.MkdirAll(filepath.Dir(configPath), os.ModePerm) if err != nil { return err } @@ -407,7 +407,7 @@ func ReadLocalWatchConfig(path string) (*WatchConfig, error) { // WriteLocalWatchConfig writes a new local watch configuration file. func WriteLocalWatchConfig(config WatchConfig, cfgPath string) error { - err := os.MkdirAll(path.Dir(cfgPath), os.ModePerm) + err := os.MkdirAll(filepath.Dir(cfgPath), os.ModePerm) if err != nil { return err } From 31d41212d745629bcbbe27be841133cd80bcb5ce Mon Sep 17 00:00:00 2001 From: aniket866 Date: Tue, 30 Jun 2026 00:14:35 +0530 Subject: [PATCH 2/2] fix : test added for Window-style paths Signed-off-by: aniket866 --- pkg/config/localconfig_test.go | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 pkg/config/localconfig_test.go diff --git a/pkg/config/localconfig_test.go b/pkg/config/localconfig_test.go new file mode 100644 index 00000000..af479806 --- /dev/null +++ b/pkg/config/localconfig_test.go @@ -0,0 +1,61 @@ +package config + +import ( + "path/filepath" + "testing" +) + +func TestDefaultConfigDir_WithEnvVar(t *testing.T) { + // Set the environment variable MICROCKS_CONFIG_DIR + customDir := filepath.Join("C:", "Users", "JohnDoe", "custom-config") + t.Setenv("MICROCKS_CONFIG_DIR", customDir) + + dir, err := DefaultConfigDir() + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + + if dir != customDir { + t.Errorf("expected config dir to be %q, got %q", customDir, dir) + } +} + +func TestDefaultConfigDir_WithWindowsHomeDir(t *testing.T) { + // Clear MICROCKS_CONFIG_DIR to ensure home dir logic is used + t.Setenv("MICROCKS_CONFIG_DIR", "") + + // Set both HOME and USERPROFILE to mock a Windows-style home directory + windowsHome := filepath.Join("C:", "Users", "JohnDoe") + t.Setenv("HOME", windowsHome) + t.Setenv("USERPROFILE", windowsHome) + + dir, err := DefaultConfigDir() + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + + expectedDir := filepath.Join(windowsHome, ".config", "microcks") + if dir != expectedDir { + t.Errorf("expected config dir to be %q, got %q", expectedDir, dir) + } + + // Verify DefaultLocalConfigPath + configPath, err := DefaultLocalConfigPath() + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + expectedConfigPath := filepath.Join(expectedDir, "config") + if configPath != expectedConfigPath { + t.Errorf("expected config path to be %q, got %q", expectedConfigPath, configPath) + } + + // Verify DefaultLocalWatchPath + watchPath, err := DefaultLocalWatchPath() + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + expectedWatchPath := filepath.Join(expectedDir, "watch") + if watchPath != expectedWatchPath { + t.Errorf("expected watch path to be %q, got %q", expectedWatchPath, watchPath) + } +}