-
Notifications
You must be signed in to change notification settings - Fork 0
/
50config-tag.t
111 lines (94 loc) · 2.51 KB
/
50config-tag.t
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
use strict;
use warnings;
use File::Temp qw(tempfile);
use Test::More;
use t::Util;
plan skip_all => 'curl not found'
unless prog_exists('curl');
my $curl = "curl --silent --show-error --dump-header /dev/stderr";
subtest 'basic' => sub {
my $included = temp_config_file(<< "EOT");
header.add: &marked "foo: FOO"
file.dir: @{[DOC_ROOT]}
EOT
my $server = spawn_h2o(<< "EOT");
hosts:
default:
paths:
/: !file $included
EOT
my ($stderr, $stdout) = run_prog("$curl http://127.0.0.1:@{[$server->{port}]}/");
like $stderr, qr{^HTTP/[^ ]+ 200\s}s;
like $stderr, qr{^foo: ?FOO\r$}im;
};
subtest 'multi-hop' => sub {
my $included2 = temp_config_file(<< "EOT");
header.add: &marked "foo: FOO"
file.dir: @{[DOC_ROOT]}
EOT
my $included1 = temp_config_file(<< "EOT");
!file $included2
EOT
my $server = spawn_h2o(<< "EOT");
hosts:
default:
paths:
/: !file $included1
EOT
my ($stderr, $stdout) = run_prog("$curl http://127.0.0.1:@{[$server->{port}]}/");
like $stderr, qr{^HTTP/[^ ]+ 200\s}s;
like $stderr, qr{^foo: ?FOO\r$}im;
};
subtest 'with-alias' => sub {
my $included = temp_config_file(<< "EOT");
header.add: &marked "foo: FOO"
file.dir: @{[DOC_ROOT]}
EOT
my $server = spawn_h2o(<< "EOT");
hosts:
default:
paths:
/: !file $included
/another:
header.add: *marked
file.dir: @{[DOC_ROOT]}
EOT
subtest 'with_merge' => sub {
my ($stderr, $stdout) = run_prog("$curl http://127.0.0.1:@{[$server->{port}]}/");
like $stderr, qr{^HTTP/[^ ]+ 200\s}s;
like $stderr, qr{^foo: ?FOO\r$}im;
};
subtest 'with_alias' => sub {
my ($stderr, $stdout) = run_prog("$curl http://127.0.0.1:@{[$server->{port}]}/another/");
like $stderr, qr{^HTTP/[^ ]+ 200\s}s;
like $stderr, qr{^foo: ?FOO\r$}im;
};
};
subtest 'with-merge' => sub {
my $included2 = temp_config_file(<< "EOT");
header.add: "foo: FOO"
EOT
my $included1 = temp_config_file(<< "EOT");
<<: !file $included2
header.append: "bar: BAR"
EOT
my $server = spawn_h2o(<< "EOT");
hosts:
default:
paths:
/:
<<: !file $included1
file.dir: @{[ DOC_ROOT ]}
EOT
my ($stderr, $stdout) = run_prog("$curl http://127.0.0.1:@{[$server->{port}]}/");
like $stderr, qr{^HTTP/[^ ]+ 200\s}s;
like $stderr, qr{^foo: ?FOO\r$}im;
like $stderr, qr{^bar: ?BAR\r$}im;
};
done_testing();
sub temp_config_file {
my ($content) = @_;
my ($fh, $fn) = tempfile(UNLINK => 1);
print $fh $content;
return $fn;
}