|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// Copyright © 2025 Apple Inc. and the Containerization project authors. All rights reserved. |
| 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 ContainerizationOCI |
| 18 | +import Foundation |
| 19 | +import Testing |
| 20 | + |
| 21 | +@testable import Containerization |
| 22 | + |
| 23 | +struct LinuxContainerTests { |
| 24 | + |
| 25 | + @Test func processInitFromImageConfigWithAllFields() { |
| 26 | + let imageConfig = ImageConfig( |
| 27 | + user: "appuser", |
| 28 | + env: ["NODE_ENV=production", "PORT=3000"], |
| 29 | + entrypoint: ["/usr/bin/node"], |
| 30 | + cmd: ["app.js", "--verbose"], |
| 31 | + workingDir: "/app" |
| 32 | + ) |
| 33 | + |
| 34 | + let process = LinuxContainer.Configuration.Process(from: imageConfig) |
| 35 | + |
| 36 | + #expect(process.workingDirectory == "/app") |
| 37 | + #expect(process.environmentVariables == ["NODE_ENV=production", "PORT=3000"]) |
| 38 | + #expect(process.arguments == ["/usr/bin/node", "app.js", "--verbose"]) |
| 39 | + #expect(process.user.username == "appuser") |
| 40 | + } |
| 41 | + |
| 42 | + @Test func processInitFromImageConfigWithNilValues() { |
| 43 | + let imageConfig = ImageConfig( |
| 44 | + user: nil, |
| 45 | + env: nil, |
| 46 | + entrypoint: nil, |
| 47 | + cmd: nil, |
| 48 | + workingDir: nil |
| 49 | + ) |
| 50 | + |
| 51 | + let process = LinuxContainer.Configuration.Process(from: imageConfig) |
| 52 | + |
| 53 | + #expect(process.workingDirectory == "/") |
| 54 | + #expect(process.environmentVariables == []) |
| 55 | + #expect(process.arguments == []) |
| 56 | + #expect(process.user.username == "") // Default User() has empty string username |
| 57 | + } |
| 58 | + |
| 59 | + @Test func processInitFromImageConfigEntrypointAndCmdConcatenation() { |
| 60 | + let imageConfig = ImageConfig( |
| 61 | + entrypoint: ["/bin/sh", "-c"], |
| 62 | + cmd: ["echo 'hello'", "&&", "sleep 10"] |
| 63 | + ) |
| 64 | + |
| 65 | + let process = LinuxContainer.Configuration.Process(from: imageConfig) |
| 66 | + |
| 67 | + #expect(process.arguments == ["/bin/sh", "-c", "echo 'hello'", "&&", "sleep 10"]) |
| 68 | + } |
| 69 | +} |
0 commit comments