Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Sources/Services/ContainerAPIService/Client/Arch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@
public enum Arch: String {
case arm64, amd64

public init?(rawValue: String) {
switch rawValue.lowercased() {
case "arm64":
self = .arm64
case "amd64", "x86_64", "x86-64":
self = .amd64
default:
return nil
}
}

public static func hostArchitecture() -> Arch {
#if arch(arm64)
return .arm64
Expand Down
65 changes: 65 additions & 0 deletions Tests/ContainerAPIClientTests/ArchTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//===----------------------------------------------------------------------===//
// Copyright © 2026 Apple Inc. and the container project 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
//
// https://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.
//===----------------------------------------------------------------------===//

import Testing

@testable import ContainerAPIClient

struct ArchTests {

@Test func testAmd64Initialization() throws {
let arch = Arch(rawValue: "amd64")
#expect(arch != nil)
#expect(arch == .amd64)
}

@Test func testX86_64Alias() throws {
let arch = Arch(rawValue: "x86_64")
#expect(arch != nil)
#expect(arch == .amd64)
}

@Test func testX86_64WithDashAlias() throws {
let arch = Arch(rawValue: "x86-64")
#expect(arch != nil)
#expect(arch == .amd64)
}

@Test func testArm64Initialization() throws {
let arch = Arch(rawValue: "arm64")
#expect(arch != nil)
#expect(arch == .arm64)
}

@Test func testCaseInsensitive() throws {
#expect(Arch(rawValue: "AMD64") == .amd64)
#expect(Arch(rawValue: "X86_64") == .amd64)
#expect(Arch(rawValue: "ARM64") == .arm64)
#expect(Arch(rawValue: "Amd64") == .amd64)
}

@Test func testInvalidArchitecture() throws {
#expect(Arch(rawValue: "invalid") == nil)
#expect(Arch(rawValue: "i386") == nil)
#expect(Arch(rawValue: "powerpc") == nil)
#expect(Arch(rawValue: "") == nil)
}

@Test func testRawValueRoundTrip() throws {
#expect(Arch.amd64.rawValue == "amd64")
#expect(Arch.arm64.rawValue == "arm64")
}
}