-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_server_installer_test.rb
executable file
·161 lines (134 loc) · 4.97 KB
/
update_server_installer_test.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# @BEGIN_LICENSE
#
# Halyard - Multimedia authoring and playback system
# Copyright 1993-2009 Trustees of Dartmouth College
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
# USA.
#
# @END_LICENSE
require 'test/unit'
require 'buildscript/update_server_installer'
require 'buildscript/manifest_parser'
require 'pathname'
require 'fileutils'
include FileUtils
class UpdateServerInstallerTest < Test::Unit::TestCase
include ManifestParser
NullHash = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
FooHash = '855426068ee8939df6bce2c2c4b1e7346532a133'
USI = UpdateServerInstaller
def setup
rm_rf 'test_build_tmp'
mkdir_p 'test_build_tmp'
@root = Pathname.new('test_build_tmp')
@pool = @root + 'pool'
@manifests = @root + 'manifests'
end
def teardown
chmod_R 0755, 'test_build_tmp'
rm_rf 'test_build_tmp'
end
def check_manifest_dir build_id
manifest_dir = @manifests + build_id
assert @manifests.directory?
assert manifest_dir.directory?
#assert !manifest_dir.writable?
['release.spec', 'release.spec.sig',
'MANIFEST.base', 'MANIFEST.sub'].each do |file|
assert_include manifest_dir.entries, Pathname.new(file)
assert !(manifest_dir+file).writable?
end
end
def check_pool hash, contents
assert @pool.directory?
assert_equal contents, (@pool+hash).read
assert !(@pool+hash).writable?
end
def check_spec file, build_id
spec_file = @root+file
# check that these point to something
assert spec_file.exist?, "No spec file"
assert (@root+(file+".sig")).exist?, "No spec sig"
spec = parse_spec_file(spec_file.read)
assert_equal build_id, spec["Build"] # check that we have the right spec
end
def check_spec_log spec, before, after, fields={ }
log_file = @root+(spec+'.log')
UpdateServer.parse_log(log_file.read).each do |line|
if (line[:before] == before && line[:after] == after)
fields.each do |key, val|
assert_equal val, line[key]
end
return
end
end
assert false, "Did not find log of #{before} to #{after} in #{log_file}"
end
def test_build_manifest_dir
installer = USI.new('updater-fixtures/base', 'test_build_tmp')
installer.build_manifest_dir
check_manifest_dir 'base'
end
def test_populate_pool
installer = USI.new('updater-fixtures/base', 'test_build_tmp')
installer.populate_pool
check_pool NullHash, ''
end
def test_server_installer_base
installer = USI.new('updater-fixtures/base', 'test_build_tmp')
installer.build_update_installer
check_spec 'staging.spec', 'base'
check_spec_log 'staging.spec', '<null>', 'base'
end
def test_release_from_staging
base_installer = USI.new("updater-fixtures/base", "test_build_tmp")
base_installer.build_update_installer
UpdateServer.new("test_build_tmp").release_from_staging
check_spec 'release.spec', 'base'
check_spec_log 'release.spec', '<null>', 'base'
check_spec 'staging.spec', 'base'
check_spec_log 'staging.spec', '<null>', 'base'
end
# This is a test of an entire process, from building an update,
# releasing one, and building a new one.
def test_server_installer_update
base_installer = USI.new("updater-fixtures/base", "test_build_tmp",
:user => 'test-builder')
base_installer.build_update_installer
update_server = UpdateServer.new("test_build_tmp", :user => 'test-releaser')
update_server.release_from_staging "v1.0"
update_installer = USI.new("updater-fixtures/update", "test_build_tmp",
:user => 'test-builder')
update_installer.build_update_installer
check_manifest_dir 'base'
check_manifest_dir 'update'
check_pool NullHash, ''
check_pool FooHash, "foo\r\n"
check_spec 'release.spec', 'base'
check_spec_log('release.spec', '<null>', 'base',
:notes => "v1.0", :user => 'test-releaser')
check_spec 'staging.spec', 'update'
check_spec_log 'staging.spec', '<null>', 'base', :user => 'test-builder'
check_spec_log 'staging.spec', 'base', 'update', :user => 'test-builder'
end
def assert_include array, item, message = nil
message = build_message(message, '<?> does not contain <?>',
array, item)
assert_block(message) do
array.include? item
end
end
end