Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2953d4d

Browse files
author
Aaron Lehmann
committed
Fix FeatureContexts keys
This needs to be updated to correspond to the changes in coder#205.
1 parent b1e4be1 commit 2953d4d

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

devcontainer/devcontainer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func (s *Spec) compileFeatures(fs billy.Filesystem, devcontainerDir, scratchDir
295295
}
296296
featureDirectives = append(featureDirectives, directive)
297297
if useBuildContexts {
298-
featureContexts[featureName] = featureDir
298+
featureContexts[featureRef] = featureDir
299299
lines = append(lines, fromDirective)
300300
}
301301
}

devcontainer/devcontainer_test.go

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,35 @@ func TestCompileWithFeatures(t *testing.T) {
8787
dc, err := devcontainer.Parse([]byte(raw))
8888
require.NoError(t, err)
8989
fs := memfs.New()
90-
params, err := dc.Compile(fs, "", magicDir, "", "", false, os.LookupEnv)
91-
require.NoError(t, err)
9290

93-
// We have to SHA because we get a different MD5 every time!
9491
featureOneMD5 := md5.Sum([]byte(featureOne))
9592
featureOneDir := fmt.Sprintf("/.envbuilder/features/one-%x", featureOneMD5[:4])
9693
featureTwoMD5 := md5.Sum([]byte(featureTwo))
9794
featureTwoDir := fmt.Sprintf("/.envbuilder/features/two-%x", featureTwoMD5[:4])
9895

99-
require.Equal(t, `FROM localhost:5000/envbuilder-test-codercom-code-server:latest
96+
t.Run("WithoutBuildContexts", func(t *testing.T) {
97+
params, err := dc.Compile(fs, "", magicDir, "", "", false, os.LookupEnv)
98+
require.NoError(t, err)
99+
100+
require.Equal(t, `FROM localhost:5000/envbuilder-test-codercom-code-server:latest
101+
102+
USER root
103+
# Rust tomato - Example description!
104+
WORKDIR `+featureOneDir+`
105+
ENV TOMATO=example
106+
RUN _CONTAINER_USER="1000" _REMOTE_USER="1000" ./install.sh
107+
# Go potato - Example description!
108+
WORKDIR `+featureTwoDir+`
109+
ENV POTATO=example
110+
RUN VERSION="potato" _CONTAINER_USER="1000" _REMOTE_USER="1000" ./install.sh
111+
USER 1000`, params.DockerfileContent)
112+
})
113+
114+
t.Run("WithBuildContexts", func(t *testing.T) {
115+
params, err := dc.Compile(fs, "", magicDir, "", "", false, os.LookupEnv)
116+
require.NoError(t, err)
117+
118+
require.Equal(t, `FROM localhost:5000/envbuilder-test-codercom-code-server:latest
100119
101120
USER root
102121
# Rust tomato - Example description!
@@ -108,6 +127,12 @@ WORKDIR `+featureTwoDir+`
108127
ENV POTATO=example
109128
RUN VERSION="potato" _CONTAINER_USER="1000" _REMOTE_USER="1000" ./install.sh
110129
USER 1000`, params.DockerfileContent)
130+
131+
require.Equal(t, map[string]string{
132+
"coder/one": featureOneDir,
133+
"coder/two": featureTwoDir,
134+
}, params.FeatureContexts)
135+
})
111136
}
112137

113138
func TestCompileDevContainer(t *testing.T) {

0 commit comments

Comments
 (0)