Skip to content

Commit

Permalink
NR-348708: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
cdillard-NewRelic committed Jan 28, 2025
1 parent f496c28 commit d1d0b7c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@
}
@property (nonatomic) int fileDescriptor;
@property (nonatomic, strong) dispatch_source_t source;

@property id mockNewRelicInternals;

@end
20 changes: 18 additions & 2 deletions Tests/Unit-Tests/NewRelicAgentTests/Uncategorized/NRLoggerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@
#import "NRTestConstants.h"
#import "NRAutoLogCollector.h"
#import <os/log.h>
#import "NewRelicAgentInternal.h"
#import <OCMock/OCMock.h>

@interface NRLogger()
+ (NRLogger *)logger;
- (NSMutableDictionary*) commonBlockDict;
@end

static NewRelicAgentInternal* _sharedInstance;

@implementation NRLoggerTests
- (void) setUp
{
Expand All @@ -39,9 +43,16 @@ - (void) setUp

[NRLogger setLogLevels:NRLogLevelDebug];
[NRLogger setRemoteLogLevel:NRLogLevelDebug];

[NRLogger setLogEntityGuid:@"Entity-Guid-XXXX"];


self.mockNewRelicInternals = [OCMockObject mockForClass:[NewRelicAgentInternal class]];
_sharedInstance = [[NewRelicAgentInternal alloc] init];
_sharedInstance.analyticsController = [[NRMAAnalytics alloc] initWithSessionStartTimeMS:0.0];
[[[[self.mockNewRelicInternals stub] classMethod] andReturn:_sharedInstance] sharedInstance];

[_sharedInstance.analyticsController setSessionAttribute:@"myAttribute" value:@(1)];

NRMAAgentConfiguration *config = [[NRMAAgentConfiguration alloc] initWithAppToken:[[NRMAAppToken alloc] initWithApplicationToken:kNRMA_ENABLED_STAGING_APP_TOKEN]
collectorAddress:KNRMA_TEST_COLLECTOR_HOST
crashAddress:nil];
Expand Down Expand Up @@ -86,7 +97,8 @@ - (void) tearDown

[NRMAMeasurements removeMeasurementConsumer:helper];
helper = nil;

[self.mockNewRelicInternals stopMocking];
_sharedInstance = nil;
[NRMAMeasurements shutdown];
[NRMAFlags disableFeatures: NRFeatureFlag_LogReporting];
[NRLogger setLogTargets:NRLogTargetConsole];
Expand Down Expand Up @@ -183,6 +195,10 @@ - (void) testNRLogger {
XCTAssertTrue([[decodedCommonBlock objectForKey:NRLogMessageInstrumentationProviderKey] isEqualToString:NRLogMessageMobileValue],@"instrumentation provider set incorrectly");
XCTAssertTrue([[decodedCommonBlock objectForKey:NRLogMessageInstrumentationVersionKey] isEqualToString:@"DEV"],@"instrumentation name set incorrectly");

// Check for added session attributes
XCTAssertTrue([[decodedCommonBlock objectForKey:@"myAttribute"] isEqualToNumber:@(1)],@"session attribute set incorrectly");


#if TARGET_OS_WATCH
XCTAssertTrue([[decodedCommonBlock objectForKey:NRLogMessageInstrumentationNameKey] isEqualToString:@"watchOSAgent"],@"instrumentation name set incorrectly");
#else
Expand Down

0 comments on commit d1d0b7c

Please sign in to comment.