|
7 | 7 | //
|
8 | 8 |
|
9 | 9 | #import <XCTest/XCTest.h>
|
| 10 | +#import "CCPackage.h" |
| 11 | +#import "CCPackageInstallData.h" |
| 12 | +#import "CCPackage+InstallData.h" |
| 13 | +#import "CCPackageInstaller.h" |
| 14 | +#import "CCDirector.h" |
| 15 | +#import "CCFileUtils.h" |
| 16 | +#import "CCPackageConstants.h" |
10 | 17 |
|
11 | 18 | @interface CCPackageInstallerTests : XCTestCase
|
12 | 19 |
|
| 20 | +@property (nonatomic, strong) CCPackage *package; |
| 21 | +@property (nonatomic, strong) CCPackageInstallData *installData; |
| 22 | +@property (nonatomic, copy) NSString *installPath; |
| 23 | +@property (nonatomic, strong) CCPackageInstaller *installer; |
| 24 | + |
13 | 25 | @end
|
14 | 26 |
|
| 27 | + |
15 | 28 | @implementation CCPackageInstallerTests
|
16 | 29 |
|
17 | 30 | - (void)setUp
|
18 | 31 | {
|
19 | 32 | [super setUp];
|
20 |
| - // Put setup code here. This method is called before the invocation of each test method in the class. |
| 33 | + |
| 34 | + self.package = [[CCPackage alloc] initWithName:@"Test" |
| 35 | + resolution:@"phonehd" |
| 36 | + os:@"iOS" |
| 37 | + remoteURL:[NSURL URLWithString:@"http://test.foo"]]; |
| 38 | + |
| 39 | + self.installData = [[CCPackageInstallData alloc] initWithPackage:_package]; |
| 40 | + [_package setInstallData:_installData]; |
| 41 | + |
| 42 | + NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]; |
| 43 | + self.installPath = [cachesPath stringByAppendingPathComponent:@"tests.Packages"]; |
| 44 | + |
| 45 | + self.installer = [[CCPackageInstaller alloc] initWithPackage:_package installPath:_installPath]; |
| 46 | + |
| 47 | + |
| 48 | + [self deleteInstallData]; |
| 49 | + |
| 50 | + [self createPackageInstallFolder]; |
| 51 | +} |
| 52 | + |
| 53 | +- (void)createPackageInstallFolder |
| 54 | +{ |
| 55 | + NSError *error; |
| 56 | + NSFileManager *fileManager = [NSFileManager defaultManager]; |
| 57 | + if (![fileManager createDirectoryAtURL:[NSURL fileURLWithPath:_installPath] |
| 58 | + withIntermediateDirectories:YES |
| 59 | + attributes:nil |
| 60 | + error:&error]) |
| 61 | + { |
| 62 | + NSLog(@"%@", error); |
| 63 | + } |
21 | 64 | }
|
22 | 65 |
|
23 | 66 | - (void)tearDown
|
24 | 67 | {
|
25 |
| - // Put teardown code here. This method is called after the invocation of each test method in the class. |
| 68 | + [self deleteInstallData]; |
| 69 | + |
26 | 70 | [super tearDown];
|
27 | 71 | }
|
28 | 72 |
|
29 |
| -- (void)testExample |
| 73 | +- (void)deleteInstallData |
| 74 | +{ |
| 75 | + NSFileManager *fileManager = [NSFileManager defaultManager]; |
| 76 | + |
| 77 | + NSError *error; |
| 78 | + if (![fileManager removeItemAtPath:_installPath error:&error]) |
| 79 | + { |
| 80 | + // NSLog(@"%@", error); |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +- (void)testInstallWithoutEnablingPackage |
30 | 85 | {
|
31 |
| - XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); |
| 86 | + [self setupInstallablePackage]; |
| 87 | + |
| 88 | + NSError *error; |
| 89 | + BOOL success = [_installer installWithError:&error]; |
| 90 | + XCTAssertTrue(success, @"Installation was unsuccessful: %@", error); |
| 91 | + XCTAssertEqual(_package.status, CCPackageStatusInstalledDisabled); |
| 92 | +} |
| 93 | + |
| 94 | +- (void)setupInstallablePackage |
| 95 | +{ |
| 96 | + NSString *pathToPackage = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Resources-shared/Packages/testpackage-iOS-phonehd_unzipped"]; |
| 97 | + |
| 98 | + _installData.unzipURL = [NSURL fileURLWithPath:pathToPackage]; |
| 99 | + _installData.folderName = @"testpackage-iOS-phonehd"; |
| 100 | + _installData.enableOnDownload = NO; |
| 101 | +} |
| 102 | + |
| 103 | +- (void)testInstallFailingUnzippedPackageDoesNotExist |
| 104 | +{ |
| 105 | + NSString *pathToPackage = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Resources-shared/Packages/DOES_NOT_EXIST"]; |
| 106 | + _installData.unzipURL = [NSURL fileURLWithPath:pathToPackage]; |
| 107 | + |
| 108 | + NSError *error; |
| 109 | + BOOL success = [_installer installWithError:&error]; |
| 110 | + XCTAssertFalse(success, @"Installation was successful: %@", error); |
| 111 | + XCTAssertEqual(_package.status, CCPackageStatusInstallationFailed); |
| 112 | + XCTAssertEqual(error.code, PACKAGE_ERROR_INSTALL_UNZIPPED_PACKAGE_NOT_FOUND); |
| 113 | +} |
| 114 | + |
| 115 | +- (void)testInstallFailingPackageAlreadyExists |
| 116 | +{ |
| 117 | + [self setupInstallablePackage]; |
| 118 | + |
| 119 | + NSFileManager *fileManager = [NSFileManager defaultManager]; |
| 120 | + [fileManager createDirectoryAtPath:[_installPath stringByAppendingPathComponent:@"testpackage-iOS-phonehd"] |
| 121 | + withIntermediateDirectories:YES |
| 122 | + attributes:nil |
| 123 | + error:nil]; |
| 124 | + |
| 125 | + NSError *error; |
| 126 | + BOOL success = [_installer installWithError:&error]; |
| 127 | + XCTAssertFalse(success, @"Installation was successful: %@", error); |
| 128 | + XCTAssertEqual(_package.status, CCPackageStatusInstallationFailed); |
| 129 | + XCTAssertEqual(error.code, PACKAGE_ERROR_INSTALL_COULD_NOT_MOVE_PACKAGE_TO_INSTALL_FOLDER); |
32 | 130 | }
|
33 | 131 |
|
34 | 132 | @end
|
0 commit comments