Skip to content

Commit

Permalink
Made changes to incorporate feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmarkowsky committed Sep 22, 2021
1 parent 1b2b090 commit 52fe79c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 15 deletions.
1 change: 0 additions & 1 deletion Source/santametricservice/Formats/SNTMetricRawJSONFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@
#import "Source/santametricservice/Formats/SNTMetricFormat.h"

@interface SNTMetricRawJSONFormat : NSObject <SNTMetricFormat>
- (NSArray<NSData *> *)convert:(NSDictionary *)metrics error:(NSError **)err;
@end
8 changes: 7 additions & 1 deletion Source/santametricservice/Formats/SNTMetricRawJSONFormat.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ - (NSDictionary *)normalize:(NSDictionary *)metrics {
NSDictionary *normalizedMetrics = [self normalize:metrics];

if (![NSJSONSerialization isValidJSONObject:normalizedMetrics]) {
LOGE(@"unable to convert metrics to JSON: invalid metrics");
*err = [[NSError alloc]
initWithDomain:@"SNTMetricRawJSONFileWriter"
code:EINVAL
userInfo:@{
NSLocalizedDescriptionKey : @"unable to convert metrics to JSON: invalid metrics"
}];

return nil;
}

Expand Down
1 change: 0 additions & 1 deletion Source/santametricservice/SNTMetricServiceTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ - (NSDictionary *)convertJSONDateStringsToNSDateWithJson:(NSDictionary *)jsonDat

- (void)testDefaultConfigOptionsDoNotExport {
SNTMetricService *ms = [[SNTMetricService alloc] init];
// OCMStub([self.mockConfigurator exportMetrics]).andReturn(NO);

[ms exportForMonitoring:validMetricsDict];

Expand Down
2 changes: 1 addition & 1 deletion Source/santametricservice/Writers/SNTMetricFileWriter.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ - (BOOL)write:(NSArray<NSData *> *)metrics toURL:(NSURL *)url error:(NSError **)
if (@available(macos 10.15, *)) {
[file writeData:entryData error:error];

if (*error != nil) {
if (error != nil && *error != nil) {
return NO;
}
} else {
Expand Down
14 changes: 3 additions & 11 deletions Source/santametricservice/Writers/SNTMetricFileWriterTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,9 @@ - (void)testWritingDataToFileWorks {

BOOL success = [fileWriter write:input toURL:url error:&err];

if (!success) {
NSLog(@"error: %@\n", err);
}

XCTAssertEqual(YES, success);
XCTAssertTrue(success, @"error: %@", err);
XCTAssertNil(err);

const char newline[1] = {'\n'};

// Read file ensure it only contains the first line followed by a Newline
Expand All @@ -82,12 +79,7 @@ - (void)testWritingDataToFileWorks {
input = @[ firstLine, secondLine ];

success = [fileWriter write:input toURL:url error:&err];
XCTAssertEqual(YES, success);
XCTAssertNil(err);

if (!success) {
NSLog(@"error: %@\n", err);
}
XCTAssertTrue(success, @"error: %@", err);

testFileContents = [NSData dataWithContentsOfFile:url.path];
XCTAssertEqualObjects(expected, testFileContents);
Expand Down

0 comments on commit 52fe79c

Please sign in to comment.