in glean-core/ios/GleanTests/Metrics/PingTests.swift [37:86]
func testSendingOfCustomPings() {
let customPing = Ping<NoReasonCodes>(
name: "custom",
includeClientId: true,
sendIfEmpty: false,
preciseTimestamps: true,
includeInfoSections: true,
enabled: true,
schedulesPings: [],
reasonCodes: [],
followsCollectionEnabled: true,
uploaderCapabilities: []
)
let counter = CounterMetricType(CommonMetricData(
category: "telemetry",
name: "counter_metric",
sendInPings: ["custom"],
lifetime: .application,
disabled: false
))
setupHttpResponseStub("custom")
expectation = expectation(description: "Completed upload")
counter.add()
XCTAssertNotNil(counter.testGetValue())
var callbackWasCalled = false
customPing.testBeforeNextSubmit { reason in
XCTAssertNil(reason, "Unexpected reason for custom ping submitted")
XCTAssertEqual(1, counter.testGetValue(), "Unexpected value for counter in custom ping")
callbackWasCalled = true
}
customPing.submit()
XCTAssert(callbackWasCalled, "Expected callback to be called by now.")
waitForExpectations(timeout: 5.0) { error in
XCTAssertNil(error, "Test timed out waiting for upload: \(error!)")
}
let clientInfo = lastPingJson?["client_info"] as? [String: Any]
XCTAssertEqual("iOS", clientInfo?["os"] as? String)
XCTAssertEqual(UIDevice.current.systemVersion, clientInfo?["os_version"] as? String)
XCTAssertNotNil(clientInfo?["client_id"] as? String)
XCTAssertNotNil(clientInfo?["device_model"] as? String)
XCTAssertNotNil(clientInfo?["device_manufacturer"] as? String)
XCTAssertNotNil(clientInfo?["locale"] as? String)
}