Skip to content

Add some test helpers and structure for new classes #2212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions GoogleDataLogger/GoogleDataLogger/Classes/GDLUploader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2018 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

/** This class connects log storage and the backend implementations, providing logs to the uploaders
* and informing the log storage what logs were successfully uploaded or not.
*/
@interface GDLUploader : NSObject

/** Creates and/or returrns the singleton.
*
* @return The singleton instance of this class.
*/
+ (instancetype)sharedInstance;

/** Forces the backend specified by the target to upload the provided set of logs. This should only
* ever happen when the QoS tier of a log requires it.
*/
- (void)forceUploadLogs:(NSSet<NSURL *> *)logFiles target:(NSInteger)logTarget;

@end

NS_ASSUME_NONNULL_END
34 changes: 34 additions & 0 deletions GoogleDataLogger/GoogleDataLogger/Classes/GDLUploader.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2018 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import "GDLUploader.h"

@implementation GDLUploader

+ (instancetype)sharedInstance {
static GDLUploader *sharedUploader;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedUploader = [[GDLUploader alloc] init];
});
return sharedUploader;
}

- (void)forceUploadLogs:(NSSet<NSURL *> *)logFiles target:(NSInteger)logTarget {
// TODO
}

@end
32 changes: 32 additions & 0 deletions GoogleDataLogger/Tests/GDLLogUploaderTest.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2018 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <XCTest/XCTest.h>

#import "GDLUploader.h"

@interface GDLUploaderTest : XCTestCase

@end

@implementation GDLUploaderTest

/** Tests the default initializer. */
- (void)testSharedInstance {
XCTAssertEqual([GDLUploader sharedInstance], [GDLUploader sharedInstance]);
}

@end
34 changes: 34 additions & 0 deletions GoogleDataLogger/Tests/Helpers/GDLTestBackend.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2018 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>

#import "GDLLogBackend.h"

NS_ASSUME_NONNULL_BEGIN

/** This class implements the log backend protocol for testing purposes, providing APIs to allow
* tests to alter the uploader behavior without creating a bunch of specialized classes.
*/
@interface GDLTestBackend : NSObject <GDLLogBackend>

/** A block that can be ran in -uploadLogs:onComplete:. */
@property(nullable, nonatomic) void (^uploadLogsBlock)
(NSSet<NSURL *> *logFiles, GDLBackendCompletionBlock completionBlock);

@end

NS_ASSUME_NONNULL_END
29 changes: 29 additions & 0 deletions GoogleDataLogger/Tests/Helpers/GDLTestBackend.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2018 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import "GDLTestBackend.h"

@implementation GDLTestBackend

- (void)uploadLogs:(NSSet<NSURL *> *)logFiles onComplete:(GDLBackendCompletionBlock)onComplete {
if (_uploadLogsBlock) {
_uploadLogsBlock(logFiles, onComplete);
} else if (onComplete) {
onComplete(nil, nil);
}
}

@end
36 changes: 36 additions & 0 deletions GoogleDataLogger/Tests/Helpers/GDLTestPrioritizer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2018 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>

#import <GoogleDataLogger/GDLLogPrioritizer.h>

NS_ASSUME_NONNULL_BEGIN

/** This class implements the log prioritizer protocol for testing purposes, providing APIs to allow
* tests to alter the prioritizer behavior without creating a bunch of specialized classes.
*/
@interface GDLTestPrioritizer : NSObject <GDLLogPrioritizer>

/** The return value of -logsForNextUpload. */
@property(nullable, nonatomic) NSSet<NSNumber *> *logsForNextUploadFake;

/** Allows the running of a block of code during -prioritizeLog. */
@property(nullable, nonatomic) void (^prioritizeLogBlock)(GDLLogEvent *logEvent);

@end

NS_ASSUME_NONNULL_END
39 changes: 39 additions & 0 deletions GoogleDataLogger/Tests/Helpers/GDLTestPrioritizer.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2018 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import "GDLTestPrioritizer.h"

@implementation GDLTestPrioritizer

- (instancetype)init {
self = [super init];
if (self) {
_logsForNextUploadFake = [[NSSet alloc] init];
}
return self;
}

- (NSSet<NSNumber *> *)logsForNextUpload {
return _logsForNextUploadFake;
}

- (void)prioritizeLog:(GDLLogEvent *)logEvent {
if (_prioritizeLogBlock) {
_prioritizeLogBlock(logEvent);
}
}

@end