Skip to content

Commit

Permalink
Variables: e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
rihter007 committed Jun 21, 2022
1 parent 71a8073 commit 48979ca
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 16 deletions.
2 changes: 1 addition & 1 deletion plugins/teststeps/sleep/sleep.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
68 changes: 53 additions & 15 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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++ {
Expand Down Expand Up @@ -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")
Expand Down
36 changes: 36 additions & 0 deletions tests/e2e/test-variables.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 48979ca

Please sign in to comment.