forked from lix-project/hydra
025be052b7
By moving the tests subdirectory to t, we gain the ability to run `yath test` with no arguments from inside `nix develop` in the root of the the repo. (`nix develop` is necessary in order to set the proper env vars for `yath` to find our test libraries.)
56 lines
1.2 KiB
Perl
56 lines
1.2 KiB
Perl
use LWP::UserAgent;
|
|
use JSON;
|
|
|
|
my $ua = LWP::UserAgent->new;
|
|
$ua->cookie_jar({});
|
|
|
|
sub request_json {
|
|
my ($opts) = @_;
|
|
my $req = HTTP::Request->new;
|
|
$req->method($opts->{method} or "GET");
|
|
$req->uri("http://localhost:3000$opts->{uri}");
|
|
$req->header(Accept => "application/json");
|
|
$req->header(Referer => "http://localhost:3000/") if $opts->{method} eq "POST";
|
|
$req->content(encode_json($opts->{data})) if defined $opts->{data};
|
|
my $res = $ua->request($req);
|
|
print $res->as_string();
|
|
return $res;
|
|
}
|
|
|
|
my $result = request_json({
|
|
uri => "/login",
|
|
method => "POST",
|
|
data => {
|
|
username => "root",
|
|
password => "foobar"
|
|
}
|
|
});
|
|
|
|
$result = request_json({
|
|
uri => '/project/sample',
|
|
method => 'PUT',
|
|
data => {
|
|
displayname => "Sample",
|
|
enabled => "1",
|
|
visible => "1",
|
|
}
|
|
});
|
|
|
|
$result = request_json({
|
|
uri => '/jobset/sample/default',
|
|
method => 'PUT',
|
|
data => {
|
|
nixexprpath => "default.nix",
|
|
nixexprinput => "my-src",
|
|
inputs => {
|
|
"my-src" => {
|
|
type => "path",
|
|
value => "/run/jobset"
|
|
}
|
|
},
|
|
enabled => "1",
|
|
visible => "1",
|
|
checkinterval => "5",
|
|
keepnr => 1
|
|
}
|
|
});
|