Skip to content

Commit d630893

Browse files
committed
unit test, adhoc command for adhoc executions
1 parent 282b272 commit d630893

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

core/src/main/java/com/dtolabs/rundeck/core/execution/ExecutionReference.java

+2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ public interface ExecutionReference {
1111
String getOptions();
1212
JobReference getJob();
1313
Date getDateStarted();
14+
Date getDateCompleted();
1415
String getStatus();
1516
String getSucceededNodeList();
1617
String getFailedNodeList();
1718
String getTargetNodes();
19+
String getAdhocCommand();
1820

1921

2022
}

rundeckapp/grails-app/services/rundeck/services/JobStateService.groovy

+8-4
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ class JobStateService implements AuthorizingJobService {
235235
project: se.project)
236236
}
237237
new ExecutionReferenceImpl(id:exec.id, options: exec.argString, filter: exec.filter, job: jobRef,
238-
dateStarted: exec.dateStarted, status: exec.status, succeededNodeList: exec.succeededNodeList,
239-
failedNodeList: exec.failedNodeList)
238+
dateStarted: exec.dateStarted, status: exec.status, succeededNodeList: exec.succeededNodeList,
239+
dateCompleted:exec.dateCompleted, failedNodeList: exec.failedNodeList)
240240

241241
}
242242

@@ -359,9 +359,13 @@ class JobStateService implements AuthorizingJobService {
359359
jobRef = new JobReferenceImpl(id: se.extid, jobName: se.jobName, groupPath: se.groupPath,
360360
project: se.project)
361361
}
362-
ExecutionReferenceImpl execRef = new ExecutionReferenceImpl(id:exec.id, options: exec.argString, filter: exec.filter, job: jobRef,
363-
dateStarted: exec.dateStarted, status: exec.status, succeededNodeList: exec.succeededNodeList,
362+
ExecutionReferenceImpl execRef = new ExecutionReferenceImpl(id:exec.id, options: exec.argString,
363+
filter: exec.filter, job: jobRef, dateStarted: exec.dateStarted, dateCompleted:exec.dateCompleted,
364+
status: exec.status, succeededNodeList: exec.succeededNodeList,
364365
failedNodeList: exec.failedNodeList)
366+
if(!se && exec.workflow && exec.workflow.commands && exec.workflow.commands[0]){
367+
execRef.adhocCommand = exec.workflow.commands[0].summarize()
368+
}
365369
idList.push(execRef)
366370
}
367371
return [result:idList, total:idList.size()]

rundeckapp/grails-app/services/rundeck/services/execution/ExecutionReferenceImpl.groovy

+2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ class ExecutionReferenceImpl implements ExecutionReference {
1010
String id
1111
JobReferenceImpl job
1212
Date dateStarted
13+
Date dateCompleted
1314
String status
1415
String succeededNodeList
1516
String failedNodeList
1617
String targetNodes
18+
String adhocCommand
1719

1820
@Override
1921
String toString() {

rundeckapp/test/unit/rundeck/services/JobStateServiceSpec.groovy

+32-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package rundeck.services
1818

19+
import com.dtolabs.rundeck.app.support.ExecutionQuery
20+
import com.dtolabs.rundeck.core.authorization.AuthContext
1921
import com.dtolabs.rundeck.core.authorization.SubjectAuthContext
2022
import com.dtolabs.rundeck.core.dispatcher.ExecutionState
2123
import com.dtolabs.rundeck.core.execution.ExecutionNotFound
@@ -495,7 +497,36 @@ class JobStateServiceSpec extends Specification {
495497
}
496498

497499

498-
500+
def "queryExecutions simple params"() {
501+
setup:
502+
def auth = Mock(AuthContext)
503+
service.frameworkService = Mock(FrameworkService)
504+
def mockExec = Mock(Execution)
505+
when:
506+
def result = service.queryExecutions(auth, filter)
507+
then:
508+
result
509+
result.total == expTotal
510+
1 * service.frameworkService.queryExecutions(_, 0, 0) >> {ExecutionQuery query,offset,max ->
511+
if(query.adhoc){
512+
return [result: [mockExec], total: 1]
513+
}
514+
if(query.jobIdListFilter){
515+
return [result: [mockExec,mockExec], total: 2]
516+
}
517+
[result: [], total: 0]
518+
}
519+
1 * service.frameworkService.filterAuthorizedProjectExecutionsAll(_, _, [AuthConstants.ACTION_READ]) >>
520+
{authcontext, inputArr, actions ->
521+
return inputArr
522+
}
523+
where:
524+
filter | expTotal
525+
[:] | 0
526+
[adhoc:true] | 1
527+
[jobonly:true] | 0
528+
[jobIdListFilter:'1,2'] | 2
529+
}
499530

500531

501532
def setTestExecutions(projectName, jobUuid){

0 commit comments

Comments
 (0)