diff --git a/plugins/teststeps/sleep/sleep.go b/plugins/teststeps/sleep/sleep.go index 9040d061..2a1c51f8 100644 --- a/plugins/teststeps/sleep/sleep.go +++ b/plugins/teststeps/sleep/sleep.go @@ -42,7 +42,7 @@ func Load() (string, test.TestStepFactory, []event.Name) { func getDuration(params test.TestStepParameters) (time.Duration, error) { durP := params.GetOne("duration") if durP.IsEmpty() { - return 0, errors.New("Missing 'duration' field in sleep parameters") + return 0, errors.New("missing 'duration' field in sleep parameters") } dur, err := time.ParseDuration(durP.String()) if err != nil { diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 0a4c7a20..54a8d7aa 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -150,6 +150,22 @@ func (ts *E2ETestSuite) startServer(extraArgs ...string) { } } +func (ts *E2ETestSuite) startTask(taskFile string) types.JobID { + // No jobs to begin with. + var listResp api.ListResponse + _, err := ts.runClient(&listResp, "list") + require.NoError(ts.T(), err) + require.Empty(ts.T(), listResp.Data.JobIDs) + + // Start a job. + var resp api.StartResponse + _, err = ts.runClient(&resp, "start", "-Y", taskFile) + require.NoError(ts.T(), err) + ctx.Infof("%+v", resp) + require.NotEqual(ts.T(), 0, resp.Data.JobID) + return resp.Data.JobID +} + func (ts *E2ETestSuite) stopServer(timeout time.Duration) error { if ts.serverSigs == nil { return nil @@ -218,22 +234,8 @@ func (ts *E2ETestSuite) TestCLIErrors() { } func (ts *E2ETestSuite) TestSimple() { - var jobID types.JobID ts.startServer() - { // No jobs to begin with. - var resp api.ListResponse - _, err := ts.runClient(&resp, "list") - require.NoError(ts.T(), err) - require.Empty(ts.T(), resp.Data.JobIDs) - } - { // Start a job. - var resp api.StartResponse - _, err := ts.runClient(&resp, "start", "-Y", "test-simple.yaml") - require.NoError(ts.T(), err) - ctx.Infof("%+v", resp) - require.NotEqual(ts.T(), 0, resp.Data.JobID) - jobID = resp.Data.JobID - } + jobID := ts.startTask("test-simple.yaml") { // Wait for the job to finish var resp api.StatusResponse for i := 1; i < 5; i++ { @@ -279,6 +281,42 @@ func (ts *E2ETestSuite) TestSimple() { require.NoError(ts.T(), ts.stopServer(5*time.Second)) } +func (ts *E2ETestSuite) TestVariables() { + ts.startServer() + jobID := ts.startTask("test-variables.yaml") + + { // Wait for the job to finish + var resp api.StatusResponse + for i := 1; i < 5; i++ { + time.Sleep(1 * time.Second) + stdout, err := ts.runClient(&resp, "status", fmt.Sprintf("%d", jobID)) + require.NoError(ts.T(), err) + require.Nil(ts.T(), resp.Err, "error: %s", resp.Err) + ctx.Infof("Job %d state %s", jobID, resp.Data.Status.State) + if resp.Data.Status.State == string(job.EventJobCompleted) { + ctx.Debugf("Job %d status: %s", jobID, stdout) + break + } + } + require.Equal(ts.T(), string(job.EventJobCompleted), resp.Data.Status.State) + } + { // Verify step output. + es := testsCommon.GetJobEventsAsString(ctx, ts.st, jobID, []event.Name{ + cmd.EventCmdStdout, target.EventTargetAcquired, target.EventTargetReleased, + }) + ctx.Debugf("%s", es) + require.Equal(ts.T(), + fmt.Sprintf(` +{[%d 1 Test 1 0 ][Target{ID: "T1"} TargetAcquired]} +{[%d 1 Test 1 0 cmdstep][Target{ID: "T1"} CmdStdout &"{\"Msg\":\"Hello\\n\"}"]} +{[%d 1 Test 1 0 ][Target{ID: "T1"} TargetReleased]} +`, jobID, jobID, jobID), + es, + ) + } + require.NoError(ts.T(), ts.stopServer(5*time.Second)) +} + func (ts *E2ETestSuite) TestPauseResume() { var jobID types.JobID ts.startServer("--pauseTimeout=60s", "--resumeJobs") diff --git a/tests/e2e/test-variables.yaml b/tests/e2e/test-variables.yaml new file mode 100644 index 00000000..5da21656 --- /dev/null +++ b/tests/e2e/test-variables.yaml @@ -0,0 +1,36 @@ +JobName: A variables test job +Runs: 1 +RunInterval: 1s +Tags: + - test + - variables +TestDescriptors: + - TargetManagerName: TargetList + TargetManagerAcquireParameters: + Targets: + - ID: T1 + TargetManagerReleaseParameters: + TestFetcherName: literal + TestFetcherFetchParameters: + TestName: Test 1 + Steps: + - name: variables + label: variablesstep + parameters: + message: ["Hello"] + - name: cmd + label: cmdstep + parameters: + executable: [echo] + args: ["{{ StringVar \"output_var\" }}"] + emit_stdout: [true] + emit_stderr: [true] + variablesmapping: + output_var: variablesstep.message +Reporting: + RunReporters: + - name: TargetSuccess + parameters: + SuccessExpression: "=100%" + FinalReporters: + - name: noop