fix(pkger): fixup updates for variables where updates from selected were skipped
parent
38d44c7980
commit
d671185bdc
|
@ -579,7 +579,7 @@ func rawDurationToTimeDuration(raw string) (time.Duration, error) {
|
||||||
case "ns":
|
case "ns":
|
||||||
dur += mag * time.Nanosecond
|
dur += mag * time.Nanosecond
|
||||||
default:
|
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
|
return dur, nil
|
||||||
|
|
|
@ -183,10 +183,11 @@ func TestLauncher_Pkger(t *testing.T) {
|
||||||
return obj
|
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{
|
obj := pkger.VariableToObject("", influxdb.Variable{
|
||||||
Name: name,
|
Name: name,
|
||||||
Description: description,
|
Description: description,
|
||||||
|
Selected: selected,
|
||||||
Arguments: &influxdb.VariableArguments{
|
Arguments: &influxdb.VariableArguments{
|
||||||
Type: "constant",
|
Type: "constant",
|
||||||
Values: influxdb.VariableConstantValues{"a", "b"},
|
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) {
|
t.Run("apply with actions", func(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
bucketPkgName = "rucketeer-1"
|
bucketPkgName = "rucketeer-1"
|
||||||
|
|
|
@ -1520,6 +1520,7 @@ func (v *stateVariable) shouldApply() bool {
|
||||||
return IsRemoval(v.stateStatus) ||
|
return IsRemoval(v.stateStatus) ||
|
||||||
v.existing == nil ||
|
v.existing == nil ||
|
||||||
v.existing.Description != v.parserVar.Description ||
|
v.existing.Description != v.parserVar.Description ||
|
||||||
|
!reflect.DeepEqual(v.existing.Selected, v.parserVar.Selected()) ||
|
||||||
v.existing.Arguments == nil ||
|
v.existing.Arguments == nil ||
|
||||||
!reflect.DeepEqual(v.existing.Arguments, v.parserVar.influxVarArgs())
|
!reflect.DeepEqual(v.existing.Arguments, v.parserVar.influxVarArgs())
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,7 +169,7 @@ func (a *VariableArguments) UnmarshalJSON(data []byte) error {
|
||||||
return err
|
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 {
|
switch aux.Type {
|
||||||
case "constant":
|
case "constant":
|
||||||
values, ok := aux.Values.([]interface{})
|
values, ok := aux.Values.([]interface{})
|
||||||
|
|
Loading…
Reference in New Issue