]> git.donarmstrong.com Git - wannabuild.git/blob - tests/tests.sh
Simple test-suite for wanna-build
[wannabuild.git] / tests / tests.sh
1 #!/bin/bash
2
3 #
4 # This file runs wanna-build in a clean environment to make sure, certain
5 # features work as expected.
6 #
7 # At the moment it
8 #  * Uploads a source
9 #  * Take the build
10 #  * Marks it as uploaded
11 #  * Uploads a source with build-depends
12 #  - Makes sure the package is marked Dep-Wait
13 #  * Uploads a new version of the dependency
14 #  - Makes sure the Dep-Wait is cleared
15 #
16
17 parent_pid=$$
18
19 function assert {
20         if ! eval $1
21         then
22                 echo "Assertion failed: $1"
23                 exit 1;
24         fi
25 }
26
27 function assert_grep {
28         cat > $testdir/assert_grep
29         if ! grep -q "$1" $testdir/assert_grep 
30         then
31           echo "Could not find expected \"$1\" in:"
32           cat $testdir/assert_grep
33           # We are in a pipe, i.e. a subshell, so kill the parent 
34           kill -TERM $parent_pid
35           exit 1
36         fi
37 }
38
39 cd "$(dirname $0)"/..
40
41 assert "[ -e bin/wanna-build ]"
42
43 testdir=./tests/tmp
44 rm -rf $testdir
45 mkdir -p $testdir
46
47 # This is a fake configuration file to make sure we do not interfere with a
48 # possibly installed wanna-build instance
49 cat > $testdir/wanna-build.conf <<__END__
50 \$basedir = "$testdir/db";
51 \$ignore_epochs = 0;
52 \$db_maint = "wb-team\@dontsend.buildd.debian.org";
53 \$notforus_maint = "notforus\@dontsend.buildd.debian.org";
54 \$stat_mail = "wb-team\@dontsend.buildd.debian.org";
55 \$buildd_domain = "buildd.debian.org";
56 \$web_stats = "/var/www/buildd/stats.txt";
57 @sections = qw(main contrib non-US/main non-US/contrib);
58 \$pkgs_source = "$testdir/ftp";
59 \$quinn_source = "$testdir/quinn-diff-output";
60 \$quinn_source_multi_section = 0;
61 @admin_users = qw(wbadm $USER);
62 %distributions = (
63         "unstable" => { },
64 );
65 # don't remove this, Perl needs it:
66 1;
67 __END__
68
69 mkdir $testdir/db;
70 mkdir $testdir/db/amd64;
71
72 function wanna-build {
73         # Here we make sure that the "require /etc/wanan-build.conf" does not
74         # have effect, and load our own file instead.
75         echo "Executing wanna-build" "$@" >&2
76         export PERL5LIB=/home/jojo/debian/wanna-build/testsetup/bin
77         perl -e '
78           package conf;
79           do "./tests/tmp/wanna-build.conf";
80           $INC{"/etc/wanna-build.conf"}=1;
81           package main;
82           my $ret;
83           eval {
84                 require "./bin/wanna-build";
85           };
86           if ($@) { die $@; }
87         ' -- "$@"
88 }
89
90 # Create database
91 wanna-build -A amd64 -b amd64/build-db --create-db --info no-package-1.2.3
92
93 echo Load some sources
94 wanna-build -A amd64 -b amd64/build-db --merge-all <(cat <<__END__ 
95 Package: bin-a-indep
96 Version: 1
97 Architecture: all
98 Source: src-a
99 __END__
100 ) <( cat <<__END__ 
101 misc/src-a_1.dsc [optional:uncompiled]
102 __END__
103 )  <( cat <<__END__
104 Package: src-a
105 Version: 1
106 Architecture: any
107 Section: misc
108 Priority: standard
109 Build-Depends: compiler
110 Binary: bin-a-indep,bin-a-1
111 __END__
112 )
113
114 # Test that they exist are in state Needs-Build
115 wanna-build -A amd64 -b amd64/build-db --info src-a | assert_grep ' State.*: Needs-Build'
116
117 echo Take for building
118 wanna-build -A amd64 -b amd64/build-db --take src-a_1
119 wanna-build -A amd64 -b amd64/build-db --info src-a | assert_grep ' State.*: Building'
120
121 echo Upload binaries
122 wanna-build -A amd64 -b amd64/build-db --uploaded src-a_1
123 wanna-build -A amd64 -b amd64/build-db --info src-a | assert_grep ' State.*: Uploaded'
124
125 echo Load the binaries for the sources
126 wanna-build -A amd64 -b amd64/build-db --merge-all <(cat <<__END__ 
127 Package: bin-a-indep
128 Version: 1
129 Architecture: all
130 Source: src-a
131
132 Package: bin-a-1
133 Version: 1
134 Architecture: amd64
135 Source: src-a
136 __END__
137 ) <( cat <<__END__ 
138 __END__
139 )  <( cat <<__END__
140 Package: src-a
141 Version: 1
142 Architecture: any
143 Section: misc
144 Priority: standard
145 Build-Depends: compiler
146 Binary: bin-a-indep,bin-a-1
147 __END__
148 )
149
150 # Test that they exist are in state Needs-Build
151 wanna-build -A amd64 -b amd64/build-db --info src-a | assert_grep ' State .*: Installed'
152
153 echo Upload another source that needs bin-a-1 in Version 2
154 wanna-build -A amd64 -b amd64/build-db --merge-all <(cat <<__END__ 
155 Package: bin-a-indep
156 Version: 1
157 Architecture: all
158 Source: src-a
159
160 Package: bin-a-1
161 Version: 1
162 Architecture: amd64
163 Source: src-a
164 __END__
165 ) <( cat <<__END__ 
166 misc/src-b_1.dsc [optional:uncompiled]
167 __END__
168 )  <( cat <<__END__
169 Package: src-a
170 Version: 1
171 Architecture: any
172 Section: misc
173 Priority: standard
174 Build-Depends: compiler
175 Binary: bin-a-indep,bin-a-1
176
177 Package: src-b
178 Version: 1
179 Architecture: any
180 Section: misc
181 Priority: standard
182 Build-Depends: bin-a-1 (>= 2)
183 Binary: bin-b
184 __END__
185 )
186
187 wanna-build -A amd64 -b amd64/build-db --info src-b | assert_grep "bin-a-1 (>= 2)"
188
189 echo Uploading the new source with an updated binary package
190 wanna-build -A amd64 -b amd64/build-db --merge-all <(cat <<__END__ 
191 Package: bin-a-indep
192 Version: 2
193 Architecture: all
194 Source: src-a
195
196 Package: bin-a-1
197 Version: 2
198 Architecture: amd64
199 Source: src-a
200 __END__
201 ) <( cat <<__END__ 
202 misc/src-a_1.dsc [optional:uncompiled]
203 misc/src-b_1.dsc [optional:uncompiled]
204 __END__
205 )  <( cat <<__END__
206 Package: src-a
207 Version: 1
208 Architecture: any
209 Section: misc
210 Priority: standard
211 Build-Depends: compiler
212 Binary: bin-a-indep,bin-a-1,bin-a-2
213
214 Package: src-b
215 Version: 1
216 Architecture: any
217 Section: misc
218 Priority: standard
219 Build-Depends: bin-a-1 (>= 2)
220 Binary: bin-b
221 __END__
222 )
223
224 wanna-build -A amd64 -b amd64/build-db --info src-b | assert_grep "State.*:.*Needs-Build"
225
226 echo "Finished sucessfully"