Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions internal/runner/exec/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"os"
"path/filepath"
"runtime"
"testing"

tuikitIO "github.com/flowexec/tuikit/io"
Expand All @@ -27,6 +28,17 @@ type runCall struct {
mode tuikitIO.LogMode
}

// absHostVolumePath is an absolute host path valid on the current platform.
// expandVolumeHost gates on filepath.IsAbs, which rejects a Unix-style path on
// Windows - there an absolute path needs a drive letter. The container side of a
// volume stays Unix, since container paths are always Linux paths.
func absHostVolumePath() string {
if runtime.GOOS == "windows" {
return `C:\opt\data`
}
return "/opt/data"
}

func TestExec(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Exec Suite")
Expand Down Expand Up @@ -253,8 +265,11 @@ var _ = Describe("Exec Runner", func() {

It("expands and mounts workspace-relative and absolute volumes", func() {
c := &executable.ExecContainer{
Image: "alpine:3",
Volumes: []executable.ExecContainerVolume{"//cache:/cache", "/opt/data:/data:ro"},
Image: "alpine:3",
Volumes: []executable.ExecContainerVolume{
"//cache:/cache",
executable.ExecContainerVolume(absHostVolumePath() + ":/data:ro"),
},
}
e := newContainerExec(c, executable.Directory(wsPath))
Expect(execRnr.Exec(ctx.Ctx, e, mockEngine, map[string]string{}, nil)).To(Succeed())
Expand All @@ -263,7 +278,7 @@ var _ = Describe("Exec Runner", func() {
// mounts[0] is the workspace; the two user volumes follow in order.
Expect(mounts[len(mounts)-2].HostPath).To(Equal(filepath.Join(wsPath, "cache")))
Expect(mounts[len(mounts)-2].ContainerPath).To(Equal("/cache"))
Expect(mounts[len(mounts)-1].HostPath).To(Equal("/opt/data"))
Expect(mounts[len(mounts)-1].HostPath).To(Equal(absHostVolumePath()))
Expect(mounts[len(mounts)-1].ContainerPath).To(Equal("/data"))
Expect(mounts[len(mounts)-1].Options).To(Equal("ro"))
})
Expand Down Expand Up @@ -306,7 +321,7 @@ var _ = Describe("Exec Runner", func() {
Expect(got).To(HaveSuffix(wantSuffix))
},
Entry("workspace-relative", "//sub/dir", false, filepath.Join("/ws/root", "sub", "dir")),
Entry("absolute", "/opt/data", false, "/opt/data"),
Entry("absolute", absHostVolumePath(), false, absHostVolumePath()),
Entry("home-relative", "~/thing", false, "thing"),
Entry("cwd-relative", "./local", false, "local"),
Entry("bare relative is rejected", "relative/path", true, ""),
Expand Down
8 changes: 7 additions & 1 deletion internal/services/run/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package run_test
import (
"errors"
"os"
"runtime"
"strings"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -132,7 +133,12 @@ var _ = Describe("Container backend", func() {

info, err := os.Stat(path)
Expect(err).NotTo(HaveOccurred())
Expect(info.Mode().Perm()).To(Equal(os.FileMode(0600)))
// Unix permission bits are not expressible on Windows: Go maps them
// onto ACLs and the file reads back as 0666. The env file still holds
// secrets, so the mode is asserted everywhere it means something.
if runtime.GOOS != "windows" {
Expect(info.Mode().Perm()).To(Equal(os.FileMode(0600)))
}

content, err := os.ReadFile(path)
Expect(err).NotTo(HaveOccurred())
Expand Down
6 changes: 4 additions & 2 deletions pkg/store/store_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package store_test

import (
"fmt"
"path/filepath"
"testing"
"time"
Expand All @@ -22,7 +21,10 @@ var _ = Describe("BoltDataStore", func() {
var err error

BeforeEach(func() {
path := filepath.Join(GinkgoT().TempDir(), fmt.Sprintf("test_%s.db", GinkgoT().Name()))
// TempDir is already unique per spec, so the file needs no disambiguating
// suffix - and deriving one from the spec name broke on Windows, where a
// name containing "->" yields an illegal filename (ERROR_INVALID_NAME).
path := filepath.Join(GinkgoT().TempDir(), "test.db")
ds, err = store.NewDataStore(path)
Expect(err).NotTo(HaveOccurred())
Expect(ds).NotTo(BeNil())
Expand Down
Loading