Skip to content

Commit

Permalink
Add some test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
csessh committed Nov 2, 2024
1 parent 78f9832 commit 5b28fbb
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package config

import (
"os"
"runtime"
"testing"
)

func getUserHomeDir() string {
if runtime.GOOS == "windows" {
home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
if home == "" {
home = os.Getenv("USERPROFILE")
}
return home
}
return os.Getenv("HOME")
}

func TestExpandPathWithTilde(t *testing.T) {
test_path := "~/.config/pet"
expectedPath := getUserHomeDir() + "/.config/pet"

result, err := ExpandPath(test_path)

if err != nil {
t.Errorf("Expected no error, but %v was raised", err)
}

if result != expectedPath {
t.Errorf("Expected result to be %s, but got %s", expectedPath, result)
}
}

func TestExpandAbsolutePath(t *testing.T) {
test_path := "/var/tmp/"
expectedPath := "/var/tmp/"

result, err := ExpandPath(test_path)

if err != nil {
t.Errorf("Expected no error, but %v was raised", err)
}

if result != expectedPath {
t.Errorf("Expected result to be %s, but got %s", expectedPath, result)
}
}

func TestExpandPathWithEmptyInput(t *testing.T) {
test_path := ""
expectedPath := ""

result, err := ExpandPath(test_path)

if err == nil {
t.Errorf("Expected error to be raised, but got nil")
}

if result != expectedPath {
t.Errorf("Expected result to be empty, but got %s", result)
}
}

0 comments on commit 5b28fbb

Please sign in to comment.