Skip to content

Commit 2fe0d97

Browse files
AkihiroSudaningmingxiao
authored andcommitted
Merge pull request containerd#4882 from ogulcanaydogan/docs/fix-security-opt-label-formatting
docs: fix missing list prefix for --security-opt label entry Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
2 parents a01031d + ea64ff9 commit 2fe0d97

4 files changed

Lines changed: 102 additions & 80 deletions

File tree

cmd/nerdctl/container/container_logs_test.go

Lines changed: 92 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -37,97 +37,116 @@ import (
3737
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
3838
)
3939

40-
func TestLogs(t *testing.T) {
41-
const expected = `foo
40+
const expected = `foo
4241
bar
4342
`
43+
const ExitSuccess = 0
4444

45+
func newLogTestCase(name string) *test.Case {
4546
testCase := nerdtest.Setup()
46-
47-
testCase.Require = nerdtest.IsFlaky("https://github.com/containerd/nerdctl/issues/4782")
48-
if runtime.GOOS == "windows" {
49-
testCase.Require = nerdtest.NerdctlNeedsFixing("https://github.com/containerd/nerdctl/issues/4237")
50-
}
51-
47+
testCase.NoParallel = true
5248
testCase.Cleanup = func(data test.Data, helpers test.Helpers) {
53-
helpers.Anyhow("rm", "-f", data.Identifier())
49+
helpers.Anyhow("rm", "-f", name)
5450
}
55-
5651
testCase.Setup = func(data test.Data, helpers test.Helpers) {
57-
helpers.Ensure("run", "--quiet", "--name", data.Identifier(), testutil.CommonImage, "sh", "-euxc", "echo foo; echo bar;")
58-
data.Labels().Set("cID", data.Identifier())
52+
helpers.Ensure("run", "--quiet", "--name", name, testutil.CommonImage,
53+
"sh", "-euxc", "echo foo; echo bar;")
5954
}
55+
return testCase
56+
}
6057

61-
testCase.SubTests = []*test.Case{
62-
{
63-
Description: "since 1s",
64-
Setup: func(data test.Data, helpers test.Helpers) {
65-
// Ensure at least 2 seconds have elapsed since the container ran,
66-
// so that --since 1s does not include the container's output.
67-
time.Sleep(2 * time.Second)
68-
},
69-
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
70-
return helpers.Command("logs", "--since", "1s", data.Labels().Get("cID"))
71-
},
72-
Expected: test.Expects(0, nil, expect.DoesNotContain(expected)),
58+
func TestLogs_Since1s(t *testing.T) {
59+
testCase := newLogTestCase(t.Name())
60+
testCase.SubTests = []*test.Case{{
61+
Description: "since 1s",
62+
Setup: func(data test.Data, helpers test.Helpers) {
63+
// Ensure at least 2 seconds have elapsed since the container ran,
64+
// so that --since 1s does not include the container's output.
65+
time.Sleep(2 * time.Second)
7366
},
74-
{
75-
Description: "since 60s",
76-
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
77-
return helpers.Command("logs", "--since", "60s", data.Labels().Get("cID"))
78-
},
79-
Expected: test.Expects(0, nil, expect.Equals(expected)),
67+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
68+
return helpers.Command("logs", "--since", "1s", t.Name())
8069
},
81-
{
82-
Description: "until 60s",
83-
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
84-
return helpers.Command("logs", "--until", "60s", data.Labels().Get("cID"))
85-
},
86-
Expected: test.Expects(0, nil, expect.DoesNotContain(expected)),
70+
Expected: test.Expects(ExitSuccess, nil, expect.DoesNotContain(expected)),
71+
}}
72+
testCase.Run(t)
73+
}
74+
75+
func TestLogs_Since60s(t *testing.T) {
76+
testCase := newLogTestCase(t.Name())
77+
testCase.SubTests = []*test.Case{{
78+
Description: "since 60s",
79+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
80+
return helpers.Command("logs", "--since", "60s", t.Name())
8781
},
88-
{
89-
Description: "until 1s",
90-
Setup: func(data test.Data, helpers test.Helpers) {
91-
// Ensure at least 2 seconds have elapsed since the container ran,
92-
// so that --until 1s includes the container's output.
93-
time.Sleep(2 * time.Second)
94-
},
95-
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
96-
return helpers.Command("logs", "--until", "1s", data.Labels().Get("cID"))
97-
},
98-
Expected: test.Expects(0, nil, expect.Equals(expected)),
82+
Expected: test.Expects(ExitSuccess, nil, expect.Equals(expected)),
83+
}}
84+
testCase.Run(t)
85+
}
86+
87+
func TestLogs_Until60s(t *testing.T) {
88+
testCase := newLogTestCase(t.Name())
89+
testCase.SubTests = []*test.Case{{
90+
Description: "until 60s",
91+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
92+
return helpers.Command("logs", "--until", "60s", t.Name())
9993
},
100-
{
101-
Description: "follow",
102-
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
103-
return helpers.Command("logs", "-f", data.Labels().Get("cID"))
104-
},
105-
Expected: test.Expects(0, nil, expect.Equals(expected)),
94+
Expected: test.Expects(ExitSuccess, nil, expect.DoesNotContain(expected)),
95+
}}
96+
testCase.Run(t)
97+
}
98+
99+
func TestLogs_Until1s(t *testing.T) {
100+
testCase := newLogTestCase(t.Name())
101+
testCase.SubTests = []*test.Case{{
102+
Description: "until 1s",
103+
// Ensure at least 2 seconds have elapsed since the container ran,
104+
// so that --until 1s includes the container's output.
105+
Setup: func(data test.Data, helpers test.Helpers) {
106+
time.Sleep(2 * time.Second)
106107
},
107-
{
108-
Description: "timestamp",
109-
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
110-
return helpers.Command("logs", "-t", data.Labels().Get("cID"))
111-
},
112-
Expected: test.Expects(0, nil, expect.Contains(time.Now().UTC().Format("2006-01-02"))),
108+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
109+
return helpers.Command("logs", "--until", "1s", t.Name())
113110
},
114-
{
115-
Description: "tail flag",
116-
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
117-
return helpers.Command("logs", "-n", "all", data.Labels().Get("cID"))
118-
},
119-
Expected: test.Expects(0, nil, expect.Equals(expected)),
111+
Expected: test.Expects(ExitSuccess, nil, expect.Equals(expected)),
112+
}}
113+
testCase.Run(t)
114+
}
115+
116+
func TestLogs_Follow(t *testing.T) {
117+
testCase := newLogTestCase(t.Name())
118+
testCase.SubTests = []*test.Case{{
119+
Description: "follow",
120+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
121+
return helpers.Command("logs", "-f", t.Name())
120122
},
121-
{
122-
Description: "tail flag",
123-
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
124-
return helpers.Command("logs", "-n", "1", data.Labels().Get("cID"))
125-
},
126-
// FIXME: why?
127-
Expected: test.Expects(0, nil, expect.Match(regexp.MustCompile("^(?:bar\n|)$"))),
123+
Expected: test.Expects(ExitSuccess, nil, expect.Equals(expected)),
124+
}}
125+
testCase.Run(t)
126+
}
127+
128+
func TestLogs_Timestamp(t *testing.T) {
129+
testCase := newLogTestCase(t.Name())
130+
testCase.SubTests = []*test.Case{{
131+
Description: "timestamp",
132+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
133+
return helpers.Command("logs", "-t", t.Name())
128134
},
129-
}
135+
Expected: test.Expects(ExitSuccess, nil, expect.Contains(time.Now().UTC().Format("2006-01-02"))),
136+
}}
137+
testCase.Run(t)
138+
}
130139

140+
func TestLogs_Tail1(t *testing.T) {
141+
testCase := newLogTestCase(t.Name())
142+
testCase.SubTests = []*test.Case{{
143+
Description: "tail flag",
144+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
145+
return helpers.Command("logs", "-n", "1", t.Name())
146+
},
147+
// FIXME: why?
148+
Expected: test.Expects(ExitSuccess, nil, expect.Match(regexp.MustCompile("^(?:bar\n|)$"))),
149+
}}
131150
testCase.Run(t)
132151
}
133152

docs/command-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ Security flags:
255255

256256
- :whale: `--security-opt seccomp=<PROFILE_JSON_FILE>`: specify custom seccomp profile
257257
- :whale: `--security-opt apparmor=<PROFILE>`: specify custom AppArmor profile
258-
:whale: `--security-opt label=<selinuxlabel>`: specify custom selinux label
258+
- :whale: `--security-opt label=<selinuxlabel>`: specify custom selinux label
259259
- :whale: `--security-opt no-new-privileges`: disallow privilege escalation, e.g., setuid and file capabilities
260260
- :whale: `--security-opt systempaths=unconfined`: Turn off confinement for system paths (masked paths, read-only paths) for the container
261261
- :whale: `--security-opt writable-cgroups`: making the cgroups writeable

hack/test-integration.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ for arg in "$@"; do
5050
done
5151

5252
if [ "$needsudo" == "true" ] || [ "$needsudo" == "yes" ] || [ "$needsudo" == "1" ]; then
53-
gotestsum "${args[@]}" -- -timeout="$timeout" -p 1 -exec sudo -args -test.allow-kill-daemon "$@"
53+
gotestsum "${args[@]}" -- -timeout="$timeout" -v -p 1 -exec sudo -args -test.allow-kill-daemon "$@"
5454
else
55-
gotestsum "${args[@]}" -- -timeout="$timeout" -p 1 -args -test.allow-kill-daemon "$@"
55+
gotestsum "${args[@]}" -- -timeout="$timeout" -v -p 1 -args -test.allow-kill-daemon "$@"
5656
fi

mod/tigron/test/command.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package test
1919

2020
import (
2121
"context"
22+
"fmt"
2223
"io"
2324
"os"
2425
"strconv"
@@ -34,7 +35,7 @@ import (
3435

3536
const (
3637
defaultExecutionTimeout = 3 * time.Minute
37-
commandDecorator = "⚙️"
38+
commandDecorator = "⚙️⚙️"
3839
errorDecorator = "🚫"
3940
exitDecorator = "⚠️"
4041
stdoutDecorator = "🟢"
@@ -174,13 +175,15 @@ func (gc *GenericCommand) Run(expect *Expected) {
174175
gc.t.Helper()
175176

176177
var debug [][]any
177-
178+
var err01 error
178179
if !gc.async {
179-
_ = gc.cmd.Run(context.WithValue(context.Background(), com.LoggerKey, gc.t))
180+
err01 = gc.cmd.Run(context.WithValue(context.Background(), com.LoggerKey, gc.t))
180181
}
181182

183+
data_new := fmt.Sprintf("gc.async is %v gc.cmd.Binary is %s args is %v err is %v time is %s", gc.async, gc.cmd.Binary, gc.cmd.Args, err01, time.Now().Format("2006-01-02 15:04:05.000"))
184+
182185
debug = append(debug,
183-
[]any{"➡️", commandDecorator + " " + gc.cmd.Binary + " " + strings.Join(gc.cmd.Args, " ")},
186+
[]any{"➡️", commandDecorator + " " + data_new + " " + strings.Join(gc.cmd.Args, " ")},
184187
)
185188

186189
// Wait for the command and if Err is not nil, append it to the debug information

0 commit comments

Comments
 (0)