-
Notifications
You must be signed in to change notification settings - Fork 28
/
TestArgFile.swift
77 lines (65 loc) · 3.27 KB
/
TestArgFile.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import EmceeExtensions
import Foundation
import MetricsExtensions
import QueueModels
/// Represents --test-arg-file file contents which describes test plan.
public struct TestArgFile: Codable, Equatable {
public private(set) var entries: [TestArgFileEntry]
public let prioritizedJob: PrioritizedJob
public let testDestinationConfigurations: [TestDestinationConfiguration]
public init(
entries: [TestArgFileEntry],
prioritizedJob: PrioritizedJob,
testDestinationConfigurations: [TestDestinationConfiguration]
) {
self.entries = entries
self.prioritizedJob = prioritizedJob
self.testDestinationConfigurations = testDestinationConfigurations
}
public func with(entries: [TestArgFileEntry]) -> Self {
var result = self
result.entries = entries
return result
}
private enum CodingKeys: String, CodingKey {
case entries
case prioritizedJob
case testDestinationConfigurations
case analyticsConfiguration
case jobGroupId
case jobGroupPriority
case jobId
case jobPriority
case persistentMetricsJobId
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let entries = try container.decodeExplaining([TestArgFileEntry].self, forKey: .entries)
let prioritizedJob = try container.decodeIfPresentExplaining(PrioritizedJob.self, forKey: .prioritizedJob) ?? { () -> PrioritizedJob in
let jobId = try container.decodeIfPresentExplaining(JobId.self, forKey: .jobId) ?? TestArgFileDefaultValues.createAutomaticJobId()
let jobPriority = try container.decodeIfPresentExplaining(Priority.self, forKey: .jobPriority) ?? TestArgFileDefaultValues.priority
let jobGroupId = try container.decodeIfPresentExplaining(JobGroupId.self, forKey: .jobGroupId) ?? JobGroupId(jobId.value)
let jobGroupPriority = try container.decodeIfPresentExplaining(Priority.self, forKey: .jobGroupPriority) ?? jobPriority
let analyticsConfiguration = try container.decodeIfPresentExplaining(AnalyticsConfiguration.self, forKey: .analyticsConfiguration) ?? TestArgFileDefaultValues.analyticsConfiguration
return PrioritizedJob(
analyticsConfiguration: analyticsConfiguration,
jobGroupId: jobGroupId,
jobGroupPriority: jobGroupPriority,
jobId: jobId,
jobPriority: jobPriority
)
}()
let testDestinationConfigurations = try container.decodeIfPresentExplaining([TestDestinationConfiguration].self, forKey: .testDestinationConfigurations) ?? []
self.init(
entries: entries,
prioritizedJob: prioritizedJob,
testDestinationConfigurations: testDestinationConfigurations
)
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(entries, forKey: .entries)
try container.encode(prioritizedJob, forKey: .prioritizedJob)
try container.encode(testDestinationConfigurations, forKey: .testDestinationConfigurations)
}
}