Skip to content

Commit cd4cd7d

Browse files
committed
give the tuple field names and rename size to sizeInBytes
1 parent 009e932 commit cd4cd7d

File tree

5 files changed

+34
-34
lines changed

5 files changed

+34
-34
lines changed

Sources/ContainerClient/Core/ClientImage.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ extension ClientImage {
296296
/// Calculate disk usage for images
297297
/// - Parameter activeReferences: Set of image references currently in use by containers
298298
/// - Returns: Tuple of (total count, active count, total size, reclaimable size)
299-
public static func calculateDiskUsage(activeReferences: Set<String>) async throws -> (Int, Int, UInt64, UInt64) {
299+
public static func calculateDiskUsage(activeReferences: Set<String>) async throws -> (totalCount: Int, activeCount: Int, totalSize: UInt64, reclaimableSize: UInt64) {
300300
let client = newXPCClient()
301301
let request = newRequest(.imageDiskUsage)
302302

@@ -310,7 +310,7 @@ extension ClientImage {
310310
let size = response.uint64(key: .imageSize)
311311
let reclaimable = response.uint64(key: .reclaimableSize)
312312

313-
return (total, active, size, reclaimable)
313+
return (totalCount: total, activeCount: active, totalSize: size, reclaimableSize: reclaimable)
314314
}
315315

316316
public static func fetch(reference: String, platform: Platform? = nil, scheme: RequestScheme = .auto, progressUpdate: ProgressUpdateHandler? = nil) async throws -> ClientImage

Sources/ContainerClient/Core/DiskUsage.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ public struct ResourceUsage: Sendable, Codable {
4343
public var active: Int
4444

4545
/// Total size in bytes
46-
public var size: UInt64
46+
public var sizeInBytes: UInt64
4747

4848
/// Reclaimable size in bytes (from unused/inactive resources)
4949
public var reclaimable: UInt64
5050

51-
public init(total: Int, active: Int, size: UInt64, reclaimable: UInt64) {
51+
public init(total: Int, active: Int, sizeInBytes: UInt64, reclaimable: UInt64) {
5252
self.total = total
5353
self.active = active
54-
self.size = size
54+
self.sizeInBytes = sizeInBytes
5555
self.reclaimable = reclaimable
5656
}
5757
}

Sources/ContainerCommands/System/SystemDF.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,26 @@ extension Application {
6565
"Images",
6666
"\(stats.images.total)",
6767
"\(stats.images.active)",
68-
formatSize(stats.images.size),
69-
formatReclaimable(stats.images.reclaimable, total: stats.images.size),
68+
formatSize(stats.images.sizeInBytes),
69+
formatReclaimable(stats.images.reclaimable, total: stats.images.sizeInBytes),
7070
])
7171

7272
// Containers row
7373
rows.append([
7474
"Containers",
7575
"\(stats.containers.total)",
7676
"\(stats.containers.active)",
77-
formatSize(stats.containers.size),
78-
formatReclaimable(stats.containers.reclaimable, total: stats.containers.size),
77+
formatSize(stats.containers.sizeInBytes),
78+
formatReclaimable(stats.containers.reclaimable, total: stats.containers.sizeInBytes),
7979
])
8080

8181
// Volumes row
8282
rows.append([
8383
"Local Volumes",
8484
"\(stats.volumes.total)",
8585
"\(stats.volumes.active)",
86-
formatSize(stats.volumes.size),
87-
formatReclaimable(stats.volumes.reclaimable, total: stats.volumes.size),
86+
formatSize(stats.volumes.sizeInBytes),
87+
formatReclaimable(stats.volumes.reclaimable, total: stats.volumes.sizeInBytes),
8888
])
8989

9090
let tableFormatter = TableOutput(rows: rows)

Sources/Services/ContainerAPIService/DiskUsage/DiskUsageService.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,29 @@ public actor DiskUsageService {
4949

5050
let stats = DiskUsageStats(
5151
images: ResourceUsage(
52-
total: imageData.0,
53-
active: imageData.1,
54-
size: imageData.2,
55-
reclaimable: imageData.3
52+
total: imageData.totalCount,
53+
active: imageData.activeCount,
54+
sizeInBytes: imageData.totalSize,
55+
reclaimable: imageData.reclaimableSize
5656
),
5757
containers: ResourceUsage(
5858
total: containerData.0,
5959
active: containerData.1,
60-
size: containerData.2,
60+
sizeInBytes: containerData.2,
6161
reclaimable: containerData.3
6262
),
6363
volumes: ResourceUsage(
6464
total: volumeData.0,
6565
active: volumeData.1,
66-
size: volumeData.2,
66+
sizeInBytes: volumeData.2,
6767
reclaimable: volumeData.3
6868
)
6969
)
7070

7171
log.debug(
7272
"disk usage calculation complete",
7373
metadata: [
74-
"images_total": "\(imageData.0)",
74+
"images_total": "\(imageData.totalCount)",
7575
"containers_total": "\(containerData.0)",
7676
"volumes_total": "\(volumeData.0)",
7777
])

Tests/ContainerClientTests/DiskUsageTests.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ struct DiskUsageTests {
2424
@Test("DiskUsageStats JSON encoding and decoding")
2525
func testJSONSerialization() throws {
2626
let stats = DiskUsageStats(
27-
images: ResourceUsage(total: 10, active: 5, size: 1024, reclaimable: 512),
28-
containers: ResourceUsage(total: 3, active: 2, size: 2048, reclaimable: 1024),
29-
volumes: ResourceUsage(total: 7, active: 4, size: 4096, reclaimable: 2048)
27+
images: ResourceUsage(total: 10, active: 5, sizeInBytes: 1024, reclaimable: 512),
28+
containers: ResourceUsage(total: 3, active: 2, sizeInBytes: 2048, reclaimable: 1024),
29+
volumes: ResourceUsage(total: 7, active: 4, sizeInBytes: 4096, reclaimable: 2048)
3030
)
3131

3232
let encoder = JSONEncoder()
@@ -37,23 +37,23 @@ struct DiskUsageTests {
3737

3838
#expect(decoded.images.total == stats.images.total)
3939
#expect(decoded.images.active == stats.images.active)
40-
#expect(decoded.images.size == stats.images.size)
40+
#expect(decoded.images.sizeInBytes == stats.images.sizeInBytes)
4141
#expect(decoded.images.reclaimable == stats.images.reclaimable)
4242

4343
#expect(decoded.containers.total == stats.containers.total)
4444
#expect(decoded.containers.active == stats.containers.active)
45-
#expect(decoded.containers.size == stats.containers.size)
45+
#expect(decoded.containers.sizeInBytes == stats.containers.sizeInBytes)
4646
#expect(decoded.containers.reclaimable == stats.containers.reclaimable)
4747

4848
#expect(decoded.volumes.total == stats.volumes.total)
4949
#expect(decoded.volumes.active == stats.volumes.active)
50-
#expect(decoded.volumes.size == stats.volumes.size)
50+
#expect(decoded.volumes.sizeInBytes == stats.volumes.sizeInBytes)
5151
#expect(decoded.volumes.reclaimable == stats.volumes.reclaimable)
5252
}
5353

5454
@Test("ResourceUsage with zero values")
5555
func testZeroValues() throws {
56-
let emptyUsage = ResourceUsage(total: 0, active: 0, size: 0, reclaimable: 0)
56+
let emptyUsage = ResourceUsage(total: 0, active: 0, sizeInBytes: 0, reclaimable: 0)
5757

5858
let encoder = JSONEncoder()
5959
let data = try encoder.encode(emptyUsage)
@@ -63,7 +63,7 @@ struct DiskUsageTests {
6363

6464
#expect(decoded.total == 0)
6565
#expect(decoded.active == 0)
66-
#expect(decoded.size == 0)
66+
#expect(decoded.sizeInBytes == 0)
6767
#expect(decoded.reclaimable == 0)
6868
}
6969

@@ -72,7 +72,7 @@ struct DiskUsageTests {
7272
let largeUsage = ResourceUsage(
7373
total: 1000,
7474
active: 500,
75-
size: UInt64.max,
75+
sizeInBytes: UInt64.max,
7676
reclaimable: UInt64.max / 2
7777
)
7878

@@ -84,22 +84,22 @@ struct DiskUsageTests {
8484

8585
#expect(decoded.total == 1000)
8686
#expect(decoded.active == 500)
87-
#expect(decoded.size == UInt64.max)
87+
#expect(decoded.sizeInBytes == UInt64.max)
8888
#expect(decoded.reclaimable == UInt64.max / 2)
8989
}
9090

9191
@Test("ResourceUsage percentage calculations")
9292
func testPercentageCalculations() throws {
9393
// 0% reclaimable
94-
let noneReclaimable = ResourceUsage(total: 10, active: 10, size: 1000, reclaimable: 0)
95-
#expect(Double(noneReclaimable.reclaimable) / Double(noneReclaimable.size) == 0.0)
94+
let noneReclaimable = ResourceUsage(total: 10, active: 10, sizeInBytes: 1000, reclaimable: 0)
95+
#expect(Double(noneReclaimable.reclaimable) / Double(noneReclaimable.sizeInBytes) == 0.0)
9696

9797
// 50% reclaimable
98-
let halfReclaimable = ResourceUsage(total: 10, active: 5, size: 1000, reclaimable: 500)
99-
#expect(Double(halfReclaimable.reclaimable) / Double(halfReclaimable.size) == 0.5)
98+
let halfReclaimable = ResourceUsage(total: 10, active: 5, sizeInBytes: 1000, reclaimable: 500)
99+
#expect(Double(halfReclaimable.reclaimable) / Double(halfReclaimable.sizeInBytes) == 0.5)
100100

101101
// 100% reclaimable
102-
let allReclaimable = ResourceUsage(total: 10, active: 0, size: 1000, reclaimable: 1000)
103-
#expect(Double(allReclaimable.reclaimable) / Double(allReclaimable.size) == 1.0)
102+
let allReclaimable = ResourceUsage(total: 10, active: 0, sizeInBytes: 1000, reclaimable: 1000)
103+
#expect(Double(allReclaimable.reclaimable) / Double(allReclaimable.sizeInBytes) == 1.0)
104104
}
105105
}

0 commit comments

Comments
 (0)