-
Notifications
You must be signed in to change notification settings - Fork 245
/
Copy pathinstaller_spec.rb
121 lines (103 loc) · 3.99 KB
/
installer_spec.rb
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
109
110
111
112
113
114
115
116
117
118
119
120
121
require File.expand_path('../spec_helper', __FILE__)
module XcodeInstall
describe '#fetch' do
before do
client = mock
client.stubs(:cookie).returns('customCookie')
Spaceship::PortalClient.stubs(:login).returns(client)
end
it 'downloads the file and calls the `progress_block` with the percentage' do
installer = Installer.new
xcode = XcodeInstall::Xcode.new('name' => 'Xcode 9.3',
'files' => [{
'remotePath' => '/Developer_Tools/Xcode_9.3/Xcode_9.3.xip'
}])
installer.stubs(:fetch_seedlist).returns([xcode])
stdin = 'stdin'
stdout = 'stdout'
stderr = 'stderr'
wait_thr = 'wait_thr'
stdin.stubs(:close)
stdout.stubs(:close)
stderr.stubs(:close)
current_time = '123123'
Time.stubs(:now).returns(current_time)
xip_path = File.join(File.expand_path('~'), '/Library/Caches/XcodeInstall/Xcode_9.3.xip')
progress_log_file = File.join(File.expand_path('~'), "/Library/Caches/XcodeInstall/progress.#{current_time}.progress")
command = [
'curl',
'--disable',
'--cookie customCookie',
'--cookie-jar /tmp/curl-cookies.txt',
'--retry 3',
'--location',
'--continue-at -',
"--output #{xip_path}",
'https://developer.apple.com/devcenter/download.action\\?path\\=/Developer_Tools/Xcode_9.3/Xcode_9.3.xip',
"2> #{progress_log_file}"
]
Open3.stubs(:popen3).with(command.join(' ')).returns([stdin, stdout, stderr, wait_thr])
wait_thr.stubs(:alive?).returns(true)
thr_value = 'thr_value'
wait_thr.stubs(:value).returns(thr_value)
thr_value.stubs(:success?).returns(true)
installer.stubs(:install_dmg).with(Pathname.new(xip_path), '-9.3', false, false)
Thread.new do
sleep(1)
File.write(progress_log_file, ' 0 4766M 0 6835k 0 0 573k 0 2:21:58 0:00:11 2:21:47 902k')
sleep(1)
File.write(progress_log_file, ' 5 4766M 0 6835k 0 0 573k 0 2:21:58 0:00:11 2:21:47 902k')
sleep(1)
File.write(progress_log_file, '50 4766M 0 6835k 0 0 573k 0 2:21:58 0:00:11 2:21:47 902k')
sleep(1)
File.write(progress_log_file, '100 4766M 0 6835k 0 0 573k 0 2:21:58 0:00:11 2:21:47 902k')
sleep(0.5)
wait_thr.stubs(:alive?).returns(false)
end
percentages = []
installer.install_version(
# version: the version to install
'9.3',
# `should_switch
false,
# `should_clean`
false, # false for now for faster debugging
# `should_install`
true,
# `progress`
false,
# `url` is nil, as we don't have a custom source
nil,
# `show_release_notes` is `false`, as this is a non-interactive machine
false,
# `progress_block` be updated on the download progress
proc do |percent|
percentages << percent
end
)
percentages.each do |current_percent|
# Verify all reported percentages are between 0 and 100
current_percent.should.be.close(50, 50)
end
# Verify we got a good amount of percentages reported
percentages.count.should.be.close(8, 4)
end
end
describe '#find_xcode_version' do
it 'should find the one with the matching name' do
installer = Installer.new
xcodes = [
XcodeInstall::Xcode.new('name' => '11.4 beta 2',
'files' => [{
'remotePath' => '/Developer_Tools/Xcode_11.4_beta_2/Xcode_11.4_beta_2.xip'
}]),
XcodeInstall::Xcode.new('name' => '11.4',
'files' => [{
'remotePath' => '/Developer_Tools/Xcode_11.4/Xcode_11.4.xip'
}])
]
installer.stubs(:fetch_seedlist).returns(xcodes)
installer.find_xcode_version("11.4").name.should.be.equal("11.4")
end
end
end