Skip to content

Commit 7e49c3e

Browse files
committed
assert previous build state when updating workspace
1 parent dc528ac commit 7e49c3e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cli/update_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ func TestUpdate(t *testing.T) {
7979
require.NoError(t, err, "member failed to get workspace they themselves own after update")
8080
require.Equal(t, version2.ID.String(), ws.LatestBuild.TemplateVersionID.String(), "workspace must have latest template version after update")
8181
require.False(t, ws.Outdated, "workspace must not be outdated after update")
82+
83+
// Then: the workspace must have been started with the new template version
84+
require.Equal(t, int32(3), ws.LatestBuild.BuildNumber, "workspace must have 3 builds after update")
85+
require.Equal(t, codersdk.WorkspaceTransitionStart, ws.LatestBuild.Transition, "latest build must be a start transition")
86+
87+
// Then: the previous workspace build must be a stop transition with the old
88+
// template version.
89+
// This is important to ensure that the workspace resources are recreated
90+
// correctly. Simply running a start transition with the new template
91+
// version may not recreate resources that were changed in the new
92+
// template version. This can happen, for example, if a user specifies
93+
// ignore_changes in the template.
94+
prevBuild, err := member.WorkspaceBuildByUsernameAndWorkspaceNameAndBuildNumber(ctx, codersdk.Me, ws.Name, "2")
95+
require.NoError(t, err, "failed to get previous workspace build")
96+
require.Equal(t, codersdk.WorkspaceTransitionStop, prevBuild.Transition, "previous build must be a stop transition")
97+
require.Equal(t, version1.ID.String(), prevBuild.TemplateVersionID.String(), "previous build must have the old template version")
8298
})
8399
}
84100

0 commit comments

Comments
 (0)