fixed inputs when input target is overriden
Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
@@ -40,7 +40,15 @@ type inputKV struct {
|
||||
Value Input `json:"value,omitempty"`
|
||||
}
|
||||
|
||||
func (s *DeploymentState) AddInput(key string, value Input) error {
|
||||
func (s *DeploymentState) SetInput(key string, value Input) error {
|
||||
for i, inp := range s.Inputs {
|
||||
if inp.Key != key {
|
||||
continue
|
||||
}
|
||||
// Remove existing inputs with the same key
|
||||
s.Inputs = append(s.Inputs[:i], s.Inputs[i+1:]...)
|
||||
}
|
||||
|
||||
s.Inputs = append(s.Inputs, inputKV{Key: key, Value: value})
|
||||
return nil
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ func TestInputDir(t *testing.T) {
|
||||
st := &DeploymentState{
|
||||
PlanSource: DirInput("/tmp/source", []string{}),
|
||||
}
|
||||
require.NoError(t, st.AddInput("www.source", DirInput(".", []string{})))
|
||||
require.NoError(t, st.SetInput("www.source", DirInput(".", []string{})))
|
||||
|
||||
deployment, err := NewDeployment(st)
|
||||
require.NoError(t, err)
|
||||
|
@@ -62,7 +62,7 @@ func TestStoreLookupByPath(t *testing.T) {
|
||||
st := &DeploymentState{
|
||||
Name: "test",
|
||||
}
|
||||
require.NoError(t, st.AddInput("foo", DirInput("/test/path", []string{})))
|
||||
require.NoError(t, st.SetInput("foo", DirInput("/test/path", []string{})))
|
||||
require.NoError(t, store.CreateDeployment(ctx, st))
|
||||
|
||||
// Lookup by path
|
||||
@@ -72,7 +72,7 @@ func TestStoreLookupByPath(t *testing.T) {
|
||||
require.Equal(t, st.ID, r.ID)
|
||||
|
||||
// Add a new path
|
||||
require.NoError(t, st.AddInput("bar", DirInput("/test/anotherpath", []string{})))
|
||||
require.NoError(t, st.SetInput("bar", DirInput("/test/anotherpath", []string{})))
|
||||
require.NoError(t, store.UpdateDeployment(ctx, st, nil))
|
||||
|
||||
// Lookup by the previous path
|
||||
|
Reference in New Issue
Block a user