kcl-lang.io/kpm@v0.8.7-0.20240520061008-9fc4c5efc8c7/pkg/utils/utils_unix_test.go (about)

     1  //go:build linux || darwin
     2  // +build linux darwin
     3  
     4  package utils
     5  
     6  import (
     7  	"os"
     8  	"path/filepath"
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/assert"
    12  )
    13  
    14  func TestCreateSymbolLink(t *testing.T) {
    15  	testDir := getTestDir("test_link")
    16  	need_linked := filepath.Join(testDir, "need_be_linked_v1")
    17  	linkPath := filepath.Join(testDir, "linked")
    18  
    19  	_ = os.Remove(linkPath)
    20  	err := CreateSymlink(need_linked, linkPath)
    21  
    22  	linkTarget, _ := os.Readlink(linkPath)
    23  	assert.Equal(t, err, nil)
    24  	assert.Equal(t, linkTarget, need_linked)
    25  	_ = os.Remove(linkPath)
    26  }