-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrkt_exec_test.go
98 lines (84 loc) · 3.78 KB
/
rkt_exec_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2015 The rkt Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// +build host coreos src kvm
package main
import (
"fmt"
"io/ioutil"
"os"
"testing"
"github.com/coreos/rkt/tests/testutils"
)
const (
noappManifestStr = `{"acKind":"ImageManifest","acVersion":"0.7.4","name":"coreos.com/rkt-inspect","labels":[{"name":"version","value":"1.7.0"},{"name":"arch","value":"amd64"},{"name":"os","value":"linux"}]}`
)
func TestRunOverrideExec(t *testing.T) {
noappManifestFile := "noapp-manifest.json"
if err := ioutil.WriteFile(noappManifestFile, []byte(noappManifestStr), 0600); err != nil {
t.Fatalf("Cannot write noapp manifest: %v", err)
}
defer os.Remove(noappManifestFile)
noappImage := patchTestACI("rkt-image-without-exec.aci", fmt.Sprintf("--manifest=%s", noappManifestFile))
defer os.Remove(noappImage)
execImage := patchTestACI("rkt-exec-override.aci", "--exec=/inspect")
defer os.Remove(execImage)
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()
for _, tt := range []struct {
rktCmd string
expectedRegex string
}{
{
// Sanity check - make sure no --exec override prints the expected exec invocation
rktCmd: fmt.Sprintf("%s --insecure-options=image run --mds-register=false %s -- --print-exec", ctx.Cmd(), execImage),
expectedRegex: "inspect execed as: /inspect",
},
{
// Now test overriding the entrypoint (which is a symlink to /inspect so should behave identically)
rktCmd: fmt.Sprintf("%s --insecure-options=image run --mds-register=false %s --exec /inspect-link -- --print-exec", ctx.Cmd(), execImage),
expectedRegex: "inspect execed as: /inspect-link",
},
{
// Test overriding the entrypoint with a relative path
rktCmd: fmt.Sprintf("%s --insecure-options=image run --mds-register=false %s --exec inspect-link-bin -- --print-exec", ctx.Cmd(), execImage),
expectedRegex: "inspect execed as: .*inspect-link-bin",
},
{
// Test overriding the entrypoint with a missing app section
rktCmd: fmt.Sprintf("%s --insecure-options=image run --mds-register=false %s --exec /inspect -- --print-exec", ctx.Cmd(), noappImage),
expectedRegex: "inspect execed as: /inspect",
},
} {
runRktAndCheckRegexOutput(t, tt.rktCmd, tt.expectedRegex)
}
}
func TestRunPreparedOverrideExec(t *testing.T) {
execImage := patchTestACI("rkt-exec-override.aci", "--exec=/inspect")
defer os.Remove(execImage)
ctx := testutils.NewRktRunCtx()
defer ctx.Cleanup()
var rktCmd, uuid, expected string
// Sanity check - make sure no --exec override prints the expected exec invocation
rktCmd = fmt.Sprintf("%s prepare --insecure-options=image %s -- --print-exec", ctx.Cmd(), execImage)
uuid = runRktAndGetUUID(t, rktCmd)
rktCmd = fmt.Sprintf("%s run-prepared --mds-register=false %s", ctx.Cmd(), uuid)
expected = "inspect execed as: /inspect"
runRktAndCheckOutput(t, rktCmd, expected, false)
// Now test overriding the entrypoint (which is a symlink to /inspect so should behave identically)
rktCmd = fmt.Sprintf("%s prepare --insecure-options=image %s --exec /inspect-link -- --print-exec", ctx.Cmd(), execImage)
uuid = runRktAndGetUUID(t, rktCmd)
rktCmd = fmt.Sprintf("%s run-prepared --mds-register=false %s", ctx.Cmd(), uuid)
expected = "inspect execed as: /inspect-link"
runRktAndCheckOutput(t, rktCmd, expected, false)
}