@@ -550,13 +550,27 @@ func TestFolderAddSnippet_PerformsSubstitutionWithoutUserName(t *testing.T) {
550550 snippetJSONFilename := filepath .Join (snippetFolder , "snippet.json" )
551551 _ = ioutil .WriteFile (snippetJSONFilename , []byte (`{
552552 "actions": [
553+ {
554+ "type": "mergeJSON",
555+ "source": "devcontainer.json",
556+ "target": ".devcontainer/devcontainer.json"
557+ },
553558 {
554559 "type": "dockerfileSnippet",
555560 "content": "ENV DC_NAME=__DEVCONTAINER_NAME__\nENV DC_USER_NAME=__DEVCONTAINER_USER_NAME__\nENV DC_HOME=__DEVCONTAINER_HOME__"
556561 }
557562 ]
558563 }` ), 0755 )
559564
565+ snippetDevcontainerFilename := filepath .Join (snippetFolder , "devcontainer.json" )
566+ _ = ioutil .WriteFile (snippetDevcontainerFilename , []byte (`{
567+ "settings": {
568+ "DC_NAME": "__DEVCONTAINER_NAME__",
569+ "DC_USER_NAME": "__DEVCONTAINER_USER_NAME__",
570+ "DC_HOME": "__DEVCONTAINER_HOME__"
571+ },
572+ }` ), 0755 )
573+
560574 // set up devcontainer
561575 targetFolder := filepath .Join (root , "target" )
562576 devcontainerFolder := filepath .Join (targetFolder , ".devcontainer" )
@@ -599,6 +613,21 @@ ENV DC_HOME=/root
599613
600614RUN echo hi2
601615` , string (buf ))
616+
617+ buf , err = ioutil .ReadFile (filepath .Join (devcontainerFolder , "devcontainer.json" ))
618+ if ! assert .NoError (t , err ) {
619+ return
620+ }
621+ stringContent := string (buf )
622+ assert .Equal (t , `{
623+ "name" : "testname",
624+ "settings": {
625+ "DC_NAME": "testname",
626+ "DC_USER_NAME": "root",
627+ "DC_HOME": "/root"
628+ },
629+ }` , stringContent )
630+
602631}
603632func TestFolderAddSnippet_PerformsSubstitutionWithUserName (t * testing.T ) {
604633
@@ -611,13 +640,27 @@ func TestFolderAddSnippet_PerformsSubstitutionWithUserName(t *testing.T) {
611640 snippetJSONFilename := filepath .Join (snippetFolder , "snippet.json" )
612641 _ = ioutil .WriteFile (snippetJSONFilename , []byte (`{
613642 "actions": [
643+ {
644+ "type": "mergeJSON",
645+ "source": "devcontainer.json",
646+ "target": ".devcontainer/devcontainer.json"
647+ },
614648 {
615649 "type": "dockerfileSnippet",
616650 "content": "ENV DC_NAME=__DEVCONTAINER_NAME__\nENV DC_USER_NAME=__DEVCONTAINER_USER_NAME__\nENV DC_HOME=__DEVCONTAINER_HOME__"
617651 }
618652 ]
619653 }` ), 0755 )
620654
655+ snippetDevcontainerFilename := filepath .Join (snippetFolder , "devcontainer.json" )
656+ _ = ioutil .WriteFile (snippetDevcontainerFilename , []byte (`{
657+ "settings": {
658+ "DC_NAME": "__DEVCONTAINER_NAME__",
659+ "DC_USER_NAME": "__DEVCONTAINER_USER_NAME__",
660+ "DC_HOME": "__DEVCONTAINER_HOME__"
661+ },
662+ }` ), 0755 )
663+
621664 // set up devcontainer
622665 targetFolder := filepath .Join (root , "target" )
623666 devcontainerFolder := filepath .Join (targetFolder , ".devcontainer" )
@@ -661,4 +704,20 @@ ENV DC_HOME=/home/dcuser
661704
662705RUN echo hi2
663706` , string (buf ))
707+
708+ buf , err = ioutil .ReadFile (filepath .Join (devcontainerFolder , "devcontainer.json" ))
709+ if ! assert .NoError (t , err ) {
710+ return
711+ }
712+ stringContent := string (buf )
713+ assert .Equal (t , `{
714+ "name" : "testname",
715+ "remoteUser": "dcuser",
716+ "settings": {
717+ "DC_NAME": "testname",
718+ "DC_USER_NAME": "dcuser",
719+ "DC_HOME": "/home/dcuser"
720+ },
721+ }` , stringContent )
722+
664723}
0 commit comments