46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package tentacle
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestDelegatedReaderParent(t *testing.T) {
|
|
for _, value := range []string{"", "relative", "/sys/fs/cgroup/../outside", "/sys/fs/cgroup/extensions"} {
|
|
t.Setenv("CTHULHU_TENTACLE_CGROUP_PARENT", value)
|
|
parent, err := DelegatedParent()
|
|
if value == "/sys/fs/cgroup/extensions" {
|
|
if err != nil || parent != value {
|
|
t.Fatalf("%q: %s %v", value, parent, err)
|
|
}
|
|
} else if err == nil {
|
|
t.Fatalf("accepted %q", value)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestLocalLaunchListValidation(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "tentacles.json")
|
|
for _, data := range []string{
|
|
`[{"ID":"echo","Program":["/bin/true"]}]`,
|
|
`[{"ID":"echo","Program":["relative"]}]`,
|
|
`[{"ID":"echo","Program":["/bin/true"]},{"ID":"echo","Program":["/bin/true"]}]`,
|
|
strings.Repeat(" ", MaxFrameBytes+1),
|
|
`[{"ID":"echo","ID":"other","Program":["/bin/true"]}]`,
|
|
} {
|
|
if err := os.WriteFile(path, []byte(data), 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
specs, err := LoadLocalSpecs(path)
|
|
valid := data == `[{"ID":"echo","Program":["/bin/true"]}]`
|
|
if (err == nil) != valid {
|
|
t.Fatalf("validation: %v", err)
|
|
}
|
|
if valid && len(specs) != 1 {
|
|
t.Fatal(specs)
|
|
}
|
|
}
|
|
}
|