forked from aws-amplify/aws-sdk-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAWSGeneralSageMakerRuntimeTests.m
108 lines (85 loc) · 4.62 KB
/
AWSGeneralSageMakerRuntimeTests.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//
// Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License").
// You may not use this file except in compliance with the License.
// A copy of the License is located at
//
// http://aws.amazon.com/apache2.0
//
// or in the "license" file accompanying this file. This file 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 <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import "OCMock.h"
#import "AWSTestUtility.h"
#import "AWSSageMakerRuntimeService.h"
static id mockNetworking = nil;
@interface AWSGeneralSageMakerRuntimeTests : XCTestCase
@end
@implementation AWSGeneralSageMakerRuntimeTests
- (void)setUp {
[super setUp];
[AWSTestUtility setupFakeCognitoCredentialsProvider];
mockNetworking = OCMClassMock([AWSNetworking class]);
AWSTask *errorTask = [AWSTask taskWithError:[NSError errorWithDomain:@"OCMockExpectedNetworkingError" code:8848 userInfo:nil]];
OCMStub([mockNetworking sendRequest:[OCMArg isKindOfClass:[AWSNetworkingRequest class]]]).andReturn(errorTask);
}
- (void)tearDown {
[super tearDown];
}
- (void)testConstructors {
NSString *key = @"testSageMakerRuntimeConstructors";
XCTAssertNotNil([AWSSageMakerRuntime defaultSageMakerRuntime]);
XCTAssertEqual([[AWSSageMakerRuntime defaultSageMakerRuntime] class], [AWSSageMakerRuntime class]);
XCTAssertNil([AWSSageMakerRuntime SageMakerRuntimeForKey:key]);
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionSAEast1 credentialsProvider:[AWSServiceManager defaultServiceManager].defaultServiceConfiguration.credentialsProvider];
[AWSSageMakerRuntime registerSageMakerRuntimeWithConfiguration:configuration forKey:key];
XCTAssertNotNil([AWSSageMakerRuntime SageMakerRuntimeForKey:key]);
XCTAssertEqual([[AWSSageMakerRuntime SageMakerRuntimeForKey:key] class], [AWSSageMakerRuntime class]);
XCTAssertEqual([AWSSageMakerRuntime SageMakerRuntimeForKey:key].configuration.regionType, AWSRegionSAEast1);
[AWSSageMakerRuntime removeSageMakerRuntimeForKey:key];
XCTAssertNil([AWSSageMakerRuntime SageMakerRuntimeForKey:key]);
}
- (void)testInvokeEndpoint {
NSString *key = @"testInvokeEndpoint";
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil];
[AWSSageMakerRuntime registerSageMakerRuntimeWithConfiguration:configuration forKey:key];
AWSSageMakerRuntime *awsClient = [AWSSageMakerRuntime SageMakerRuntimeForKey:key];
XCTAssertNotNil(awsClient);
XCTAssertNotNil(mockNetworking);
[awsClient setValue:mockNetworking forKey:@"networking"];
[[[[AWSSageMakerRuntime SageMakerRuntimeForKey:key] invokeEndpoint:[AWSSageMakerRuntimeInvokeEndpointInput new]] continueWithBlock:^id(AWSTask *task) {
XCTAssertNotNil(task.error);
XCTAssertEqualObjects(@"OCMockExpectedNetworkingError", task.error.domain);
XCTAssertEqual(8848, task.error.code);
XCTAssertNil(task.result);
return nil;
}] waitUntilFinished];
OCMVerify([mockNetworking sendRequest:[OCMArg isNotNil]]);
[AWSSageMakerRuntime removeSageMakerRuntimeForKey:key];
}
- (void)testInvokeEndpointCompletionHandler {
NSString *key = @"testInvokeEndpoint";
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil];
[AWSSageMakerRuntime registerSageMakerRuntimeWithConfiguration:configuration forKey:key];
AWSSageMakerRuntime *awsClient = [AWSSageMakerRuntime SageMakerRuntimeForKey:key];
XCTAssertNotNil(awsClient);
XCTAssertNotNil(mockNetworking);
[awsClient setValue:mockNetworking forKey:@"networking"];
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
[[AWSSageMakerRuntime SageMakerRuntimeForKey:key] invokeEndpoint:[AWSSageMakerRuntimeInvokeEndpointInput new] completionHandler:^(AWSSageMakerRuntimeInvokeEndpointOutput* _Nullable response, NSError * _Nullable error) {
XCTAssertNotNil(error);
XCTAssertEqualObjects(@"OCMockExpectedNetworkingError", error.domain);
XCTAssertEqual(8848, error.code);
XCTAssertNil(response);
dispatch_semaphore_signal(semaphore);
}];
dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, (int)(2.0 * NSEC_PER_SEC)));
OCMVerify([mockNetworking sendRequest:[OCMArg isNotNil]]);
[AWSSageMakerRuntime removeSageMakerRuntimeForKey:key];
}
@end