Skip to content

Commit 93efcca

Browse files
committed
some more docs for the types
1 parent 1efc24b commit 93efcca

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

Sources/MetricsTestUtils/TestMetrics.swift

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,23 @@ extension TestMetrics.FullKey: Hashable {
143143

144144
extension TestMetrics {
145145
// ==== ------------------------------------------------------------------------------------------------------------
146-
147146
// MARK: Counter
148147

148+
/// Assert that the passed in `metric` is a ``TestCounter`` and return it for further executing assertions.
149149
public func expectCounter(_ metric: Counter) throws -> TestCounter {
150150
guard let counter = metric._handler as? TestCounter else {
151151
throw TestMetricsError.illegalMetricType(metric: metric._handler, expected: "\(TestCounter.self)")
152152
}
153153
return counter
154154
}
155155

156+
/// Locate a ``TestCounter`` created by the ``TestMetrics`` factory identified by the passed in ``label`` and ``dimensions``, and return it for further executing assertions.
157+
///
158+
/// - Parameters:
159+
/// - label: the expected label the looked for metric should have
160+
/// - dimensions: the expected dimensions the looked for metric should have
161+
/// - Returns: the underlying ``TestMetric``
162+
/// - Throws: when no such test metric was present
156163
public func expectCounter(_ label: String, _ dimensions: [(String, String)] = []) throws -> TestCounter {
157164
let maybeItem = self.lock.withLock {
158165
self.counters[.init(label: label, dimensions: dimensions)]
@@ -167,28 +174,41 @@ extension TestMetrics {
167174
}
168175

169176
// ==== ------------------------------------------------------------------------------------------------------------
170-
171177
// MARK: Gauge
172178

179+
/// Assert that the passed in `metric` is a ``TestRecorder`` and return it for further executing assertions.
173180
public func expectGauge(_ metric: Gauge) throws -> TestRecorder {
174181
return try self.expectRecorder(metric)
175182
}
176-
183+
/// Locate a ``TestRecorder`` created by the ``TestMetrics`` factory identified by the passed in ``label`` and ``dimensions``, and return it for further executing assertions.
184+
///
185+
/// - Parameters:
186+
/// - label: the expected label the looked for metric should have
187+
/// - dimensions: the expected dimensions the looked for metric should have
188+
/// - Returns: the underlying ``TestRecorder``
189+
/// - Throws: when no such test metric was present
177190
public func expectGauge(_ label: String, _ dimensions: [(String, String)] = []) throws -> TestRecorder {
178191
return try self.expectRecorder(label, dimensions)
179192
}
180193

181194
// ==== ------------------------------------------------------------------------------------------------------------
182-
183195
// MARK: Recorder
184196

197+
/// Assert that the passed in `metric` is a ``TestRecorder`` and return it for further executing assertions.
185198
public func expectRecorder(_ metric: Recorder) throws -> TestRecorder {
186199
guard let recorder = metric._handler as? TestRecorder else {
187200
throw TestMetricsError.illegalMetricType(metric: metric._handler, expected: "\(TestRecorder.self)")
188201
}
189202
return recorder
190203
}
191204

205+
/// Locate a ``TestRecorder`` created by the ``TestMetrics`` factory identified by the passed in ``label`` and ``dimensions``, and return it for further executing assertions.
206+
///
207+
/// - Parameters:
208+
/// - label: the expected label the looked for metric should have
209+
/// - dimensions: the expected dimensions the looked for metric should have
210+
/// - Returns: the underlying ``TestRecorder``
211+
/// - Throws: when no such test metric was present
192212
public func expectRecorder(_ label: String, _ dimensions: [(String, String)] = []) throws -> TestRecorder {
193213
let maybeItem = self.lock.withLock {
194214
self.recorders[.init(label: label, dimensions: dimensions)]
@@ -203,16 +223,23 @@ extension TestMetrics {
203223
}
204224

205225
// ==== ------------------------------------------------------------------------------------------------------------
206-
207226
// MARK: Timer
208227

228+
/// Assert that the passed in `metric` is a ``TestTimer`` and return it for further executing assertions.
209229
public func expectTimer(_ metric: CoreMetrics.Timer) throws -> TestTimer {
210230
guard let timer = metric._handler as? TestTimer else {
211231
throw TestMetricsError.illegalMetricType(metric: metric._handler, expected: "\(TestTimer.self)")
212232
}
213233
return timer
214234
}
215235

236+
/// Locate a ``TestTimer`` created by the ``TestMetrics`` factory identified by the passed in ``label`` and ``dimensions``, and return it for further executing assertions.
237+
///
238+
/// - Parameters:
239+
/// - label: the expected label the looked for metric should have
240+
/// - dimensions: the expected dimensions the looked for metric should have
241+
/// - Returns: the underlying ``TestTimer``
242+
/// - Throws: when no such test metric was present
216243
public func expectTimer(_ label: String, _ dimensions: [(String, String)] = []) throws -> TestTimer {
217244
let maybeItem = self.lock.withLock {
218245
self.timers[.init(label: label, dimensions: dimensions)]
@@ -231,12 +258,18 @@ extension TestMetrics {
231258

232259
// MARK: Metric type implementations
233260

261+
/// Common protocol for all test metrics, created by the ``TestMetrics`` metrics backend.
234262
public protocol TestMetric {
235263
associatedtype Value
236264

265+
/// Key used to identify a metric.
237266
var key: TestMetrics.FullKey { get }
238267

268+
/// Last metric value that was recorded into this metric.
239269
var lastValue: Value? { get }
270+
271+
/// Sequence of pairs of values reported into this metric, as well as the `Date` at which the metric was emitted.
272+
/// The sequence is ordered from oldest to latest, so you can e.g. assert a counter growing at an expected rate etc.
240273
var last: (Date, Value)? { get }
241274
}
242275

0 commit comments

Comments
 (0)