Skip to content

Commit 6f7178a

Browse files
committed
Adds polymorphic LockedBy relationship to Workspace
1 parent 51ab4c6 commit 6f7178a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

workspace.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ type WorkspaceList struct {
114114
Items []*Workspace
115115
}
116116

117+
// LockedByChoice is a choice type struct that represents the possible values
118+
// within a polymorphic relation. If a value is available, exactly one field
119+
// will be non-nil.
120+
type LockedByChoice struct {
121+
Run *Run
122+
User *User
123+
Team *Team
124+
}
125+
117126
// Workspace represents a Terraform Enterprise workspace.
118127
type Workspace struct {
119128
ID string `jsonapi:"primary,workspaces"`
@@ -164,6 +173,7 @@ type Workspace struct {
164173
Project *Project `jsonapi:"relation,project"`
165174
Tags []*Tag `jsonapi:"relation,tags"`
166175
CurrentConfigurationVersion *ConfigurationVersion `jsonapi:"relation,current-configuration-version,omitempty"`
176+
LockedBy *LockedByChoice `jsonapi:"polyrelation,locked-by"`
167177

168178
// Links
169179
Links map[string]interface{} `jsonapi:"links,omitempty"`

workspace_integration_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,9 +1874,15 @@ func TestWorkspacesLock(t *testing.T) {
18741874
t.Cleanup(wTestCleanup)
18751875

18761876
t.Run("with valid options", func(t *testing.T) {
1877+
require.Empty(t, wTest.LockedBy)
1878+
18771879
w, err := client.Workspaces.Lock(ctx, wTest.ID, WorkspaceLockOptions{})
18781880
require.NoError(t, err)
18791881
assert.True(t, w.Locked)
1882+
1883+
require.NoError(t, err)
1884+
require.NotEmpty(t, w.LockedBy)
1885+
requireExactlyOneNotEmpty(t, w.LockedBy.Run, w.LockedBy.Team, w.LockedBy.User)
18801886
})
18811887

18821888
t.Run("when workspace is already locked", func(t *testing.T) {

0 commit comments

Comments
 (0)