template / ci-testing / files / utils_test.go
Branch ci-testing · default branch · all branches
utils_test.go
763c260d 2022-10-06 Pavel Safronov | 1 | package main |
| 2 | ||
| 3 | import ( | |
| 4 | "os/user" | |
| 5 | "testing" | |
| 6 | ||
| 7 | "github.com/stretchr/testify/assert" | |
| 8 | ) | |
| 9 | ||
| 10 | func TestGetFullPath(t *testing.T) { | |
05f9e8ef 2022-10-06 Pavel Safronov | 11 | usr, err := user.Current() |
| 12 | assert.Nil(t, err) | |
| 13 | ||
763c260d 2022-10-06 Pavel Safronov | 14 | testSuccess := func(path string, expected string) { |
05f9e8ef 2022-10-06 Pavel Safronov | 15 | fullPath := getFullPath(path, *usr) |
763c260d 2022-10-06 Pavel Safronov | 16 | if fullPath != expected { |
| 17 | t.Errorf("Expected to get full path '%v' for '%v', but got '%v'", expected, path, fullPath) | |
| 18 | } | |
| 19 | } | |
| 20 | // testFailure := func(path string) { | |
| 21 | // _, err := getFullPath(path) | |
| 22 | // if err == nil { | |
| 23 | // t.Errorf("Expected to fail to get full path for '%v', but succeeded", path) | |
| 24 | // } | |
| 25 | // } | |
| 26 | ||
| 27 | testSuccess("C:\\", "C:\\") | |
| 28 | testSuccess("C:\\test", "C:\\test") | |
| 29 | testSuccess("C:\\test\\", "C:\\test\\") | |
| 30 | testSuccess("C:\\test\\..", "C:\\test\\..") // WRONG | |
| 31 | ||
| 32 | testSuccess("~/", usr.HomeDir) | |
| 33 | testSuccess("~", usr.HomeDir) | |
| 34 | } |