Skip to content

Commit 2109c9d

Browse files
authored
Merge pull request #3399 from crazy-max/test-gitquerystring
test: git query string
2 parents 0567803 + 643322c commit 2109c9d

File tree

2 files changed

+144
-16
lines changed

2 files changed

+144
-16
lines changed

tests/build.go

Lines changed: 143 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,28 +115,155 @@ COPY --from=base /etc/bar /bar
115115
}
116116

117117
func testBuildRemote(t *testing.T, sb integration.Sandbox) {
118-
dockerfile := []byte(`
118+
t.Run("default branch", func(t *testing.T) {
119+
dockerfile := []byte(`
119120
FROM busybox:latest
120121
COPY foo /foo
121122
`)
122-
dir := tmpdir(
123-
t,
124-
fstest.CreateFile("Dockerfile", dockerfile, 0600),
125-
fstest.CreateFile("foo", []byte("foo"), 0600),
126-
)
127-
dirDest := t.TempDir()
123+
dir := tmpdir(
124+
t,
125+
fstest.CreateFile("Dockerfile", dockerfile, 0600),
126+
fstest.CreateFile("foo", []byte("foo"), 0600),
127+
)
128+
dirDest := t.TempDir()
128129

129-
git, err := gitutil.New(gitutil.WithWorkingDir(dir))
130-
require.NoError(t, err)
130+
git, err := gitutil.New(gitutil.WithWorkingDir(dir))
131+
require.NoError(t, err)
131132

132-
gittestutil.GitInit(git, t)
133-
gittestutil.GitAdd(git, t, "Dockerfile", "foo")
134-
gittestutil.GitCommit(git, t, "initial commit")
135-
addr := gittestutil.GitServeHTTP(git, t)
133+
gittestutil.GitInit(git, t)
134+
gittestutil.GitAdd(git, t, "Dockerfile", "foo")
135+
gittestutil.GitCommit(git, t, "initial commit")
136+
addr := gittestutil.GitServeHTTP(git, t)
136137

137-
out, err := buildCmd(sb, withDir(dir), withArgs("--output=type=local,dest="+dirDest, addr))
138-
require.NoError(t, err, out)
139-
require.FileExists(t, filepath.Join(dirDest, "foo"))
138+
out, err := buildCmd(sb, withDir(dir), withArgs("--output=type=local,dest="+dirDest, addr))
139+
require.NoError(t, err, out)
140+
require.FileExists(t, filepath.Join(dirDest, "foo"))
141+
})
142+
143+
t.Run("tag ref with url fragment", func(t *testing.T) {
144+
dockerfile := []byte(`
145+
FROM busybox:latest
146+
COPY foo /foo
147+
`)
148+
dir := tmpdir(
149+
t,
150+
fstest.CreateFile("Dockerfile", dockerfile, 0600),
151+
fstest.CreateFile("foo", []byte("foo"), 0600),
152+
)
153+
dirDest := t.TempDir()
154+
155+
git, err := gitutil.New(gitutil.WithWorkingDir(dir))
156+
require.NoError(t, err)
157+
158+
gittestutil.GitInit(git, t)
159+
gittestutil.GitAdd(git, t, "Dockerfile", "foo")
160+
gittestutil.GitCommit(git, t, "initial commit")
161+
gittestutil.GitTag(git, t, "v0.1.0")
162+
addr := gittestutil.GitServeHTTP(git, t)
163+
addr = addr + "#v0.1.0" // tag
164+
165+
out, err := buildCmd(sb, withDir(dir), withArgs("--output=type=local,dest="+dirDest, addr))
166+
require.NoError(t, err, out)
167+
require.FileExists(t, filepath.Join(dirDest, "foo"))
168+
})
169+
170+
t.Run("tag ref with query string", func(t *testing.T) {
171+
dockerfile := []byte(`
172+
FROM busybox:latest
173+
COPY foo /foo
174+
`)
175+
dir := tmpdir(
176+
t,
177+
fstest.CreateFile("Dockerfile", dockerfile, 0600),
178+
fstest.CreateFile("foo", []byte("foo"), 0600),
179+
)
180+
dirDest := t.TempDir()
181+
182+
git, err := gitutil.New(gitutil.WithWorkingDir(dir))
183+
require.NoError(t, err)
184+
185+
gittestutil.GitInit(git, t)
186+
gittestutil.GitAdd(git, t, "Dockerfile", "foo")
187+
gittestutil.GitCommit(git, t, "initial commit")
188+
gittestutil.GitTag(git, t, "v0.1.0")
189+
addr := gittestutil.GitServeHTTP(git, t)
190+
addr = addr + "?tag=v0.1.0" // tag
191+
192+
out, err := buildCmd(sb, withDir(dir), withArgs("--output=type=local,dest="+dirDest, addr))
193+
if matchesBuildKitVersion(t, sb, ">= 0.24.0-0") {
194+
require.NoError(t, err, out)
195+
require.FileExists(t, filepath.Join(dirDest, "foo"))
196+
} else {
197+
require.Error(t, err)
198+
require.Contains(t, out, "current frontend does not support Git URLs with query string components")
199+
}
200+
})
201+
202+
t.Run("tag ref with query string frontend 1.17", func(t *testing.T) {
203+
dockerfile := []byte(`
204+
# syntax=docker/dockerfile:1.17
205+
FROM busybox:latest
206+
COPY foo /foo
207+
`)
208+
dir := tmpdir(
209+
t,
210+
fstest.CreateFile("Dockerfile", dockerfile, 0600),
211+
fstest.CreateFile("foo", []byte("foo"), 0600),
212+
)
213+
dirDest := t.TempDir()
214+
215+
git, err := gitutil.New(gitutil.WithWorkingDir(dir))
216+
require.NoError(t, err)
217+
218+
gittestutil.GitInit(git, t)
219+
gittestutil.GitAdd(git, t, "Dockerfile", "foo")
220+
gittestutil.GitCommit(git, t, "initial commit")
221+
gittestutil.GitTag(git, t, "v0.1.0")
222+
addr := gittestutil.GitServeHTTP(git, t)
223+
addr = addr + "?tag=v0.1.0" // tag
224+
225+
out, err := buildCmd(sb, withDir(dir), withArgs("--output=type=local,dest="+dirDest, addr))
226+
if matchesBuildKitVersion(t, sb, ">= 0.24.0-0") {
227+
require.NoError(t, err, out)
228+
require.FileExists(t, filepath.Join(dirDest, "foo"))
229+
} else {
230+
require.Error(t, err)
231+
require.Contains(t, out, "current frontend does not support Git URLs with query string components")
232+
}
233+
})
234+
235+
t.Run("tag ref with query string frontend 1.18.0", func(t *testing.T) {
236+
dockerfile := []byte(`
237+
# syntax=docker/dockerfile-upstream:1.18.0
238+
FROM busybox:latest
239+
COPY foo /foo
240+
`)
241+
dir := tmpdir(
242+
t,
243+
fstest.CreateFile("Dockerfile", dockerfile, 0600),
244+
fstest.CreateFile("foo", []byte("foo"), 0600),
245+
)
246+
dirDest := t.TempDir()
247+
248+
git, err := gitutil.New(gitutil.WithWorkingDir(dir))
249+
require.NoError(t, err)
250+
251+
gittestutil.GitInit(git, t)
252+
gittestutil.GitAdd(git, t, "Dockerfile", "foo")
253+
gittestutil.GitCommit(git, t, "initial commit")
254+
gittestutil.GitTag(git, t, "v0.1.0")
255+
addr := gittestutil.GitServeHTTP(git, t)
256+
addr = addr + "?tag=v0.1.0" // tag
257+
258+
out, err := buildCmd(sb, withDir(dir), withArgs("--output=type=local,dest="+dirDest, addr))
259+
if matchesBuildKitVersion(t, sb, ">= 0.24.0-0") {
260+
require.NoError(t, err, out)
261+
require.FileExists(t, filepath.Join(dirDest, "foo"))
262+
} else {
263+
require.Error(t, err)
264+
require.Contains(t, out, "current frontend does not support Git URLs with query string components")
265+
}
266+
})
140267
}
141268

142269
func testBuildLocalState(t *testing.T, sb integration.Sandbox) {

tests/integration_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func testIntegration(t *testing.T, funcs ...func(t *testing.T, sb integration.Sa
4949
}
5050
}
5151
mirroredImages["moby/buildkit:buildx-stable-1"] = buildkitImage
52+
mirroredImages["docker/dockerfile-upstream:1.18.0"] = "docker.io/docker/dockerfile-upstream:1.18.0"
5253
mirrors := integration.WithMirroredImages(mirroredImages)
5354

5455
tests := integration.TestFuncs(funcs...)

0 commit comments

Comments
 (0)