From 1a313ad566042ac49584e7054a1bf35b26bc4013 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Mon, 23 Sep 2013 17:53:35 -0400 Subject: [PATCH] Allow dashes in jobset input names Signed-off-by: Shea Levy --- src/lib/Hydra/Controller/Jobset.pm | 4 ++-- src/lib/Hydra/Controller/Root.pm | 2 +- tests/api-test.pl | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/Hydra/Controller/Jobset.pm b/src/lib/Hydra/Controller/Jobset.pm index 3dcb1f78..7ef7c680 100644 --- a/src/lib/Hydra/Controller/Jobset.pm +++ b/src/lib/Hydra/Controller/Jobset.pm @@ -248,7 +248,7 @@ sub nixExprPathFromParams { error($c, "Invalid Nix expression path: $nixExprPath") if $nixExprPath !~ /^$relPathRE$/; my $nixExprInput = trim $c->stash->{params}->{"nixexprinput"}; - error($c, "Invalid Nix expression input name: $nixExprInput") unless $nixExprInput =~ /^\w+$/; + error($c, "Invalid Nix expression input name: $nixExprInput") unless $nixExprInput =~ /^[[:alpha:]][\w-]*$/; return ($nixExprPath, $nixExprInput); } @@ -309,7 +309,7 @@ sub updateJobset { foreach my $inputName (keys %{$c->stash->{params}->{inputs}}) { my $inputData = $c->stash->{params}->{inputs}->{$inputName}; - error($c, "Invalid input name: $inputName") unless $inputName =~ /^[[:alpha:]]\w*$/; + error($c, "Invalid input name: $inputName") unless $inputName =~ /^[[:alpha:]][\w-]*$/; my $inputType = $inputData->{type}; diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index 8b7cf4ee..64bdc8cf 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -223,7 +223,7 @@ sub end : ActionClass('RenderView') { } if (scalar @{$c->error}) { - $c->stash->{resource} = { errors => "$c->error" }; + $c->stash->{resource} = { errors => $c->error }; $c->stash->{template} = 'error.tt'; $c->stash->{errors} = $c->error; $c->response->status(500) if $c->response->status == 200; diff --git a/tests/api-test.pl b/tests/api-test.pl index ad91d1a8..d1ea4588 100644 --- a/tests/api-test.pl +++ b/tests/api-test.pl @@ -37,13 +37,13 @@ my $project = decode_json(request_json({ uri => '/project/sample' })->content()) ok((not @{$project->{jobsets}}), "A new project has no jobsets"); -$result = request_json({ uri => '/jobset/sample/default', method => 'PUT', data => { nixexprpath => "default.nix", nixexprinput => "src", inputs => { src => { type => "path", values => "/run/jobset" } }, enabled => "1", checkinterval => "3600"} }); +$result = request_json({ uri => '/jobset/sample/default', method => 'PUT', data => { nixexprpath => "default.nix", nixexprinput => "my-src", inputs => { "my-src" => { type => "path", values => "/run/jobset" } }, enabled => "1", checkinterval => "3600"} }); ok($result->code() == 201, "PUTting a new jobset creates it"); my $jobset = decode_json(request_json({ uri => '/jobset/sample/default' })->content()); -ok($jobset->{jobsetinputs}->[0]->{name} eq "src", "The new jobset has an 'src' input"); -ok($jobset->{jobsetinputs}->[0]->{jobsetinputalts}->[0]->{value} eq "/run/jobset", "The 'src' input is in /run/jobset"); +ok($jobset->{jobsetinputs}->[0]->{name} eq "my-src", "The new jobset has a 'my-src' input"); +ok($jobset->{jobsetinputs}->[0]->{jobsetinputalts}->[0]->{value} eq "/run/jobset", "The 'my-src' input is in /run/jobset"); system("LOGNAME=root NIX_STORE_DIR=/run/nix/store NIX_LOG_DIR=/run/nix/var/log/nix NIX_STATE_DIR=/run/nix/var/nix HYDRA_DATA=/var/lib/hydra HYDRA_DBI='dbi:Pg:dbname=hydra;user=root;' hydra-evaluator sample default"); $result = request_json({ uri => '/jobset/sample/default/evals' });