2026-09-11 15:03:39 +00:00
|
|
|
//go:build linux || darwin
|
|
|
|
|
|
|
|
|
|
package cli
|
|
|
|
|
|
|
|
|
|
import (
|
2026-09-11 15:06:29 +00:00
|
|
|
"fmt"
|
2026-09-11 15:03:39 +00:00
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"syscall"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestRunCreatesReusableGroupAccessibleCacheState(t *testing.T) {
|
2026-11-22 05:24:30 +00:00
|
|
|
previousUmask := syscall.Umask(0007)
|
2026-09-11 15:03:39 +00:00
|
|
|
defer syscall.Umask(previousUmask)
|
2026-11-22 05:24:30 +00:00
|
|
|
fixture := newStateRunFixture(t)
|
|
|
|
|
first := fixture.run(t, "--cache", "auto")
|
|
|
|
|
if first.status != 0 {
|
|
|
|
|
t.Fatalf("initial run=%#v", first)
|
2026-09-11 15:03:39 +00:00
|
|
|
}
|
2026-11-22 05:24:30 +00:00
|
|
|
assertGroupAccessibleCacheTree(t, fixture.cacheRoot)
|
|
|
|
|
calls := len(fixture.client.requestsSnapshot())
|
|
|
|
|
second := fixture.run(t, "--cache", "auto")
|
|
|
|
|
if second.status != 0 || len(fixture.client.requestsSnapshot()) != calls {
|
|
|
|
|
t.Fatalf("reuse=%#v calls=%d/%d", second, len(fixture.client.requestsSnapshot()), calls)
|
2026-09-11 15:03:39 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
func assertGroupAccessibleCacheTree(t *testing.T, root string) {
|
|
|
|
|
t.Helper()
|
|
|
|
|
if err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
want := os.FileMode(0o660)
|
|
|
|
|
if info.IsDir() {
|
|
|
|
|
want = 0o770
|
|
|
|
|
}
|
|
|
|
|
if got := info.Mode().Perm(); got != want {
|
2026-09-11 15:06:29 +00:00
|
|
|
return fmt.Errorf("%s mode = %#o, want %#o", path, got, want)
|
2026-09-11 15:03:39 +00:00
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|