forked from sparkle-project/Sparkle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSUInstallerTest.m
73 lines (57 loc) · 2.18 KB
/
SUInstallerTest.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
//
// SUInstallerTest.m
// Sparkle
//
// Created by Kornel on 24/04/2015.
// Copyright (c) 2015 Sparkle Project. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <XCTest/XCTest.h>
#import "SUHost.h"
#import "SUInstaller.h"
#import <unistd.h>
@interface SUInstallerTest : XCTestCase
@end
@implementation SUInstallerTest
- (void)setUp
{
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
#if __clang_major__ >= 6
- (void)testInstallIfRoot
{
uid_t uid = getuid();
if (uid) {
NSLog(@"Test must be run as root: sudo xctest -XCTest SUInstallerTest 'Sparkle Unit Tests.xctest'");
return;
}
NSString *expectedDestination = @"/tmp/sparklepkgtest.app";
NSFileManager *fm = [NSFileManager defaultManager];
[fm removeItemAtPath:expectedDestination error:nil];
XCTAssertFalse([fm fileExistsAtPath:expectedDestination isDirectory:nil]);
XCTestExpectation *done = [self expectationWithDescription:@"install finished"];
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSString *path = [bundle pathForResource:@"test.sparkle_guided" ofType:@"pkg"];
XCTAssertNotNil(path);
SUHost *host = [[SUHost alloc] initWithBundle:bundle];
NSString *fileOperationToolPath = [bundle pathForResource:@""SPARKLE_FILEOP_TOOL_NAME ofType:@""];
XCTAssertNotNil(fileOperationToolPath);
[SUInstaller installFromUpdateFolder:[path stringByDeletingLastPathComponent] overHost:host installationPath:@"/tmp" fileOperationToolPath:fileOperationToolPath versionComparator:nil completionHandler:^(NSError *error) {
if (error != nil) {
NSLog(@"Underlying error: %@", [error.userInfo objectForKey:NSUnderlyingErrorKey]);
}
XCTAssertNil(error);
XCTAssertTrue([fm fileExistsAtPath:expectedDestination isDirectory:nil]);
[done fulfill];
}];
[self waitForExpectationsWithTimeout:40 handler:nil];
[fm removeItemAtPath:expectedDestination error:nil];
}
#endif
@end