@@ -17,47 +17,6 @@ import (
17
17
func TestBump (t * testing.T ) {
18
18
t .Parallel ()
19
19
20
- t .Run ("BumpOKDefault" , func (t * testing.T ) {
21
- t .Parallel ()
22
-
23
- // Given: we have a workspace
24
- var (
25
- err error
26
- ctx = context .Background ()
27
- client = coderdtest .New (t , & coderdtest.Options {IncludeProvisionerD : true })
28
- user = coderdtest .CreateFirstUser (t , client )
29
- version = coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
30
- _ = coderdtest .AwaitTemplateVersionJob (t , client , version .ID )
31
- project = coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
32
- workspace = coderdtest .CreateWorkspace (t , client , user .OrganizationID , project .ID )
33
- cmdArgs = []string {"bump" , workspace .Name }
34
- stdoutBuf = & bytes.Buffer {}
35
- )
36
-
37
- // Given: we wait for the workspace to be built
38
- coderdtest .AwaitWorkspaceBuildJob (t , client , workspace .LatestBuild .ID )
39
- workspace , err = client .Workspace (ctx , workspace .ID )
40
- require .NoError (t , err )
41
- expectedDeadline := workspace .LatestBuild .Deadline .Add (90 * time .Minute )
42
-
43
- // Assert test invariant: workspace build has a deadline set equal to now plus ttl
44
- initDeadline := time .Now ().Add (time .Duration (* workspace .TTLMillis ) * time .Millisecond )
45
- require .WithinDuration (t , initDeadline , workspace .LatestBuild .Deadline , time .Minute )
46
-
47
- cmd , root := clitest .New (t , cmdArgs ... )
48
- clitest .SetupConfig (t , client , root )
49
- cmd .SetOut (stdoutBuf )
50
-
51
- // When: we execute `coder bump <workspace>`
52
- err = cmd .ExecuteContext (ctx )
53
- require .NoError (t , err , "unexpected error" )
54
-
55
- // Then: the deadline of the latest build is updated
56
- updated , err := client .Workspace (ctx , workspace .ID )
57
- require .NoError (t , err )
58
- require .WithinDuration (t , expectedDeadline , updated .LatestBuild .Deadline , time .Minute )
59
- })
60
-
61
20
t .Run ("BumpSpecificDuration" , func (t * testing.T ) {
62
21
t .Parallel ()
63
22
@@ -71,15 +30,15 @@ func TestBump(t *testing.T) {
71
30
_ = coderdtest .AwaitTemplateVersionJob (t , client , version .ID )
72
31
project = coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
73
32
workspace = coderdtest .CreateWorkspace (t , client , user .OrganizationID , project .ID )
74
- cmdArgs = []string {"bump" , workspace .Name , "30 " }
33
+ cmdArgs = []string {"bump" , workspace .Name , "10h " }
75
34
stdoutBuf = & bytes.Buffer {}
76
35
)
77
36
78
37
// Given: we wait for the workspace to be built
79
38
coderdtest .AwaitWorkspaceBuildJob (t , client , workspace .LatestBuild .ID )
80
39
workspace , err = client .Workspace (ctx , workspace .ID )
81
40
require .NoError (t , err )
82
- expectedDeadline := workspace . LatestBuild . Deadline . Add (30 * time .Minute )
41
+ expectedDeadline := time . Now (). Add (10 * time .Hour )
83
42
84
43
// Assert test invariant: workspace build has a deadline set equal to now plus ttl
85
44
initDeadline := time .Now ().Add (time .Duration (* workspace .TTLMillis ) * time .Millisecond )
@@ -150,7 +109,7 @@ func TestBump(t *testing.T) {
150
109
workspace = coderdtest .CreateWorkspace (t , client , user .OrganizationID , project .ID , func (cwr * codersdk.CreateWorkspaceRequest ) {
151
110
cwr .TTLMillis = nil
152
111
})
153
- cmdArgs = []string {"bump" , workspace .Name }
112
+ cmdArgs = []string {"bump" , workspace .Name , "1h" }
154
113
stdoutBuf = & bytes.Buffer {}
155
114
)
156
115
// Unset the workspace TTL
@@ -180,51 +139,11 @@ func TestBump(t *testing.T) {
180
139
181
140
// When: we execute `coder bump workspace``
182
141
err = cmd .ExecuteContext (ctx )
183
- require .NoError (t , err )
142
+ require .Error (t , err )
184
143
185
144
// Then: nothing happens and the deadline remains unset
186
145
updated , err := client .Workspace (ctx , workspace .ID )
187
146
require .NoError (t , err )
188
147
require .Zero (t , updated .LatestBuild .Deadline )
189
148
})
190
-
191
- t .Run ("BumpMinimumDuration" , func (t * testing.T ) {
192
- t .Parallel ()
193
-
194
- // Given: we have a workspace with no deadline set
195
- var (
196
- err error
197
- ctx = context .Background ()
198
- client = coderdtest .New (t , & coderdtest.Options {IncludeProvisionerD : true })
199
- user = coderdtest .CreateFirstUser (t , client )
200
- version = coderdtest .CreateTemplateVersion (t , client , user .OrganizationID , nil )
201
- _ = coderdtest .AwaitTemplateVersionJob (t , client , version .ID )
202
- project = coderdtest .CreateTemplate (t , client , user .OrganizationID , version .ID )
203
- workspace = coderdtest .CreateWorkspace (t , client , user .OrganizationID , project .ID )
204
- cmdArgs = []string {"bump" , workspace .Name , "59s" }
205
- stdoutBuf = & bytes.Buffer {}
206
- )
207
-
208
- // Given: we wait for the workspace to build
209
- coderdtest .AwaitWorkspaceBuildJob (t , client , workspace .LatestBuild .ID )
210
- workspace , err = client .Workspace (ctx , workspace .ID )
211
- require .NoError (t , err )
212
-
213
- // Assert test invariant: workspace build has a deadline set equal to now plus ttl
214
- initDeadline := time .Now ().Add (time .Duration (* workspace .TTLMillis ) * time .Millisecond )
215
- require .WithinDuration (t , initDeadline , workspace .LatestBuild .Deadline , time .Minute )
216
-
217
- cmd , root := clitest .New (t , cmdArgs ... )
218
- clitest .SetupConfig (t , client , root )
219
- cmd .SetOut (stdoutBuf )
220
-
221
- // When: we execute `coder bump workspace 59s`
222
- err = cmd .ExecuteContext (ctx )
223
- require .ErrorContains (t , err , "minimum bump duration is 1 minute" )
224
-
225
- // Then: an error is reported and the deadline remains as before
226
- updated , err := client .Workspace (ctx , workspace .ID )
227
- require .NoError (t , err )
228
- require .WithinDuration (t , workspace .LatestBuild .Deadline , updated .LatestBuild .Deadline , time .Minute )
229
- })
230
149
}
0 commit comments