fix(pkger): fixup updates for variables where updates from selected were skipped

pull/18651/head
Johnny Steenbergen 2020-06-23 06:34:59 -07:00 committed by Johnny Steenbergen
parent 38d44c7980
commit d671185bdc
4 changed files with 32 additions and 3 deletions

View File

@ -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

View File

@ -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"

View File

@ -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())
}

View File

@ -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{})