44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package tentacle
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestDelegatedReaderParent(t *testing.T) {
|
|
parent, err := delegated_parent("0::/user.slice/test.service/reader\n")
|
|
if err != nil || parent != "/sys/fs/cgroup/user.slice/test.service" {
|
|
t.Fatalf("%s %v", parent, err)
|
|
}
|
|
for _, path := range []string{"0::/", "0::/test.service", "0::/session.scope/reader", "0::/test.service/../reader", "1:cpu:/test.service/reader"} {
|
|
if _, err := delegated_parent(path); err == nil {
|
|
t.Fatalf("accepted %q", path)
|
|
}
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
}
|