|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// Copyright © 2026 Apple Inc. and the container project 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 | +// https://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 | +import Foundation |
| 18 | +import Testing |
| 19 | + |
| 20 | +/// Serial removal tests that use `delete --all` and affect global container state. |
| 21 | +@Suite(.serialized) |
| 22 | +struct TestCLIRemoveSerial { |
| 23 | + @Test func testDeleteAllStopped() async throws { |
| 24 | + try await ContainerFixture.with { f in |
| 25 | + let image = try f.copyWarmupImage(ContainerFixture.warmupImages[0]) |
| 26 | + let name1 = "\(f.testID)-c1" |
| 27 | + let name2 = "\(f.testID)-c2" |
| 28 | + try f.doCreate(name: name1, image: image) |
| 29 | + f.addCleanup { try f.doRemoveIfExists(name1, ignoreFailure: true) } |
| 30 | + try f.doCreate(name: name2, image: image) |
| 31 | + f.addCleanup { try f.doRemoveIfExists(name2, ignoreFailure: true) } |
| 32 | + |
| 33 | + try f.run(["delete", "--all"]).check() |
| 34 | + |
| 35 | + #expect(try f.run(["inspect", name1]).status != 0, "name1 should be deleted") |
| 36 | + #expect(try f.run(["inspect", name2]).status != 0, "name2 should be deleted") |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + @Test func testDeleteAllSkipsRunning() async throws { |
| 41 | + try await ContainerFixture.with { f in |
| 42 | + let image = try f.copyWarmupImage(ContainerFixture.warmupImages[0]) |
| 43 | + let runningName = "\(f.testID)-running" |
| 44 | + let stoppedName = "\(f.testID)-stopped" |
| 45 | + |
| 46 | + try f.doLongRun(name: runningName, image: image, autoRemove: false) |
| 47 | + f.addCleanup { |
| 48 | + try? f.doStop(runningName) |
| 49 | + try? f.doRemove(runningName) |
| 50 | + } |
| 51 | + try f.doCreate(name: stoppedName, image: image) |
| 52 | + f.addCleanup { try f.doRemoveIfExists(stoppedName, ignoreFailure: true) } |
| 53 | + |
| 54 | + try f.run(["delete", "--all"]).check() |
| 55 | + |
| 56 | + #expect(try f.getContainerStatus(runningName) == "running", "running container should survive delete --all") |
| 57 | + #expect(try f.run(["inspect", stoppedName]).status != 0, "stopped container should be deleted") |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + @Test func testDeleteAllForce() async throws { |
| 62 | + try await ContainerFixture.with { f in |
| 63 | + let image = try f.copyWarmupImage(ContainerFixture.warmupImages[0]) |
| 64 | + let name = "\(f.testID)-c" |
| 65 | + try f.doLongRun(name: name, image: image, autoRemove: false) |
| 66 | + f.addCleanup { try f.doRemoveIfExists(name, force: true, ignoreFailure: true) } |
| 67 | + |
| 68 | + try f.run(["delete", "--all", "--force"]).check() |
| 69 | + |
| 70 | + #expect(try f.run(["inspect", name]).status != 0, "container should be deleted by --force") |
| 71 | + } |
| 72 | + } |
| 73 | +} |
0 commit comments