github.com/nektos/act@v0.2.63/pkg/container/linux_container_environment_extensions_test.go (about) 1 package container 2 3 import ( 4 "fmt" 5 "os" 6 "runtime" 7 "strings" 8 "testing" 9 10 log "github.com/sirupsen/logrus" 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestContainerPath(t *testing.T) { 15 type containerPathJob struct { 16 destinationPath string 17 sourcePath string 18 workDir string 19 } 20 21 linuxcontainerext := &LinuxContainerEnvironmentExtensions{} 22 23 if runtime.GOOS == "windows" { 24 cwd, err := os.Getwd() 25 if err != nil { 26 log.Error(err) 27 } 28 29 rootDrive := os.Getenv("SystemDrive") 30 rootDriveLetter := strings.ReplaceAll(strings.ToLower(rootDrive), `:`, "") 31 for _, v := range []containerPathJob{ 32 {"/mnt/c/Users/act/go/src/github.com/nektos/act", "C:\\Users\\act\\go\\src\\github.com\\nektos\\act\\", ""}, 33 {"/mnt/f/work/dir", `F:\work\dir`, ""}, 34 {"/mnt/c/windows/to/unix", "windows\\to\\unix", fmt.Sprintf("%s\\", rootDrive)}, 35 {fmt.Sprintf("/mnt/%v/act", rootDriveLetter), "act", fmt.Sprintf("%s\\", rootDrive)}, 36 } { 37 if v.workDir != "" { 38 if err := os.Chdir(v.workDir); err != nil { 39 log.Error(err) 40 t.Fail() 41 } 42 } 43 44 assert.Equal(t, v.destinationPath, linuxcontainerext.ToContainerPath(v.sourcePath)) 45 } 46 47 if err := os.Chdir(cwd); err != nil { 48 log.Error(err) 49 } 50 } else { 51 cwd, err := os.Getwd() 52 if err != nil { 53 log.Error(err) 54 } 55 for _, v := range []containerPathJob{ 56 {"/home/act/go/src/github.com/nektos/act", "/home/act/go/src/github.com/nektos/act", ""}, 57 {"/home/act", `/home/act/`, ""}, 58 {cwd, ".", ""}, 59 } { 60 assert.Equal(t, v.destinationPath, linuxcontainerext.ToContainerPath(v.sourcePath)) 61 } 62 } 63 } 64 65 type typeAssertMockContainer struct { 66 Container 67 LinuxContainerEnvironmentExtensions 68 } 69 70 // Type assert Container + LinuxContainerEnvironmentExtensions implements ExecutionsEnvironment 71 var _ ExecutionsEnvironment = &typeAssertMockContainer{}