mirror of
https://github.com/apple/container.git
synced 2026-09-25 09:05:47 +00:00
Fix: Support x86_64 architecture alias to prevent silent pull failure… (#1036)
- Adds architecture name normalization to accept `x86_64` and `x86-64` as aliases for `amd64`.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user