You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
676 B
Go
40 lines
676 B
Go
3 years ago
|
package pathx
|
||
3 years ago
|
|
||
|
import (
|
||
|
"io/ioutil"
|
||
|
"os"
|
||
|
"path/filepath"
|
||
|
"testing"
|
||
3 years ago
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
3 years ago
|
)
|
||
|
|
||
|
func TestReadLink(t *testing.T) {
|
||
|
dir, err := ioutil.TempDir("", "go-zero")
|
||
3 years ago
|
assert.Nil(t, err)
|
||
3 years ago
|
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)
|
||
|
}
|
||
|
}
|