From 73dd8c7d78cc3065dac371f218c820b629b73c5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 20 Oct 2022 12:55:01 +0200 Subject: [PATCH] Cleanup: pass submittedJob as pointer to two-way variable replacer The two-way variable replacement function changes the submitted job. To clarify that this happens, pass the pointer `&submittedJob`. Both pass-by-pointer and pass-by-value work, because the variable replacement typically works on maps/slices, which are passed by reference anyway. Better to be explicit about this, though. No functional changes. --- internal/manager/api_impl/jobs.go | 2 +- internal/manager/api_impl/varrepl.go | 2 +- internal/manager/api_impl/varrepl_test.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/manager/api_impl/jobs.go b/internal/manager/api_impl/jobs.go index 25ebadfe..88061921 100644 --- a/internal/manager/api_impl/jobs.go +++ b/internal/manager/api_impl/jobs.go @@ -89,7 +89,7 @@ func (f *Flamenco) SubmitJob(e echo.Context) error { // Before compiling the job, replace the two-way variables. This ensures all // the tasks also use those. - replaceTwoWayVariables(f.config, submittedJob) + replaceTwoWayVariables(f.config, &submittedJob) authoredJob, err := f.jobCompiler.Compile(ctx, submittedJob) switch { diff --git a/internal/manager/api_impl/varrepl.go b/internal/manager/api_impl/varrepl.go index ed7c680d..562ce81e 100644 --- a/internal/manager/api_impl/varrepl.go +++ b/internal/manager/api_impl/varrepl.go @@ -77,7 +77,7 @@ func replaceTaskVariables(replacer VariableReplacer, task api.AssignedTask, work // `{render}/output.png` // // NOTE: this updates the job in place. -func replaceTwoWayVariables(replacer VariableReplacer, job api.SubmittedJob) { +func replaceTwoWayVariables(replacer VariableReplacer, job *api.SubmittedJob) { feeder := make(chan string, 1) receiver := make(chan string, 1) diff --git a/internal/manager/api_impl/varrepl_test.go b/internal/manager/api_impl/varrepl_test.go index 395dbccf..38a579dc 100644 --- a/internal/manager/api_impl/varrepl_test.go +++ b/internal/manager/api_impl/varrepl_test.go @@ -197,7 +197,7 @@ func TestReplaceTwoWayVariables(t *testing.T) { replaced := varReplSubmittedJob() replaced.Settings = nil replaced.Metadata = nil - replaceTwoWayVariables(&c, replaced) + replaceTwoWayVariables(&c, &replaced) assert.Equal(t, original.Type, replaced.Type, "two-way variable replacement shouldn't happen on the Type property") assert.Equal(t, original.Name, replaced.Name, "two-way variable replacement shouldn't happen on the Name property") @@ -211,7 +211,7 @@ func TestReplaceTwoWayVariables(t *testing.T) { { original := varReplSubmittedJob() replaced := jsonWash(varReplSubmittedJob()) - replaceTwoWayVariables(&c, replaced) + replaceTwoWayVariables(&c, &replaced) expectSettings := map[string]interface{}{ "blender_cmd": "{blender}",