Skip to content
Merged
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
2 changes: 0 additions & 2 deletions Sources/ContainerResource/Image/ImageResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,13 @@ extension ImageResource {
extension ImageResource {
enum CodingKeys: String, CodingKey {
case id
case name
case configuration
case variants
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encode(name, forKey: .name)
try container.encode(configuration, forKey: .configuration)
try container.encode(variants, forKey: .variants)
}
Expand Down
27 changes: 14 additions & 13 deletions Tests/CLITests/Utilities/CLITest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ import Testing

class CLITest {
private static let commandSeq = Mutex<Int>(0)
struct Image: Codable {
let name: String
var reference: String { name }
}

// These structs need to track their counterpart presentation structs in CLI.
struct ImageInspectOutput: Codable {
let name: String
struct ImageResourceOutput: Codable {
let configuration: imageConfiguration

let variants: [variant]
struct variant: Codable {
let platform: imagePlatform
Expand All @@ -47,6 +44,10 @@ class CLITest {
}
}

struct imageConfiguration: Codable {
let name: String
}

struct NetworkInspectOutput: Codable {
struct Status: Codable {
let ipv4Subnet: String?
Expand Down Expand Up @@ -427,7 +428,7 @@ class CLITest {
let decoder = JSONDecoder()

struct inspectOutput: Codable {
let name: String
let configuration: imageConfiguration
}

typealias inspectOutputs = [inspectOutput]
Expand All @@ -436,7 +437,7 @@ class CLITest {
guard io.count > 0 else {
throw CLIError.containerNotFound(name)
}
return io[0].name
return io[0].configuration.name
}

func doPull(imageName: String, args: [String]? = nil) throws {
Expand Down Expand Up @@ -469,7 +470,7 @@ class CLITest {
return out.trimmingCharacters(in: .whitespacesAndNewlines).components(separatedBy: .newlines)
}

func doInspectImages(image: String) throws -> [ImageInspectOutput] {
func doInspectImages(image: String) throws -> [ImageResourceOutput] {
let (_, output, error, status) = try run(arguments: [
"image",
"inspect",
Expand All @@ -485,7 +486,7 @@ class CLITest {
}

let decoder = JSONDecoder()
return try decoder.decode([ImageInspectOutput].self, from: jsonData)
return try decoder.decode([ImageResourceOutput].self, from: jsonData)
}

func getSystemConfig() throws -> ContainerSystemConfig {
Expand Down Expand Up @@ -560,14 +561,14 @@ class CLITest {
func isImagePresent(targetImage: String) throws -> Bool {
let images = try doListImages()
return images.contains(where: { image in
if image.reference == targetImage {
if image.configuration.name == targetImage {
return true
}
return false
})
}

func doListImages() throws -> [Image] {
func doListImages() throws -> [ImageResourceOutput] {
let (_, output, error, status) = try run(arguments: [
"image",
"list",
Expand All @@ -583,7 +584,7 @@ class CLITest {
}

let decoder = JSONDecoder()
return try decoder.decode([Image].self, from: jsonData)
return try decoder.decode([ImageResourceOutput].self, from: jsonData)
}

func doImageTag(image: String, newName: String) throws {
Expand Down