Normalize legacy file list job results
This commit is contained in:
@@ -196,6 +196,68 @@ func TestCoreServiceRunJobClaimSkipsServerFileCapabilityWithoutDeclaration(t *te
|
||||
}
|
||||
}
|
||||
|
||||
func TestCoreServiceNormalizesLegacyFileListResultKind(t *testing.T) {
|
||||
svc := newTestCoreService()
|
||||
plugin, endpoint := createPluginAndRunEndpoint(t, svc)
|
||||
instance, err := svc.CreateServerInstance(domain.ServerInstance{
|
||||
ID: "server-file-list-legacy-kind",
|
||||
PluginID: plugin.ID,
|
||||
RunEndpointID: endpoint.ID,
|
||||
Name: "Legacy File List Server",
|
||||
State: domain.ServerInstanceStateRunning,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("create server instance: %v", err)
|
||||
}
|
||||
helloRequest := validRunControlHello()
|
||||
helloRequest.CapabilityReport.Capabilities = append(helloRequest.CapabilityReport.Capabilities, domain.JobCapabilityFilesList)
|
||||
helloRequest.CapabilityReport.Fingerprint = "cap-file-list-legacy-kind"
|
||||
hello, err := svc.RegisterRunHello(helloRequest)
|
||||
if err != nil {
|
||||
t.Fatalf("register run hello: %v", err)
|
||||
}
|
||||
job, err := svc.CreateJob(domain.Job{
|
||||
ID: "job-file-list-legacy-kind",
|
||||
ServerInstanceID: instance.ID,
|
||||
RunEndpointID: endpoint.ID,
|
||||
Capability: domain.JobCapabilityFilesList,
|
||||
TargetKey: "server-root",
|
||||
IdempotencyKey: "idem-file-list-legacy-kind",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("create file list job: %v", err)
|
||||
}
|
||||
claim, err := svc.ClaimRunJob(domain.RunJobClaim{RunEndpointID: endpoint.ID, SessionToken: hello.SessionToken, Capabilities: []string{domain.JobCapabilityFilesList}, Capacity: domain.RunCapacity{MaxJobs: 4}})
|
||||
if err != nil || !claim.HasJob || claim.Job.JobID != job.ID {
|
||||
t.Fatalf("claim file list job: claim=%+v err=%v", claim, err)
|
||||
}
|
||||
completed, err := svc.CompleteRunJob(domain.RunJobResult{
|
||||
RunEndpointID: endpoint.ID,
|
||||
SessionToken: hello.SessionToken,
|
||||
JobID: claim.Job.JobID,
|
||||
LeaseToken: claim.Job.LeaseToken,
|
||||
Attempt: claim.Job.Attempt,
|
||||
State: domain.JobStateSucceeded,
|
||||
Progress: domain.RunJobProgressReport{Percent: 100, Message: "listed"},
|
||||
Message: "listed",
|
||||
ExecutionResult: domain.JobExecutionResult{
|
||||
Kind: "file",
|
||||
Content: runFileListFixture("server-root", "", "SCUM"),
|
||||
Summary: "legacy bounded logical file listing",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("complete legacy file list job: %v", err)
|
||||
}
|
||||
if !completed.Accepted || completed.Job.State != domain.JobStateSucceeded {
|
||||
t.Fatalf("expected legacy file list result to be accepted, got %+v", completed)
|
||||
}
|
||||
stored, err := svc.GetJob(job.ID)
|
||||
if err != nil || stored.ExecutionResult.Kind != "file.list" {
|
||||
t.Fatalf("expected stored legacy file kind to be normalized, job=%+v err=%v", stored, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCoreServiceRunJobRejectsInvalidSessionAndLease(t *testing.T) {
|
||||
svc, sessionToken := newRegisteredRunJobService(t)
|
||||
createQueuedRunJob(t, svc, "job-1", "idem-1")
|
||||
|
||||
Reference in New Issue
Block a user