5 use warnings FATAL => 'all';
7 use File::ShareDir 'dist_dir';
11 use File::Slurp qw(write_file);
12 use Class::Accessor 'antlers';
14 our $VERSION = '0.01';
18 Freeside testing suite
26 Returns the path to the shared data directory, which contains the reference
27 database image, the test plan, and probably other stuff.
37 Creates a test session. OPTIONS must contain 'dir', a directory to save the
38 output files into (this may eventually default to a temp directory). It can
41 - fsurl: the root Freeside url [http://localhost/freeside]
42 - user: the Freeside test username [test]
43 - pass: the Freeside test password [test]
47 has dir => ( is => 'rw' );
48 has fsurl => ( is => 'rw' );
49 has user => ( is => 'rw' );
50 has pass => ( is => 'rw' );
51 has mech => ( is => 'rw' );
56 fsurl => 'http://localhost/freeside',
63 # strip trailing slash, if any; it causes problems
64 $self->{fsurl} =~ s(/$)();
66 die "FS::Test->new: 'dir' required" unless $self->dir;
67 if ( ! -d $self->dir ) {
69 or die "can't create '".$self->dir."': $!";
71 if ( ! -w $self->dir ) {
72 die "FS::Test->new: can't write to '". $self->dir . "'";
75 $self->mech( WWW::Mechanize->new( autocheck => 0 ) );
78 $self->mech->credentials( $self->user, $self->pass );
91 Takes one or more PATHS (Freeside URIs, relative to $self->fsurl, including
92 query parameters) and downloads them from the web server, into the output
93 directory. Currently this will write progress messages to standard output.
94 If you don't like that, it's open source, fix it.
101 local $CWD = $self->dir;
103 my $base_uri = URI->new($self->fsurl);
104 my $basedirs = () = $base_uri->path_segments;
106 foreach my $path (@_) {
111 if ($path =~ /^#(.*)/) {
116 my $uri = URI->new( $self->fsurl . '/' . $path);
118 my $response = $self->mech->get($uri);
119 print " - " . $response->code . "\n";
120 next unless $response->is_success;
123 my @dirs = $uri->path_segments;
124 splice @dirs, 0, $basedirs;
126 if ( length($uri->query) ) {
127 # if there's a query string, use the (server-side) file name as the
128 # last directory, and the query string as the local file name; this
129 # allows multiple tests that differ only in the query string.
130 push @dirs, $uri->query;
132 my $file = pop @dirs;
133 # make the filename safe for inclusion in a makefile/shell script.
134 # & and ; are both bad; using ":" is reversible and unambiguous (because
135 # it can't appear in query params)
137 foreach my $dir (@dirs) {
138 mkdir $dir unless -d $dir;
141 write_file($file, {binmode => ':utf8'}, $response->decoded_content);