Skip to content

Commit

Permalink
add coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
breedx-splk committed Oct 24, 2023
1 parent 9530960 commit 60db1b4
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,36 @@ void emitWithTimestamp() {
assertThatCode(() -> emitter.emit(System.nanoTime(), "event-name", attributes))
.doesNotThrowAnyException();
}

@Test
void builder() {
Attributes attributes = Attributes.builder().put("key1", "value1").build();
EventEmitter emitter = DefaultEventEmitter.getInstance();
assertThatCode(
() ->
emitter
.builder()
.setEventName("myEvent")
.setAttributes(attributes)
.setTimestamp(123456L)
.emit())
.doesNotThrowAnyException();
}

@Test
void builderWithName() {
Attributes attributes = Attributes.builder().put("key1", "value1").build();
EventEmitter emitter = DefaultEventEmitter.getInstance();
assertThatCode(
() -> emitter.builder("myEvent").setAttributes(attributes).setTimestamp(123456L).emit())
.doesNotThrowAnyException();
}

@Test
void builderWithNameAndAttrs() {
Attributes attributes = Attributes.builder().put("key1", "value1").build();
EventEmitter emitter = DefaultEventEmitter.getInstance();
assertThatCode(() -> emitter.builder("myEvent", attributes).setTimestamp(123456L).emit())
.doesNotThrowAnyException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,52 @@ void emit_withTimestamp() {

emitter.emit(yesterday, "testing", attributes);

assertThat(seenLog.get().toLogRecordData())
.hasResource(RESOURCE)
.hasInstrumentationScope(InstrumentationScopeInfo.create("test-scope"))
.hasTimestamp(yesterday)
.hasAttributes(
attributes.toBuilder()
.put("event.domain", "unknown")
.put("event.name", "testing")
.build());
verifySeen(yesterday, attributes);
}

@Test
void builder() {
void builderWithNameAndAttributes() {
long yesterday = System.nanoTime() - TimeUnit.DAYS.toNanos(1);
Attributes attributes = Attributes.of(stringKey("foo"), "bar");

EventEmitter emitter = eventEmitterProvider.eventEmitterBuilder("test-scope").build();

emitter.builder("testing", attributes).setTimestamp(yesterday).emit();
verifySeen(yesterday, attributes);
}

@Test
void builderWithName() {
long yesterday = System.nanoTime() - TimeUnit.DAYS.toNanos(1);
Attributes attributes = Attributes.of(stringKey("foo"), "bar");

EventEmitter emitter = eventEmitterProvider.eventEmitterBuilder("test-scope").build();

emitter.builder("testing").setAttributes(attributes).setTimestamp(yesterday).emit();
verifySeen(yesterday, attributes);
}

@Test
void builder() {
long yesterday = System.nanoTime() - TimeUnit.DAYS.toNanos(1);
Attributes attributes = Attributes.of(stringKey("foo"), "bar");

EventEmitter emitter = eventEmitterProvider.eventEmitterBuilder("test-scope").build();

emitter
.builder()
.setEventName("testing")
.setAttributes(attributes)
.setTimestamp(yesterday)
.emit();
verifySeen(yesterday, attributes);
}

private void verifySeen(long timestamp, Attributes attributes) {
assertThat(seenLog.get().toLogRecordData())
.hasResource(RESOURCE)
.hasInstrumentationScope(InstrumentationScopeInfo.create("test-scope"))
.hasTimestamp(yesterday)
.hasTimestamp(timestamp)
.hasAttributes(
attributes.toBuilder()
.put("event.domain", "unknown")
Expand Down

0 comments on commit 60db1b4

Please sign in to comment.