@@ -23,6 +23,7 @@ import (
23
23
24
24
"github.com/coder/envbox/cli"
25
25
"github.com/coder/envbox/cli/clitest"
26
+ "github.com/coder/envbox/dockerutil"
26
27
"github.com/coder/envbox/xunix"
27
28
"github.com/coder/envbox/xunix/xunixfake"
28
29
)
@@ -164,7 +165,7 @@ func TestDocker(t *testing.T) {
164
165
client := clitest .DockerClient (t , ctx )
165
166
var called bool
166
167
client .ContainerCreateFn = func (_ context.Context , config * container.Config , hostConfig * container.HostConfig , networkingConfig * network.NetworkingConfig , _ * v1.Platform , containerName string ) (container.ContainerCreateCreatedBody , error ) {
167
- if containerName == "workspace_cvm" {
168
+ if containerName == cli . InnerContainerName {
168
169
called = true
169
170
require .Equal (t , expectedEnvs , config .Env )
170
171
}
@@ -217,7 +218,7 @@ func TestDocker(t *testing.T) {
217
218
218
219
var called bool
219
220
client .ContainerCreateFn = func (_ context.Context , config * container.Config , hostConfig * container.HostConfig , networkingConfig * network.NetworkingConfig , _ * v1.Platform , containerName string ) (container.ContainerCreateCreatedBody , error ) {
220
- if containerName == "workspace_cvm" {
221
+ if containerName == cli . InnerContainerName {
221
222
called = true
222
223
require .Equal (t , expectedMounts , hostConfig .Binds )
223
224
}
@@ -301,7 +302,7 @@ func TestDocker(t *testing.T) {
301
302
302
303
var called bool
303
304
client .ContainerCreateFn = func (_ context.Context , config * container.Config , hostConfig * container.HostConfig , networkingConfig * network.NetworkingConfig , _ * v1.Platform , containerName string ) (container.ContainerCreateCreatedBody , error ) {
304
- if containerName == "workspace_cvm" {
305
+ if containerName == cli . InnerContainerName {
305
306
called = true
306
307
require .Equal (t , expectedDevices , hostConfig .Devices )
307
308
}
@@ -368,7 +369,7 @@ func TestDocker(t *testing.T) {
368
369
369
370
var called bool
370
371
client .ContainerCreateFn = func (_ context.Context , config * container.Config , hostConfig * container.HostConfig , networkingConfig * network.NetworkingConfig , _ * v1.Platform , containerName string ) (container.ContainerCreateCreatedBody , error ) {
371
- if containerName == "workspace_cvm" {
372
+ if containerName == cli . InnerContainerName {
372
373
called = true
373
374
require .Equal (t , []string {"sleep" , "infinity" }, []string (config .Entrypoint ))
374
375
}
@@ -406,6 +407,42 @@ func TestDocker(t *testing.T) {
406
407
err := cmd .ExecuteContext (ctx )
407
408
require .NoError (t , err )
408
409
})
410
+
411
+ t .Run ("SetsResources" , func (t * testing.T ) {
412
+ t .Parallel ()
413
+
414
+ const (
415
+ // 4GB.
416
+ memory = 4 << 30
417
+ cpus = 6
418
+ )
419
+ name := namesgenerator .GetRandomName (1 )
420
+ ctx , cmd := clitest .New (t , "docker" ,
421
+ "--image=ubuntu" ,
422
+ "--username=root" ,
423
+ fmt .Sprintf ("--container-name=%s" , name ),
424
+ "--agent-token=hi" ,
425
+ fmt .Sprintf ("--cpus=%d" , cpus ),
426
+ fmt .Sprintf ("--memory=%d" , memory ),
427
+ )
428
+
429
+ var called bool
430
+ client := clitest .DockerClient (t , ctx )
431
+ client .ContainerCreateFn = func (_ context.Context , config * container.Config , hostConfig * container.HostConfig , networkingConfig * network.NetworkingConfig , _ * v1.Platform , containerName string ) (container.ContainerCreateCreatedBody , error ) {
432
+ if containerName == cli .InnerContainerName {
433
+ called = true
434
+ require .Equal (t , int64 (memory ), hostConfig .Memory )
435
+ require .Equal (t , int64 (cpus * dockerutil .DefaultCPUPeriod ), hostConfig .CPUQuota )
436
+ require .Equal (t , int64 (dockerutil .DefaultCPUPeriod ), hostConfig .CPUPeriod )
437
+ }
438
+
439
+ return container.ContainerCreateCreatedBody {}, nil
440
+ }
441
+
442
+ err := cmd .ExecuteContext (ctx )
443
+ require .NoError (t , err )
444
+ require .True (t , called , "create function was not called for inner container" )
445
+ })
409
446
}
410
447
411
448
// rawDockerAuth is sample input for a kubernetes secret to a gcr.io private
0 commit comments