Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
internal/server/state: generation on ops cannot be updated
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Apr 8, 2021
1 parent 28d182b commit 729c504
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 1 addition & 2 deletions internal/server/singleprocess/state/app_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,7 @@ func (op *appOperation) dbPut(
}

// Next, ensure that the fields we want to match are matched.
matchFields := []string{"Sequence"}

matchFields := []string{"Generation", "Sequence"}
for _, name := range matchFields {
f := op.valueFieldReflect(value, name)
if !f.IsValid() {
Expand Down
14 changes: 14 additions & 0 deletions internal/server/singleprocess/state/app_operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,20 @@ func TestAppOperation_deploy(t *testing.T) {
require.NotEmpty(b.Generation)
require.Equal("other", d.Generation.Id)
require.Equal(uint64(3), d.Generation.InitialSequence)

// Cannot update the generation sequence
d.Generation.InitialSequence = 42
require.NoError(op.Put(s, true, d))

raw, err = op.Get(s, appOpById("D"))
require.NoError(err)
require.NotNil(raw)
d, ok = raw.(*pb.Deployment)
require.True(ok)
require.Equal(uint64(3), d.Sequence)
require.NotEmpty(b.Generation)
require.Equal("other", d.Generation.Id)
require.Equal(uint64(3), d.Generation.InitialSequence)
})

t.Run("does not change generation if set", func(t *testing.T) {
Expand Down

0 comments on commit 729c504

Please sign in to comment.