go-zero/tools/goctl/util/path_test.go

39 lines
655 B
Go
Raw Normal View History

2021-09-04 08:15:22 +08:00
package util
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
2021-09-04 10:08:49 +08:00
"github.com/stretchr/testify/assert"
2021-09-04 08:15:22 +08:00
)
func TestReadLink(t *testing.T) {
dir, err := ioutil.TempDir("", "go-zero")
symLink := filepath.Join(dir, "test")
pwd, err := os.Getwd()
assertError(err, t)
err = os.Symlink(pwd, symLink)
assertError(err, t)
t.Run("linked", func(t *testing.T) {
ret, err := ReadLink(symLink)
assert.Nil(t, err)
assert.Equal(t, pwd, ret)
})
t.Run("unlink", func(t *testing.T) {
ret, err := ReadLink(pwd)
assert.Nil(t, err)
assert.Equal(t, pwd, ret)
})
}
func assertError(err error, t *testing.T) {
if err != nil {
t.Fatal(err)
}
}