Skip to content

Commit

Permalink
fix some tests
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandar Stojanov <[email protected]>
  • Loading branch information
losisin committed Jun 24, 2024
1 parent c00ef81 commit b24cc50
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ func ParseFlags(progname string, args []string) (*Config, string, error) {
}

// LoadConfig loads configuration from a YAML file
var readFileFunc = os.ReadFile

func LoadConfig(configPath string) (*Config, error) {
data, err := os.ReadFile(configPath)
data, err := readFileFunc(configPath)
if err != nil {
if os.IsNotExist(err) {
// Return an empty config if the file does not exist
Expand Down
14 changes: 14 additions & 0 deletions pkg/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,20 @@ input:
}
}

func TestLoadConfig_PermissionDenied(t *testing.T) {
restrictedDir := "/restricted"
configFilePath := restrictedDir + "/restricted.yaml"

readFileFunc = func(filename string) ([]byte, error) {
return nil, os.ErrPermission
}
defer func() { readFileFunc = os.ReadFile }()

conf, err := LoadConfig(configFilePath)
assert.ErrorIs(t, err, os.ErrPermission, "Expected permission denied error")
assert.Nil(t, conf, "Expected config to be nil for permission denied error")
}

func TestMergeConfig(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit b24cc50

Please sign in to comment.