@@ -695,6 +695,46 @@ PATH=/usr/local/bin:/bin:/go/bin:/opt
695
695
REMOTE_BAR=bar` )
696
696
}
697
697
698
+ func TestUnsetOptionsEnv (t * testing.T ) {
699
+ t .Parallel ()
700
+
701
+ // Ensures that a Git repository with a devcontainer.json is cloned and built.
702
+ srv := createGitServer (t , gitServerOptions {
703
+ files : map [string ]string {
704
+ ".devcontainer/devcontainer.json" : `{
705
+ "name": "Test",
706
+ "build": {
707
+ "dockerfile": "Dockerfile"
708
+ },
709
+ }` ,
710
+ ".devcontainer/Dockerfile" : "FROM " + testImageAlpine + "\n ENV FROM_DOCKERFILE=foo" ,
711
+ },
712
+ })
713
+ ctr , err := runEnvbuilder (t , options {env : []string {
714
+ envbuilderEnv ("GIT_URL" , srv .URL ),
715
+ "GIT_URL" , srv .URL ,
716
+ envbuilderEnv ("GIT_PASSWORD" , "supersecret" ),
717
+ "GIT_PASSWORD" , "supersecret" ,
718
+ envbuilderEnv ("INIT_SCRIPT" , "env > /root/env.txt && sleep infinity" ),
719
+ "INIT_SCRIPT" , "env > /root/env.txt && sleep infinity" ,
720
+ }})
721
+ require .NoError (t , err )
722
+
723
+ output := execContainer (t , ctr , "cat /root/env.txt" )
724
+ var os envbuilder.Options
725
+ for _ , s := range strings .Split (strings .TrimSpace (output ), "\n " ) {
726
+ for _ , o := range os .CLI () {
727
+ if strings .HasPrefix (s , o .Env ) {
728
+ assert .Fail (t , "environment variable should be stripped when running init script" , s )
729
+ }
730
+ optWithoutPrefix := strings .TrimPrefix (o .Env , envbuilder .WithEnvPrefix ("" ))
731
+ if strings .HasPrefix (s , optWithoutPrefix ) {
732
+ assert .Fail (t , "environment variable should be stripped when running init script" , s )
733
+ }
734
+ }
735
+ }
736
+ }
737
+
698
738
func TestLifecycleScripts (t * testing.T ) {
699
739
t .Parallel ()
700
740
0 commit comments