| index 6b998f53a..2208929ee 100644 |
| --- a/internal/media/gate_test.go |
| +++ b/internal/media/gate_test.go |
| @@ -2,6 +2,7 @@ package media |
| |
| import ( |
| "errors" |
| + "reflect" |
| "testing" |
| ) |
| |
| @@ -24,6 +25,8 @@ func intendedTaskDefinition() TaskDefinition { |
| Name: ContainerDeadline, Image: tdImage, User: "65534:65534", |
| Essential: true, ReadOnlyRoot: true, DropsAll: true, |
| StopTimeout: thirty(), |
| + EntryPoint: []string{"/usr/local/bin/carlos-media"}, |
| + Command: []string{"deadline"}, |
| }, |
| { |
| Name: ContainerCodec, Image: tdImage, User: "65534:65534", |
| @@ -31,6 +34,8 @@ func intendedTaskDefinition() TaskDefinition { |
| StopTimeout: thirty(), |
| DependsOn: []Dependency{{Container: ContainerDeadline, Condition: "START"}}, |
| Volumes: []string{"scratch"}, |
| + EntryPoint: []string{"/usr/local/bin/carlos-media"}, |
| + Command: []string{"codec"}, |
| }, |
| }, |
| } |
| @@ -223,6 +228,24 @@ func TestCheckTaskDefinition(t *testing.T) { |
| {"codec user beyond int64", func(t *testing.T, td *TaskDefinition) { |
| container(t, td, ContainerCodec).User = "99999999999999999999" |
| }, "user"}, |
| + {"codec group 0", func(t *testing.T, td *TaskDefinition) { |
| + container(t, td, ContainerCodec).User = "65534:0" |
| + }, "user"}, |
| + {"deadline group 0", func(t *testing.T, td *TaskDefinition) { |
| + container(t, td, ContainerDeadline).User = "65534:0" |
| + }, "user"}, |
| + {"codec group root", func(t *testing.T, td *TaskDefinition) { |
| + container(t, td, ContainerCodec).User = "65534:root" |
| + }, "user"}, |
| + {"codec group 00", func(t *testing.T, td *TaskDefinition) { |
| + container(t, td, ContainerCodec).User = "65534:00" |
| + }, "user"}, |
| + {"codec group empty", func(t *testing.T, td *TaskDefinition) { |
| + container(t, td, ContainerCodec).User = "65534:" |
| + }, "user"}, |
| + {"codec group with a second colon", func(t *testing.T, td *TaskDefinition) { |
| + container(t, td, ContainerCodec).User = "65534:65534:0" |
| + }, "user"}, |
| {"codec user unset", func(t *testing.T, td *TaskDefinition) { |
| container(t, td, ContainerCodec).User = "" |
| }, "user"}, |
| @@ -253,6 +276,48 @@ func TestCheckTaskDefinition(t *testing.T) { |
| {"no architecture", func(t *testing.T, td *TaskDefinition) { |
| td.CPUArchitecture = "" |
| }, "arm64"}, |
| + |
| + // command |
| + {"deadline runs the codec", func(t *testing.T, td *TaskDefinition) { |
| + container(t, td, ContainerDeadline).Command = []string{"codec"} |
| + }, "command"}, |
| + {"deadline runs a drill that never exits", func(t *testing.T, td *TaskDefinition) { |
| + container(t, td, ContainerDeadline).Command = []string{"drill", "hostile-timer"} |
| + }, "command"}, |
| + {"deadline with an extra argument", func(t *testing.T, td *TaskDefinition) { |
| + container(t, td, ContainerDeadline).Command = []string{"deadline", "3000"} |
| + }, "command"}, |
| + {"deadline with no command", func(t *testing.T, td *TaskDefinition) { |
| + container(t, td, ContainerDeadline).Command = nil |
| + }, "command"}, |
| + {"deadline with another entry point", func(t *testing.T, td *TaskDefinition) { |
| + container(t, td, ContainerDeadline).EntryPoint = []string{"/bin/sh", "-c"} |
| + }, "command"}, |
| + {"deadline with the image's default entry point", func(t *testing.T, td *TaskDefinition) { |
| + container(t, td, ContainerDeadline).EntryPoint = nil |
| + }, "command"}, |
| + {"deadline with the entry point carrying the role", func(t *testing.T, td *TaskDefinition) { |
| + d := container(t, td, ContainerDeadline) |
| + d.EntryPoint, d.Command = []string{"/usr/local/bin/carlos-media", "deadline"}, nil |
| + }, "command"}, |
| + {"deadline with an extra entry point argument", func(t *testing.T, td *TaskDefinition) { |
| + container(t, td, ContainerDeadline).EntryPoint = []string{"/usr/local/bin/carlos-media", "codec"} |
| + }, "command"}, |
| + {"codec with an extra entry point argument", func(t *testing.T, td *TaskDefinition) { |
| + container(t, td, ContainerCodec).EntryPoint = []string{"/usr/local/bin/carlos-media", "selftest"} |
| + }, "command"}, |
| + {"codec runs selftest", func(t *testing.T, td *TaskDefinition) { |
| + container(t, td, ContainerCodec).Command = []string{"selftest"} |
| + }, "command"}, |
| + {"codec with an extra argument", func(t *testing.T, td *TaskDefinition) { |
| + container(t, td, ContainerCodec).Command = []string{"codec", "--debug"} |
| + }, "command"}, |
| + {"codec with another entry point", func(t *testing.T, td *TaskDefinition) { |
| + container(t, td, ContainerCodec).EntryPoint = []string{"/usr/bin/ffmpeg"} |
| + }, "command"}, |
| + {"codec with the image's default entry point", func(t *testing.T, td *TaskDefinition) { |
| + container(t, td, ContainerCodec).EntryPoint = nil |
| + }, "command"}, |
| } |
| for _, c := range cases { |
| t.Run(c.name, func(t *testing.T) { |
| @@ -294,6 +359,9 @@ func TestCheckTaskDefinitionOrder(t *testing.T) { |
| {"read_only", func(t *testing.T, td *TaskDefinition) { container(t, td, ContainerCodec).ReadOnlyRoot = false }}, |
| {"capabilities", func(t *testing.T, td *TaskDefinition) { container(t, td, ContainerCodec).DropsAll = false }}, |
| {"arm64", func(t *testing.T, td *TaskDefinition) { td.CPUArchitecture = "X86_64" }}, |
| + {"command", func(t *testing.T, td *TaskDefinition) { |
| + container(t, td, ContainerDeadline).Command = []string{"codec"} |
| + }}, |
| } |
| td := intendedTaskDefinition() |
| for i := len(steps) - 1; i >= 0; i-- { |
| @@ -304,3 +372,30 @@ func TestCheckTaskDefinitionOrder(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// TestEngineCommandConstants pins the contract plan 3's image and module |
| +// implement (cmd/carlos-media at /usr/local/bin/carlos-media, roles |
| +// "deadline" and "codec"), so a change to them is a change to both. |
| +func TestEngineCommandConstants(t *testing.T) { |
| + if EngineEntryPoint != "/usr/local/bin/carlos-media" || DeadlineCommand != "deadline" || CodecCommand != "codec" { |
| + t.Fatalf("engine command contract changed: %q %q %q", EngineEntryPoint, DeadlineCommand, CodecCommand) |
| + } |
| +} |
| + |
| +// TestRunRequestNamesNoCommand: RunTask's container overrides can |
| +// replace a container's command (not its entry point), which the gate |
| +// cannot see because it reads the revision, not the run. The console |
| +// builds every override from RunRequest (plan 3's adapter Run, pinned by |
| +// its TestRunTaskInput), so RunRequest carries no command: a new field |
| +// here fails this test and has to be weighed against the gate. |
| +func TestRunRequestNamesNoCommand(t *testing.T) { |
| + want := []string{"Execution", "Class", "Payload", "DeadlineS", "GrantExpiry", "EphemeralGiB"} |
| + rt := reflect.TypeOf(RunRequest{}) |
| + var got []string |
| + for i := 0; i < rt.NumField(); i++ { |
| + got = append(got, rt.Field(i).Name) |
| + } |
| + if !reflect.DeepEqual(got, want) { |
| + t.Fatalf("RunRequest fields = %v, want %v: an override field must not change what the containers run", got, want) |
| + } |
| +} |