From 8e6052fdcc494786a9e593ebcc0bdb0257214358 Mon Sep 17 00:00:00 2001 From: Filip Marek Date: Fri, 19 Jan 2024 14:05:54 +0100 Subject: [PATCH] Public set methods for data bag It's very hard or almost impossible to create some tests if we can't define some data in the data bag, so I'm making it public. --- data_bag.go | 10 ++++++---- data_bag_inner_test.go | 4 ++-- worker.go | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/data_bag.go b/data_bag.go index 8c16d0c..92a7a45 100644 --- a/data_bag.go +++ b/data_bag.go @@ -26,13 +26,13 @@ type DataBag struct { bag sync.Map } -// GetJobData allows to fetch the job data from bag using step name. +// GetJobData allows to fetch the job data from data bag using step name. // If ok is false, it means that no data was stored. func (d *DataBag) GetJobData(name string) (interface{}, bool) { return d.getData(name + jobDataPostfix) } -// GetPreCheckData allows to fetch the job data from bag using step name. +// GetPreCheckData allows to fetch the pre-check data from data bag using step name. // If ok is false, it means that no data was stored. func (d *DataBag) GetPreCheckData(name string) (interface{}, bool) { return d.getData(name + preCheckDataPostfix) @@ -50,11 +50,13 @@ func (d *DataBag) setData(name string, data interface{}) { d.bag.Store(d.getKeyName(name), data) } -func (d *DataBag) setJobData(name string, data interface{}) { +// SetJobData allows to set the job data from data bag using step name. +func (d *DataBag) SetJobData(name string, data interface{}) { d.setData(name+jobDataPostfix, data) } -func (d *DataBag) setPreCheckData(name string, data interface{}) { +// SetPreCheckData allows to set the pre-check data to data bag using step name. +func (d *DataBag) SetPreCheckData(name string, data interface{}) { d.setData(name+preCheckDataPostfix, data) } diff --git a/data_bag_inner_test.go b/data_bag_inner_test.go index f33ab97..ce06426 100644 --- a/data_bag_inner_test.go +++ b/data_bag_inner_test.go @@ -35,7 +35,7 @@ func TestDataBag_GetJobData(t *testing.T) { t.Run(tt.name, func(t *testing.T) { d := new(DataBag) - d.setJobData(tt.args.keyName, tt.args.storeVal) + d.SetJobData(tt.args.keyName, tt.args.storeVal) got, exists := d.GetJobData(tt.getKeyName) @@ -52,7 +52,7 @@ func TestDataBag_GetPreCheckData(t *testing.T) { t.Run(tt.name, func(t *testing.T) { d := new(DataBag) - d.setPreCheckData(tt.args.keyName, tt.args.storeVal) + d.SetPreCheckData(tt.args.keyName, tt.args.storeVal) got, exists := d.GetPreCheckData(tt.getKeyName) diff --git a/worker.go b/worker.go index 81378d7..8ba99f0 100644 --- a/worker.go +++ b/worker.go @@ -76,7 +76,7 @@ func (w *worker) executeStep(ctx context.Context, stepIdx int, input interface{} if output, ok := isReturnOutput(preCheckResp); ok { if db, ok := ctx.Value(DataBagContextKey).(*DataBag); ok { - db.setPreCheckData(w.steps.StepName(stepIdx), output) + db.SetPreCheckData(w.steps.StepName(stepIdx), output) } } @@ -110,7 +110,7 @@ func (w *worker) executeStep(ctx context.Context, stepIdx int, input interface{} if output, ok := isReturnOutput(jobResp); ok { if db, ok := ctx.Value(DataBagContextKey).(*DataBag); ok { - db.setJobData(w.steps.StepName(stepIdx), output) + db.SetJobData(w.steps.StepName(stepIdx), output) } }