Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bryce-b committed Sep 18, 2023
1 parent a1e64a1 commit bf5f4ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,12 @@ class OtlpLogRecordExporterTests: XCTestCase {

func testImplicitGrpcLoggingConfig() throws {
let exporter = OtlpLogExporter(channel: channel)
guard let logger = exporter.callOptions?.logger else {
throw "Missing logger"
}
let logger = exporter.callOptions.logger
XCTAssertEqual(logger.label, "io.grpc")
}
func testExplicitGrpcLoggingConfig() throws {
let exporter = OtlpLogExporter(channel: channel, logger: Logger(label: "my.grpc.logger"))
guard let logger = exporter.callOptions?.logger else {
throw "Missing logger"
}
let logger = exporter.callOptions.logger
XCTAssertEqual(logger.label, "my.grpc.logger")
}

Expand All @@ -110,13 +106,13 @@ class OtlpLogRecordExporterTests: XCTestCase {
XCTAssertNotNil(exporter.config.headers)
XCTAssertEqual(exporter.config.headers?[0].0, "FOO")
XCTAssertEqual(exporter.config.headers?[0].1, "BAR")
XCTAssertEqual("BAR", exporter.callOptions?.customMetadata.first(name: "FOO"))
XCTAssertEqual("BAR", exporter.callOptions.customMetadata.first(name: "FOO"))
}

func testConfigHeadersAreSet_whenInitCalledWithExplicitHeaders() throws {
let exporter = OtlpLogExporter(channel: channel, envVarHeaders: [("FOO", "BAR")])
XCTAssertNil(exporter.config.headers)
XCTAssertEqual("BAR", exporter.callOptions?.customMetadata.first(name: "FOO"))
XCTAssertEqual("BAR", exporter.callOptions.customMetadata.first(name: "FOO"))
}

func testExportAfterShutdown() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,23 @@ class OtlpTraceExporterTests: XCTestCase {

func testImplicitGrpcLoggingConfig() throws {
let exporter = OtlpTraceExporter(channel: channel)
guard let logger = exporter.callOptions?.logger else {
throw "Missing logger"
}
XCTAssertEqual(logger.label, "io.grpc")
let logger = exporter.callOptions.logger
}

func testExplicitGrpcLoggingConfig() throws {
let exporter = OtlpTraceExporter(channel: channel, logger: Logger(label: "my.grpc.logger"))
guard let logger = exporter.callOptions?.logger else {
throw "Missing logger"
}
let logger = exporter.callOptions.logger
XCTAssertEqual(logger.label, "my.grpc.logger")
}

func verifyUserAgentIsSet(exporter: OtlpTraceExporter) {
if let callOptions = exporter.callOptions {
let customMetadata = callOptions.customMetadata
let userAgent = Headers.getUserAgentHeader()
if customMetadata.contains(name: Constants.HTTP.userAgent) && customMetadata.first(name: Constants.HTTP.userAgent) == userAgent {
return
}
let callOptions = exporter.callOptions
let customMetadata = callOptions.customMetadata
let userAgent = Headers.getUserAgentHeader()
if customMetadata.contains(name: Constants.HTTP.userAgent) && customMetadata.first(name: Constants.HTTP.userAgent) == userAgent {
return
}

XCTFail("User-Agent header was not set correctly")
}

Expand All @@ -88,15 +83,15 @@ class OtlpTraceExporterTests: XCTestCase {
XCTAssertNotNil(exporter.config.headers)
XCTAssertEqual(exporter.config.headers?[0].0, "FOO")
XCTAssertEqual(exporter.config.headers?[0].1, "BAR")
XCTAssertEqual("BAR", exporter.callOptions?.customMetadata.first(name: "FOO"))
XCTAssertEqual("BAR", exporter.callOptions.customMetadata.first(name: "FOO"))

verifyUserAgentIsSet(exporter: exporter)
}

func testConfigHeadersAreSet_whenInitCalledWithExplicitHeaders() throws {
let exporter = OtlpTraceExporter(channel: channel, envVarHeaders: [("FOO", "BAR")])
XCTAssertNil(exporter.config.headers)
XCTAssertEqual("BAR", exporter.callOptions?.customMetadata.first(name: "FOO"))
XCTAssertEqual("BAR", exporter.callOptions.customMetadata.first(name: "FOO"))

verifyUserAgentIsSet(exporter: exporter)
}
Expand Down

0 comments on commit bf5f4ec

Please sign in to comment.