Manager: construct api.Worker from api.WorkerSummary + extra fields

This commit is contained in:
Sybren A. Stüvel 2022-05-31 15:30:46 +02:00
parent 90707dceed
commit 3063e1fe6d
2 changed files with 19 additions and 13 deletions

View File

@ -68,13 +68,15 @@ func workerSummary(w persistence.Worker) api.WorkerSummary {
func workerDBtoAPI(dbWorker *persistence.Worker) api.Worker { func workerDBtoAPI(dbWorker *persistence.Worker) api.Worker {
apiWorker := api.Worker{ apiWorker := api.Worker{
Id: dbWorker.UUID, WorkerSummary: api.WorkerSummary{
Id: dbWorker.UUID,
Nickname: dbWorker.Name,
Status: dbWorker.Status,
Version: dbWorker.Software,
},
IpAddress: dbWorker.Address, IpAddress: dbWorker.Address,
Nickname: dbWorker.Name,
Platform: dbWorker.Platform, Platform: dbWorker.Platform,
Status: dbWorker.Status,
SupportedTaskTypes: dbWorker.TaskTypes(), SupportedTaskTypes: dbWorker.TaskTypes(),
Version: dbWorker.Software,
} }
if dbWorker.StatusRequested != "" { if dbWorker.StatusRequested != "" {

View File

@ -87,12 +87,14 @@ func TestFetchWorker(t *testing.T) {
err = mf.flamenco.FetchWorker(echo, workerUUID) err = mf.flamenco.FetchWorker(echo, workerUUID)
assert.NoError(t, err) assert.NoError(t, err)
assertResponseJSON(t, echo, http.StatusOK, api.Worker{ assertResponseJSON(t, echo, http.StatusOK, api.Worker{
Id: workerUUID, WorkerSummary: api.WorkerSummary{
Nickname: "дрон", Id: workerUUID,
Nickname: "дрон",
Version: "3.0",
Status: api.WorkerStatusAwake,
},
IpAddress: "fe80::5054:ff:fede:2ad7", IpAddress: "fe80::5054:ff:fede:2ad7",
Platform: "linux", Platform: "linux",
Version: "3.0",
Status: api.WorkerStatusAwake,
SupportedTaskTypes: []string{"blender", "ffmpeg", "file-management", "misc"}, SupportedTaskTypes: []string{"blender", "ffmpeg", "file-management", "misc"},
}) })
@ -105,13 +107,15 @@ func TestFetchWorker(t *testing.T) {
err = mf.flamenco.FetchWorker(echo, worker.UUID) err = mf.flamenco.FetchWorker(echo, worker.UUID)
assert.NoError(t, err) assert.NoError(t, err)
assertResponseJSON(t, echo, http.StatusOK, api.Worker{ assertResponseJSON(t, echo, http.StatusOK, api.Worker{
Id: workerUUID, WorkerSummary: api.WorkerSummary{
Nickname: "дрон", Id: workerUUID,
Nickname: "дрон",
Version: "3.0",
Status: api.WorkerStatusAwake,
StatusRequested: &requestedStatus,
},
IpAddress: "fe80::5054:ff:fede:2ad7", IpAddress: "fe80::5054:ff:fede:2ad7",
Platform: "linux", Platform: "linux",
Version: "3.0",
Status: api.WorkerStatusAwake,
StatusRequested: &requestedStatus,
SupportedTaskTypes: []string{"blender", "ffmpeg", "file-management", "misc"}, SupportedTaskTypes: []string{"blender", "ffmpeg", "file-management", "misc"},
}) })
} }