Skip to content

Commit 9914701

Browse files
authored
Merge pull request #5365 from immanuwell/fix/namespace-remove-multiple
fix(namespace): remove all requested namespaces
2 parents ff0abc4 + 3e4acd0 commit 9914701

2 files changed

Lines changed: 62 additions & 2 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package namespace
18+
19+
import (
20+
"testing"
21+
22+
"github.com/containerd/nerdctl/mod/tigron/expect"
23+
"github.com/containerd/nerdctl/mod/tigron/require"
24+
"github.com/containerd/nerdctl/mod/tigron/test"
25+
26+
"github.com/containerd/nerdctl/v2/pkg/testutil/nerdtest"
27+
)
28+
29+
func TestNamespaceRemoveMultiple(t *testing.T) {
30+
for _, tc := range []struct {
31+
description string
32+
firstExists bool
33+
}{
34+
{description: "both namespaces exist", firstExists: true},
35+
{description: "first namespace does not exist", firstExists: false},
36+
} {
37+
t.Run(tc.description, func(t *testing.T) {
38+
testCase := nerdtest.Setup()
39+
testCase.Require = require.Not(nerdtest.Docker)
40+
testCase.Setup = func(data test.Data, helpers test.Helpers) {
41+
if tc.firstExists {
42+
helpers.Ensure("namespace", "create", data.Identifier("first"))
43+
}
44+
helpers.Ensure("namespace", "create", data.Identifier("second"))
45+
}
46+
testCase.Cleanup = func(data test.Data, helpers test.Helpers) {
47+
helpers.Anyhow("namespace", "rm", data.Identifier("first"))
48+
helpers.Anyhow("namespace", "rm", data.Identifier("second"))
49+
}
50+
testCase.Command = func(data test.Data, helpers test.Helpers) test.TestableCommand {
51+
return helpers.Command("namespace", "rm", data.Identifier("first"), data.Identifier("second"))
52+
}
53+
testCase.Expected = func(data test.Data, helpers test.Helpers) *test.Expected {
54+
return &test.Expected{Output: expect.Equals(data.Identifier("first") + "\n" + data.Identifier("second") + "\n")}
55+
}
56+
testCase.Run(t)
57+
})
58+
}
59+
}

‎pkg/cmd/namespace/remove.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ func Remove(ctx context.Context, client *containerd.Client, deletedNamespaces []
4444
continue
4545
}
4646
}
47-
_, err := fmt.Fprintln(options.Stdout, target)
48-
return err
47+
if _, err := fmt.Fprintln(options.Stdout, target); err != nil {
48+
return err
49+
}
4950
}
5051
return exitErr
5152
}

0 commit comments

Comments
 (0)