@@ -434,6 +434,83 @@ func Test_RunContainer_JobContainer_VolumeMount(t *testing.T) {
434434 }
435435}
436436
437+ func Test_RunContainer_JobContainer_Environment (t * testing.T ) {
438+ client := newTestRuntimeClient (t )
439+
440+ type config struct {
441+ name string
442+ containerName string
443+ requiredFeatures []string
444+ sandboxImage string
445+ containerImage string
446+ env []* runtime.KeyValue
447+ exec []string
448+ }
449+
450+ tests := []config {
451+ {
452+ name : "JobContainer_Env_NoMountPoint" ,
453+ containerName : t .Name () + "-Container-WithNoMountPoint" ,
454+ requiredFeatures : []string {featureWCOWProcess , featureHostProcess },
455+ sandboxImage : imageWindowsNanoserver ,
456+ containerImage : imageWindowsNanoserver ,
457+ env : []* runtime.KeyValue {
458+ {
459+ Key : "PATH" , Value : "C:\\ Windows\\ system32;C:\\ Windows" ,
460+ },
461+ },
462+ exec : []string {"cmd" , "/c" , "IF" , "%PATH%" , "==" , "C:\\ Windows\\ system32;C:\\ Windows" , "( exit 0 )" , "ELSE" , "(exit -1)" },
463+ },
464+ {
465+ name : "JobContainer_VolumeMount_WithMountPoint" ,
466+ containerName : t .Name () + "-Container-WithMountPoint" ,
467+ requiredFeatures : []string {featureWCOWProcess , featureHostProcess },
468+ sandboxImage : imageWindowsNanoserver ,
469+ containerImage : imageWindowsNanoserver ,
470+ env : []* runtime.KeyValue {
471+ {
472+ Key : "PATH" , Value : "%CONTAINER_SANDBOX_MOUNT_POINT%\\ apps\\ vim\\ ;C:\\ Windows\\ system32;C:\\ Windows" ,
473+ },
474+ },
475+ exec : []string {"cmd" , "/c" , "IF" , "%PATH%" , "==" , "%CONTAINER_SANDBOX_MOUNT_POINT%\\ apps\\ vim\\ ;C:\\ Windows\\ system32;C:\\ Windows" , "( exit -1 )" , "ELSE" , "(exit 0)" },
476+ },
477+ }
478+
479+ for _ , test := range tests {
480+ t .Run (test .name , func (t * testing.T ) {
481+ requireFeatures (t , test .requiredFeatures ... )
482+
483+ requiredImages := []string {test .sandboxImage , test .containerImage }
484+ pullRequiredImages (t , requiredImages )
485+
486+ podctx := context .Background ()
487+ sandboxRequest := getJobContainerPodRequestWCOW (t )
488+
489+ podID := runPodSandbox (t , client , podctx , sandboxRequest )
490+ defer removePodSandbox (t , client , podctx , podID )
491+ defer stopPodSandbox (t , client , podctx , podID )
492+
493+ containerRequest := getJobContainerRequestWCOW (t , podID , sandboxRequest .Config , imageWindowsNanoserver , nil )
494+ containerRequest .Config .Envs = test .env
495+ ctx , cancel := context .WithTimeout (context .Background (), 20 * time .Second )
496+ defer cancel ()
497+
498+ containerID := createContainer (t , client , ctx , containerRequest )
499+ defer removeContainer (t , client , ctx , containerID )
500+ startContainer (t , client , ctx , containerID )
501+ defer stopContainer (t , client , ctx , containerID )
502+
503+ r := execSync (t , client , ctx , & runtime.ExecSyncRequest {
504+ ContainerId : containerID ,
505+ Cmd : test .exec ,
506+ })
507+ if r .ExitCode != 0 {
508+ t .Fatalf ("failed with exit code %d checking for job container mount: %s" , r .ExitCode , string (r .Stderr ))
509+ }
510+ })
511+ }
512+ }
513+
437514func Test_RunContainer_WorkingDirectory_JobContainer_WCOW (t * testing.T ) {
438515 client := newTestRuntimeClient (t )
439516
0 commit comments