File: 01-auto-install.t

package info (click to toggle)
preseed 1.125
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie, trixie-proposed-updates, trixie-updates
  • size: 852 kB
  • sloc: sh: 442; perl: 153; makefile: 5
file content (184 lines) | stat: -rwxr-xr-x 5,227 bytes parent folder | download | duplicates (6)
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/perl -w
use strict;
use Test::More qw(no_plan);

# Generate the test template based on BEGIN/END: testable comments:
my $src = 'auto-install.sh';
my $dst = "$src.test";
my @debconf_keys;

open my $input, '<', $src
  or die "Unable to open $src";
open my $output, '>', $dst
  or die "Unable to open $dst";

my $testable_tokens='';
while (<$input>) {
  if (/^# BEGIN: testable$/) {
    $testable_tokens .= 'BEGIN';
    next;
  }
  if (/^# END: testable$/) {
    $testable_tokens .= 'END';
    next;
  }
  if (/^(\s*)db_get (.+) && (.+)=\"\$RET\"/) {
    my ($space, $debconf, $variable) = ($1, $2, $3);
    if ($testable_tokens eq 'BEGIN') {
      push @debconf_keys, $debconf;
      print $output "$space$variable=##$debconf##\n";
    }
    next;
  }
  if (/^(\s*)db_set (.+) (.+)$/) {
    my ($space, $debconf, $variable) = ($1, $2, $3);
    print $output "${space}echo $debconf=$variable\n"
      if $testable_tokens eq 'BEGIN';
    next;
  }
  # Fall through:
  print $output $_
    if $testable_tokens eq 'BEGIN';
}

close $output
  or die "Unable to close $dst";
close $input
  or die "Unable to close $src";

is($testable_tokens, 'BEGINEND', "BEGIN/END: testable found");

# Tiny helper, with a real dirty iterator, and ugly shell calls:
my $iterator=0;
sub run_test {
  my %parameters = @_;
  $iterator++;
  `cp $dst $dst.$iterator`;
  for my $key (@debconf_keys) {
    my $value = $parameters{$key} || '';
    `sed -i -e "s,##$key##,$value," $dst.$iterator`;
  }
  (my $reply = join('', `sh $dst.$iterator`)) =~ s/\n//g;
  return $reply;
}

# Perform the actual tests:
is(run_test('preseed/url'=>'',
           ),
   '',
   'empty URL'
  );

is(run_test('preseed/url'=>'http://foo/preseed.cfg',
           ),
   'preseed/url=http://foo/preseed.cfg',
   'basic foo'
  );

is(run_test('preseed/url'=>'http://foo/preseed.cfg',
            'netcfg/get_domain' => 'example.org',
           ),
   'preseed/url=http://foo.example.org/preseed.cfg',
   'foo and get_domain'
  );

is(run_test('preseed/url'=>'http://foo:1234/preseed.cfg',
            'netcfg/get_domain' => 'example.org',
           ),
   'preseed/url=http://foo.example.org:1234/preseed.cfg',
   'foo:port and get_domain'
  );

is(run_test('preseed/url'=>'http://foo/preseed.cfg',
            'netcfg/get_domain' => 'example.org',
           ),
   'preseed/url=http://foo.example.org/preseed.cfg',
   'foo and get_domain'
  );

is(run_test('preseed/url'=>'http://foo/preseed.cfg',
            'netcfg/get_domain' => 'unnassigned-domain',
           ),
   'preseed/url=http://foo/preseed.cfg',
   'foo and unnassigned-domain (2 "n")'
  );

is(run_test('preseed/url'=>'http://foo/preseed.cfg',
            'netcfg/get_domain' => 'unassigned-domain',
           ),
   'preseed/url=http://foo/preseed.cfg',
   'foo and unassigned-domain (1 "n")'
  );

is(run_test('preseed/url'=>'foo/preseed.cfg',
           ),
   'preseed/url=http://foo/preseed.cfg',
   'http:// is added'
  );

is(run_test('preseed/url'=>'ftp://foo/preseed.cfg',
           ),
   'preseed/url=ftp://foo/preseed.cfg',
   'ftp:// is kept'
  );

is(run_test('preseed/url'=>'ftp://user:pass@10.11.12.13/foo/preseed.cfg',
	    'netcfg/get_domain' => 'example.org',
	   ),
    'preseed/url=ftp://user:pass@10.11.12.13/foo/preseed.cfg',
    'ftp with user/password, IPv4, and domain'
  );

is(run_test('preseed/url'=>'ftp://user:pass@10.11.12.13:8080/foo/preseed.cfg',
	    'netcfg/get_domain' => 'example.org',
	   ),
    'preseed/url=ftp://user:pass@10.11.12.13:8080/foo/preseed.cfg',
    'ftp with user/password, IPv4, and domain and port'
  );

is(run_test('preseed/url'=>'http://[fe80::5054:ff:fe23:8018]/foo/preseed.cfg',
	    'netcfg/get_domain' => 'example.org',
	   ),
    'preseed/url=http://[fe80::5054:ff:fe23:8018]/foo/preseed.cfg',
    'http with short IPv6 and domain'
  );

is(run_test('preseed/url'=>'http://[::1]/foo/preseed.cfg',
	    'netcfg/get_domain' => 'example.org',
	   ),
    'preseed/url=http://[::1]/foo/preseed.cfg',
    'http with simple IPv6 and domain'
  );
is(run_test('preseed/url'=>'http://[fd00:9:152:48:1822:ffff:162:199]/foo/preseed.cfg',
	    'netcfg/get_domain' => 'example.org',
	   ),
    'preseed/url=http://[fd00:9:152:48:1822:ffff:162:199]/foo/preseed.cfg',
    'http with IPv6 and domain'
  );

is(run_test('preseed/url'=>'http://[fd00:9:152:48:1822:ffff:162:199]:8080/foo/preseed.cfg',
	    'netcfg/get_domain' => 'example.org',
	   ),
    'preseed/url=http://[fd00:9:152:48:1822:ffff:162:199]:8080/foo/preseed.cfg',
    'http with IPv6, port, and domain'
  );

is(run_test('preseed/url'=>'http://user:pass@[fd00:9:152:48:1822:ffff:162:199]/foo/preseed.cfg',
	    'netcfg/get_domain' => 'example.org',
	   ),
    'preseed/url=http://user:pass@[fd00:9:152:48:1822:ffff:162:199]/foo/preseed.cfg',
    'http with user/password, IPv6 and domain'
  );

is(run_test('preseed/url'=>'http://user:pass@[fd00:9:152:48:1822:ffff:162:199]:8080/foo/preseed.cfg',
	    'netcfg/get_domain' => 'example.org',
	   ),
    'preseed/url=http://user:pass@[fd00:9:152:48:1822:ffff:162:199]:8080/foo/preseed.cfg',
    'http with user/password, IPv6, port, and domain'
  );

# XXX: Write some tests for auto-install/defaultroot

# Clean-up:
unlink $_
  for (<$dst*>);