From d671185bdc376449a019563e2c631329280362a6 Mon Sep 17 00:00:00 2001 From: Johnny Steenbergen Date: Tue, 23 Jun 2020 06:34:59 -0700 Subject: [PATCH] fix(pkger): fixup updates for variables where updates from selected were skipped --- cmd/influx/main.go | 2 +- cmd/influxd/launcher/pkger_test.go | 30 +++++++++++++++++++++++++++++- pkger/service_models.go | 1 + variable.go | 2 +- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/cmd/influx/main.go b/cmd/influx/main.go index 2c4897774d..4565c966ec 100644 --- a/cmd/influx/main.go +++ b/cmd/influx/main.go @@ -579,7 +579,7 @@ func rawDurationToTimeDuration(raw string) (time.Duration, error) { case "ns": dur += mag * time.Nanosecond default: - return 0, errors.New("duration must be day(d), hour(h), min(m), sec(s), millisec(ms), microsec(us), or nanosec(ns)") + return 0, errors.New("duration must be week(w), day(d), hour(h), min(m), sec(s), millisec(ms), microsec(us), or nanosec(ns)") } } return dur, nil diff --git a/cmd/influxd/launcher/pkger_test.go b/cmd/influxd/launcher/pkger_test.go index 4f40d073dc..71fcb6e99c 100644 --- a/cmd/influxd/launcher/pkger_test.go +++ b/cmd/influxd/launcher/pkger_test.go @@ -183,10 +183,11 @@ func TestLauncher_Pkger(t *testing.T) { return obj } - newVariableObject := func(pkgName, name, description string) pkger.Object { + newVariableObject := func(pkgName, name, description string, selected ...string) pkger.Object { obj := pkger.VariableToObject("", influxdb.Variable{ Name: name, Description: description, + Selected: selected, Arguments: &influxdb.VariableArguments{ Type: "constant", Values: influxdb.VariableConstantValues{"a", "b"}, @@ -1538,6 +1539,33 @@ func TestLauncher_Pkger(t *testing.T) { }) }) + t.Run("applying updates to existing variable should be successful", func(t *testing.T) { + stack, cleanup := newStackFn(t, pkger.Stack{}) + defer cleanup() + + impact, err := svc.Apply(ctx, l.Org.ID, l.User.ID, + pkger.ApplyWithStackID(stack.ID), + pkger.ApplyWithPkg(newPkg(newVariableObject("var", "", ""))), + ) + require.NoError(t, err) + + vars := impact.Summary.Variables + require.Len(t, vars, 1) + v := resourceCheck.mustGetVariable(t, byID(influxdb.ID(vars[0].ID))) + assert.Empty(t, v.Selected) + + impact, err = svc.Apply(ctx, l.Org.ID, l.User.ID, + pkger.ApplyWithStackID(stack.ID), + pkger.ApplyWithPkg(newPkg(newVariableObject("var", "", "", "selected"))), + ) + require.NoError(t, err) + + vars = impact.Summary.Variables + require.Len(t, vars, 1) + v = resourceCheck.mustGetVariable(t, byID(influxdb.ID(vars[0].ID))) + assert.Equal(t, []string{"selected"}, v.Selected) + }) + t.Run("apply with actions", func(t *testing.T) { var ( bucketPkgName = "rucketeer-1" diff --git a/pkger/service_models.go b/pkger/service_models.go index cdafcff3b3..6521893773 100644 --- a/pkger/service_models.go +++ b/pkger/service_models.go @@ -1520,6 +1520,7 @@ func (v *stateVariable) shouldApply() bool { return IsRemoval(v.stateStatus) || v.existing == nil || v.existing.Description != v.parserVar.Description || + !reflect.DeepEqual(v.existing.Selected, v.parserVar.Selected()) || v.existing.Arguments == nil || !reflect.DeepEqual(v.existing.Arguments, v.parserVar.influxVarArgs()) } diff --git a/variable.go b/variable.go index f26c1b5df3..9082a469cc 100644 --- a/variable.go +++ b/variable.go @@ -169,7 +169,7 @@ func (a *VariableArguments) UnmarshalJSON(data []byte) error { return err } - // Decode the polymorphic VariableArguments.Values field into the approriate struct + // Decode the polymorphic VariableArguments.Values field into the appropriate struct switch aux.Type { case "constant": values, ok := aux.Values.([]interface{})