@@ -38,7 +38,6 @@ import (
38
38
"github.com/docker/docker/api/types/volume"
39
39
"github.com/docker/docker/client"
40
40
"github.com/docker/docker/pkg/stdcopy"
41
- "github.com/go-git/go-billy/v5/memfs"
42
41
"github.com/google/go-containerregistry/pkg/authn"
43
42
"github.com/google/go-containerregistry/pkg/name"
44
43
"github.com/google/go-containerregistry/pkg/registry"
@@ -68,8 +67,8 @@ func TestInitScriptInitCommand(t *testing.T) {
68
67
w .WriteHeader (http .StatusOK )
69
68
}))
70
69
71
- srv := createGitServer (t , gitServerOptions {
72
- files : map [string ]string {
70
+ srv := gittest . CreateGitServer (t , gittest. Options {
71
+ Files : map [string ]string {
73
72
// Let's say /bin/sh is not available and we can only use /bin/ash
74
73
"Dockerfile" : fmt .Sprintf ("FROM %s\n RUN unlink /bin/sh" , testImageAlpine ),
75
74
},
@@ -113,7 +112,7 @@ RUN mkdir -p /myapp/somedir \
113
112
&& touch /myapp/somedir/somefile \
114
113
&& chown 123:123 /myapp/somedir \
115
114
&& chown 321:321 /myapp/somedir/somefile
116
-
115
+
117
116
FROM %s
118
117
COPY --from=builder /myapp /myapp
119
118
RUN printf "%%s\n" \
@@ -127,8 +126,8 @@ RUN printf "%%s\n" \
127
126
/myapp/somedir/somefile \
128
127
> /tmp/got \
129
128
&& diff -u /tmp/got /tmp/expected` , testImageAlpine , testImageAlpine )
130
- srv := createGitServer (t , gitServerOptions {
131
- files : map [string ]string {
129
+ srv := gittest . CreateGitServer (t , gittest. Options {
130
+ Files : map [string ]string {
132
131
"Dockerfile" : dockerFile ,
133
132
},
134
133
})
@@ -158,8 +157,8 @@ RUN mkdir -p /myapp/somedir \
158
157
/myapp/somedir/somefile \
159
158
> /tmp/got \
160
159
&& diff -u /tmp/got /tmp/expected` , testImageAlpine )
161
- srv := createGitServer (t , gitServerOptions {
162
- files : map [string ]string {
160
+ srv := gittest . CreateGitServer (t , gittest. Options {
161
+ Files : map [string ]string {
163
162
"Dockerfile" : dockerFile ,
164
163
},
165
164
})
@@ -176,8 +175,8 @@ func TestForceSafe(t *testing.T) {
176
175
177
176
t .Run ("Safe" , func (t * testing.T ) {
178
177
t .Parallel ()
179
- srv := createGitServer (t , gitServerOptions {
180
- files : map [string ]string {
178
+ srv := gittest . CreateGitServer (t , gittest. Options {
179
+ Files : map [string ]string {
181
180
"Dockerfile" : "FROM " + testImageAlpine ,
182
181
},
183
182
})
@@ -192,8 +191,8 @@ func TestForceSafe(t *testing.T) {
192
191
// Careful with this one!
193
192
t .Run ("Unsafe" , func (t * testing.T ) {
194
193
t .Parallel ()
195
- srv := createGitServer (t , gitServerOptions {
196
- files : map [string ]string {
194
+ srv := gittest . CreateGitServer (t , gittest. Options {
195
+ Files : map [string ]string {
197
196
"Dockerfile" : "FROM " + testImageAlpine ,
198
197
},
199
198
})
@@ -209,12 +208,12 @@ func TestForceSafe(t *testing.T) {
209
208
210
209
func TestFailsGitAuth (t * testing.T ) {
211
210
t .Parallel ()
212
- srv := createGitServer (t , gitServerOptions {
213
- files : map [string ]string {
211
+ srv := gittest . CreateGitServer (t , gittest. Options {
212
+ Files : map [string ]string {
214
213
"Dockerfile" : "FROM " + testImageAlpine ,
215
214
},
216
- username : "kyle" ,
217
- password : "testing" ,
215
+ Username : "kyle" ,
216
+ Password : "testing" ,
218
217
})
219
218
_ , err := runEnvbuilder (t , runOpts {env : []string {
220
219
envbuilderEnv ("GIT_URL" , srv .URL ),
@@ -224,12 +223,12 @@ func TestFailsGitAuth(t *testing.T) {
224
223
225
224
func TestSucceedsGitAuth (t * testing.T ) {
226
225
t .Parallel ()
227
- srv := createGitServer (t , gitServerOptions {
228
- files : map [string ]string {
226
+ srv := gittest . CreateGitServer (t , gittest. Options {
227
+ Files : map [string ]string {
229
228
"Dockerfile" : "FROM " + testImageAlpine ,
230
229
},
231
- username : "kyle" ,
232
- password : "testing" ,
230
+ Username : "kyle" ,
231
+ Password : "testing" ,
233
232
})
234
233
ctr , err := runEnvbuilder (t , runOpts {env : []string {
235
234
envbuilderEnv ("GIT_URL" , srv .URL ),
@@ -244,12 +243,12 @@ func TestSucceedsGitAuth(t *testing.T) {
244
243
245
244
func TestSucceedsGitAuthInURL (t * testing.T ) {
246
245
t .Parallel ()
247
- srv := createGitServer (t , gitServerOptions {
248
- files : map [string ]string {
246
+ srv := gittest . CreateGitServer (t , gittest. Options {
247
+ Files : map [string ]string {
249
248
"Dockerfile" : "FROM " + testImageAlpine ,
250
249
},
251
- username : "kyle" ,
252
- password : "testing" ,
250
+ Username : "kyle" ,
251
+ Password : "testing" ,
253
252
})
254
253
255
254
u , err := url .Parse (srv .URL )
@@ -309,8 +308,8 @@ func TestBuildFromDevcontainerWithFeatures(t *testing.T) {
309
308
require .NoError (t , err )
310
309
311
310
// Ensures that a Git repository with a devcontainer.json is cloned and built.
312
- srv := createGitServer (t , gitServerOptions {
313
- files : map [string ]string {
311
+ srv := gittest . CreateGitServer (t , gittest. Options {
312
+ Files : map [string ]string {
314
313
".devcontainer/devcontainer.json" : `{
315
314
"name": "Test",
316
315
"build": {
@@ -350,8 +349,8 @@ func TestBuildFromDevcontainerWithFeatures(t *testing.T) {
350
349
351
350
func TestBuildFromDockerfile (t * testing.T ) {
352
351
// Ensures that a Git repository with a Dockerfile is cloned and built.
353
- srv := createGitServer (t , gitServerOptions {
354
- files : map [string ]string {
352
+ srv := gittest . CreateGitServer (t , gittest. Options {
353
+ Files : map [string ]string {
355
354
"Dockerfile" : "FROM " + testImageAlpine ,
356
355
},
357
356
})
@@ -372,8 +371,8 @@ func TestBuildFromDockerfile(t *testing.T) {
372
371
373
372
func TestBuildPrintBuildOutput (t * testing.T ) {
374
373
// Ensures that a Git repository with a Dockerfile is cloned and built.
375
- srv := createGitServer (t , gitServerOptions {
376
- files : map [string ]string {
374
+ srv := gittest . CreateGitServer (t , gittest. Options {
375
+ Files : map [string ]string {
377
376
"Dockerfile" : "FROM " + testImageAlpine + "\n RUN echo hello" ,
378
377
},
379
378
})
@@ -400,8 +399,8 @@ func TestBuildPrintBuildOutput(t *testing.T) {
400
399
401
400
func TestBuildIgnoreVarRunSecrets (t * testing.T ) {
402
401
// Ensures that a Git repository with a Dockerfile is cloned and built.
403
- srv := createGitServer (t , gitServerOptions {
404
- files : map [string ]string {
402
+ srv := gittest . CreateGitServer (t , gittest. Options {
403
+ Files : map [string ]string {
405
404
"Dockerfile" : "FROM " + testImageAlpine ,
406
405
},
407
406
})
@@ -441,8 +440,8 @@ func TestBuildIgnoreVarRunSecrets(t *testing.T) {
441
440
442
441
func TestBuildWithSetupScript (t * testing.T ) {
443
442
// Ensures that a Git repository with a Dockerfile is cloned and built.
444
- srv := createGitServer (t , gitServerOptions {
445
- files : map [string ]string {
443
+ srv := gittest . CreateGitServer (t , gittest. Options {
444
+ Files : map [string ]string {
446
445
"Dockerfile" : "FROM " + testImageAlpine ,
447
446
},
448
447
})
@@ -461,8 +460,8 @@ func TestBuildFromDevcontainerInCustomPath(t *testing.T) {
461
460
t .Parallel ()
462
461
463
462
// Ensures that a Git repository with a devcontainer.json is cloned and built.
464
- srv := createGitServer (t , gitServerOptions {
465
- files : map [string ]string {
463
+ srv := gittest . CreateGitServer (t , gittest. Options {
464
+ Files : map [string ]string {
466
465
".devcontainer/custom/devcontainer.json" : `{
467
466
"name": "Test",
468
467
"build": {
@@ -486,8 +485,8 @@ func TestBuildFromDevcontainerInSubfolder(t *testing.T) {
486
485
t .Parallel ()
487
486
488
487
// Ensures that a Git repository with a devcontainer.json is cloned and built.
489
- srv := createGitServer (t , gitServerOptions {
490
- files : map [string ]string {
488
+ srv := gittest . CreateGitServer (t , gittest. Options {
489
+ Files : map [string ]string {
491
490
".devcontainer/subfolder/devcontainer.json" : `{
492
491
"name": "Test",
493
492
"build": {
@@ -510,8 +509,8 @@ func TestBuildFromDevcontainerInRoot(t *testing.T) {
510
509
t .Parallel ()
511
510
512
511
// Ensures that a Git repository with a devcontainer.json is cloned and built.
513
- srv := createGitServer (t , gitServerOptions {
514
- files : map [string ]string {
512
+ srv := gittest . CreateGitServer (t , gittest. Options {
513
+ Files : map [string ]string {
515
514
"devcontainer.json" : `{
516
515
"name": "Test",
517
516
"build": {
@@ -531,11 +530,11 @@ func TestBuildFromDevcontainerInRoot(t *testing.T) {
531
530
}
532
531
533
532
func TestBuildCustomCertificates (t * testing.T ) {
534
- srv := createGitServer (t , gitServerOptions {
535
- files : map [string ]string {
533
+ srv := gittest . CreateGitServer (t , gittest. Options {
534
+ Files : map [string ]string {
536
535
"Dockerfile" : "FROM " + testImageAlpine ,
537
536
},
538
- tls : true ,
537
+ TLS : true ,
539
538
})
540
539
ctr , err := runEnvbuilder (t , runOpts {env : []string {
541
540
envbuilderEnv ("GIT_URL" , srv .URL ),
@@ -553,8 +552,8 @@ func TestBuildCustomCertificates(t *testing.T) {
553
552
554
553
func TestBuildStopStartCached (t * testing.T ) {
555
554
// Ensures that a Git repository with a Dockerfile is cloned and built.
556
- srv := createGitServer (t , gitServerOptions {
557
- files : map [string ]string {
555
+ srv := gittest . CreateGitServer (t , gittest. Options {
556
+ Files : map [string ]string {
558
557
"Dockerfile" : "FROM " + testImageAlpine ,
559
558
},
560
559
})
@@ -601,8 +600,8 @@ func TestBuildFailsFallback(t *testing.T) {
601
600
t .Run ("BadDockerfile" , func (t * testing.T ) {
602
601
t .Parallel ()
603
602
// Ensures that a Git repository with a Dockerfile is cloned and built.
604
- srv := createGitServer (t , gitServerOptions {
605
- files : map [string ]string {
603
+ srv := gittest . CreateGitServer (t , gittest. Options {
604
+ Files : map [string ]string {
606
605
"Dockerfile" : "bad syntax" ,
607
606
},
608
607
})
@@ -616,8 +615,8 @@ func TestBuildFailsFallback(t *testing.T) {
616
615
t .Run ("FailsBuild" , func (t * testing.T ) {
617
616
t .Parallel ()
618
617
// Ensures that a Git repository with a Dockerfile is cloned and built.
619
- srv := createGitServer (t , gitServerOptions {
620
- files : map [string ]string {
618
+ srv := gittest . CreateGitServer (t , gittest. Options {
619
+ Files : map [string ]string {
621
620
"Dockerfile" : `FROM ` + testImageAlpine + `
622
621
RUN exit 1` ,
623
622
},
@@ -631,8 +630,8 @@ RUN exit 1`,
631
630
t .Run ("BadDevcontainer" , func (t * testing.T ) {
632
631
t .Parallel ()
633
632
// Ensures that a Git repository with a Dockerfile is cloned and built.
634
- srv := createGitServer (t , gitServerOptions {
635
- files : map [string ]string {
633
+ srv := gittest . CreateGitServer (t , gittest. Options {
634
+ Files : map [string ]string {
636
635
".devcontainer/devcontainer.json" : "not json" ,
637
636
},
638
637
})
@@ -643,8 +642,8 @@ RUN exit 1`,
643
642
})
644
643
t .Run ("NoImageOrDockerfile" , func (t * testing.T ) {
645
644
t .Parallel ()
646
- srv := createGitServer (t , gitServerOptions {
647
- files : map [string ]string {
645
+ srv := gittest . CreateGitServer (t , gittest. Options {
646
+ Files : map [string ]string {
648
647
".devcontainer/devcontainer.json" : "{}" ,
649
648
},
650
649
})
@@ -661,8 +660,8 @@ RUN exit 1`,
661
660
662
661
func TestExitBuildOnFailure (t * testing.T ) {
663
662
t .Parallel ()
664
- srv := createGitServer (t , gitServerOptions {
665
- files : map [string ]string {
663
+ srv := gittest . CreateGitServer (t , gittest. Options {
664
+ Files : map [string ]string {
666
665
"Dockerfile" : "bad syntax" ,
667
666
},
668
667
})
@@ -680,8 +679,8 @@ func TestContainerEnv(t *testing.T) {
680
679
t .Parallel ()
681
680
682
681
// Ensures that a Git repository with a devcontainer.json is cloned and built.
683
- srv := createGitServer (t , gitServerOptions {
684
- files : map [string ]string {
682
+ srv := gittest . CreateGitServer (t , gittest. Options {
683
+ Files : map [string ]string {
685
684
".devcontainer/devcontainer.json" : `{
686
685
"name": "Test",
687
686
"build": {
@@ -722,8 +721,8 @@ func TestUnsetOptionsEnv(t *testing.T) {
722
721
t .Parallel ()
723
722
724
723
// Ensures that a Git repository with a devcontainer.json is cloned and built.
725
- srv := createGitServer (t , gitServerOptions {
726
- files : map [string ]string {
724
+ srv := gittest . CreateGitServer (t , gittest. Options {
725
+ Files : map [string ]string {
727
726
".devcontainer/devcontainer.json" : `{
728
727
"name": "Test",
729
728
"build": {
@@ -762,8 +761,8 @@ func TestLifecycleScripts(t *testing.T) {
762
761
t .Parallel ()
763
762
764
763
// Ensures that a Git repository with a devcontainer.json is cloned and built.
765
- srv := createGitServer (t , gitServerOptions {
766
- files : map [string ]string {
764
+ srv := gittest . CreateGitServer (t , gittest. Options {
765
+ Files : map [string ]string {
767
766
".devcontainer/devcontainer.json" : `{
768
767
"name": "Test",
769
768
"build": {
@@ -798,8 +797,8 @@ func TestPostStartScript(t *testing.T) {
798
797
t .Parallel ()
799
798
800
799
// Ensures that a Git repository with a devcontainer.json is cloned and built.
801
- srv := createGitServer (t , gitServerOptions {
802
- files : map [string ]string {
800
+ srv := gittest . CreateGitServer (t , gittest. Options {
801
+ Files : map [string ]string {
803
802
".devcontainer/devcontainer.json" : `{
804
803
"name": "Test",
805
804
"build": {
@@ -848,8 +847,8 @@ func TestPrivateRegistry(t *testing.T) {
848
847
})
849
848
850
849
// Ensures that a Git repository with a Dockerfile is cloned and built.
851
- srv := createGitServer (t , gitServerOptions {
852
- files : map [string ]string {
850
+ srv := gittest . CreateGitServer (t , gittest. Options {
851
+ Files : map [string ]string {
853
852
"Dockerfile" : "FROM " + image ,
854
853
},
855
854
})
@@ -867,8 +866,8 @@ func TestPrivateRegistry(t *testing.T) {
867
866
})
868
867
869
868
// Ensures that a Git repository with a Dockerfile is cloned and built.
870
- srv := createGitServer (t , gitServerOptions {
871
- files : map [string ]string {
869
+ srv := gittest . CreateGitServer (t , gittest. Options {
870
+ Files : map [string ]string {
872
871
"Dockerfile" : "FROM " + image ,
873
872
},
874
873
})
@@ -899,8 +898,8 @@ func TestPrivateRegistry(t *testing.T) {
899
898
})
900
899
901
900
// Ensures that a Git repository with a Dockerfile is cloned and built.
902
- srv := createGitServer (t , gitServerOptions {
903
- files : map [string ]string {
901
+ srv := gittest . CreateGitServer (t , gittest. Options {
902
+ Files : map [string ]string {
904
903
"Dockerfile" : "FROM " + image ,
905
904
},
906
905
})
@@ -1042,8 +1041,8 @@ COPY %s .`, testImageAlpine, inclFile)
1042
1041
tc := tc
1043
1042
1044
1043
t .Run (tc .name , func (t * testing.T ) {
1045
- srv := createGitServer (t , gitServerOptions {
1046
- files : tc .files ,
1044
+ srv := gittest . CreateGitServer (t , gittest. Options {
1045
+ Files : tc .files ,
1047
1046
})
1048
1047
_ , err := runEnvbuilder (t , runOpts {env : []string {
1049
1048
envbuilderEnv ("GIT_URL" , srv .URL ),
@@ -1066,8 +1065,8 @@ func TestPushImage(t *testing.T) {
1066
1065
t .Run ("CacheWithoutPush" , func (t * testing.T ) {
1067
1066
t .Parallel ()
1068
1067
1069
- srv := createGitServer (t , gitServerOptions {
1070
- files : map [string ]string {
1068
+ srv := gittest . CreateGitServer (t , gittest. Options {
1069
+ Files : map [string ]string {
1071
1070
".devcontainer/Dockerfile" : fmt .Sprintf (`FROM %s
1072
1071
USER root
1073
1072
ARG WORKDIR=/
@@ -1127,8 +1126,8 @@ RUN date --utc > /root/date.txt`, testImageAlpine),
1127
1126
t .Run ("CacheAndPush" , func (t * testing.T ) {
1128
1127
t .Parallel ()
1129
1128
1130
- srv := createGitServer (t , gitServerOptions {
1131
- files : map [string ]string {
1129
+ srv := gittest . CreateGitServer (t , gittest. Options {
1130
+ Files : map [string ]string {
1132
1131
".devcontainer/Dockerfile" : fmt .Sprintf (`FROM %s
1133
1132
USER root
1134
1133
ARG WORKDIR=/
@@ -1243,11 +1242,117 @@ RUN date --utc > /root/date.txt`, testImageAlpine),
1243
1242
require .NotEmpty (t , strings .TrimSpace (out ))
1244
1243
})
1245
1244
1245
+ t .Run ("CacheAndPushDevcontainerOnly" , func (t * testing.T ) {
1246
+ t .Parallel ()
1247
+
1248
+ srv := gittest .CreateGitServer (t , gittest.Options {
1249
+ Files : map [string ]string {
1250
+ ".devcontainer/devcontainer.json" : fmt .Sprintf (`{"image": %q}` , testImageAlpine ),
1251
+ },
1252
+ })
1253
+
1254
+ // Given: an empty registry
1255
+ testReg := setupInMemoryRegistry (t , setupInMemoryRegistryOpts {})
1256
+ testRepo := testReg + "/test"
1257
+ ref , err := name .ParseReference (testRepo + ":latest" )
1258
+ require .NoError (t , err )
1259
+ _ , err = remote .Image (ref )
1260
+ require .ErrorContains (t , err , "NAME_UNKNOWN" , "expected image to not be present before build + push" )
1261
+
1262
+ // When: we run envbuilder with GET_CACHED_IMAGE
1263
+ _ , err = runEnvbuilder (t , runOpts {env : []string {
1264
+ envbuilderEnv ("GIT_URL" , srv .URL ),
1265
+ envbuilderEnv ("CACHE_REPO" , testRepo ),
1266
+ envbuilderEnv ("GET_CACHED_IMAGE" , "1" ),
1267
+ }})
1268
+ require .ErrorContains (t , err , "error probing build cache: uncached COPY command" )
1269
+ // Then: it should fail to build the image and nothing should be pushed
1270
+ _ , err = remote .Image (ref )
1271
+ require .ErrorContains (t , err , "NAME_UNKNOWN" , "expected image to not be present before build + push" )
1272
+
1273
+ // When: we run envbuilder with PUSH_IMAGE set
1274
+ _ , err = runEnvbuilder (t , runOpts {env : []string {
1275
+ envbuilderEnv ("GIT_URL" , srv .URL ),
1276
+ envbuilderEnv ("CACHE_REPO" , testRepo ),
1277
+ envbuilderEnv ("PUSH_IMAGE" , "1" ),
1278
+ }})
1279
+ require .NoError (t , err )
1280
+
1281
+ // Then: the image should be pushed
1282
+ img , err := remote .Image (ref )
1283
+ require .NoError (t , err , "expected image to be present after build + push" )
1284
+
1285
+ // Then: the image should have its directives replaced with those required
1286
+ // to run envbuilder automatically
1287
+ configFile , err := img .ConfigFile ()
1288
+ require .NoError (t , err , "expected image to return a config file" )
1289
+
1290
+ assert .Equal (t , "root" , configFile .Config .User , "user must be root" )
1291
+ assert .Equal (t , "/" , configFile .Config .WorkingDir , "workdir must be /" )
1292
+ if assert .Len (t , configFile .Config .Entrypoint , 1 ) {
1293
+ assert .Equal (t , "/.envbuilder/bin/envbuilder" , configFile .Config .Entrypoint [0 ], "incorrect entrypoint" )
1294
+ }
1295
+
1296
+ // Then: re-running envbuilder with GET_CACHED_IMAGE should succeed
1297
+ ctrID , err := runEnvbuilder (t , runOpts {env : []string {
1298
+ envbuilderEnv ("GIT_URL" , srv .URL ),
1299
+ envbuilderEnv ("CACHE_REPO" , testRepo ),
1300
+ envbuilderEnv ("GET_CACHED_IMAGE" , "1" ),
1301
+ }})
1302
+ require .NoError (t , err )
1303
+
1304
+ // Then: the cached image ref should be emitted in the container logs
1305
+ ctx , cancel := context .WithCancel (context .Background ())
1306
+ t .Cleanup (cancel )
1307
+ cli , err := client .NewClientWithOpts (client .FromEnv , client .WithAPIVersionNegotiation ())
1308
+ require .NoError (t , err )
1309
+ defer cli .Close ()
1310
+ logs , err := cli .ContainerLogs (ctx , ctrID , container.LogsOptions {
1311
+ ShowStdout : true ,
1312
+ ShowStderr : true ,
1313
+ })
1314
+ require .NoError (t , err )
1315
+ defer logs .Close ()
1316
+ logBytes , err := io .ReadAll (logs )
1317
+ require .NoError (t , err )
1318
+ require .Regexp (t , `ENVBUILDER_CACHED_IMAGE=(\S+)` , string (logBytes ))
1319
+
1320
+ // When: we pull the image we just built
1321
+ rc , err := cli .ImagePull (ctx , ref .String (), image.PullOptions {})
1322
+ require .NoError (t , err )
1323
+ t .Cleanup (func () { _ = rc .Close () })
1324
+ _ , err = io .ReadAll (rc )
1325
+ require .NoError (t , err )
1326
+
1327
+ // When: we run the image we just built
1328
+ ctr , err := cli .ContainerCreate (ctx , & container.Config {
1329
+ Image : ref .String (),
1330
+ Entrypoint : []string {"sleep" , "infinity" },
1331
+ Labels : map [string ]string {
1332
+ testContainerLabel : "true" ,
1333
+ },
1334
+ }, nil , nil , nil , "" )
1335
+ require .NoError (t , err )
1336
+ t .Cleanup (func () {
1337
+ _ = cli .ContainerRemove (ctx , ctr .ID , container.RemoveOptions {
1338
+ RemoveVolumes : true ,
1339
+ Force : true ,
1340
+ })
1341
+ })
1342
+ err = cli .ContainerStart (ctx , ctr .ID , container.StartOptions {})
1343
+ require .NoError (t , err )
1344
+
1345
+ // Then: the envbuilder binary exists in the image!
1346
+ out := execContainer (t , ctr .ID , "/.envbuilder/bin/envbuilder --help" )
1347
+ require .Regexp (t , `(?s)^USAGE:\s+envbuilder` , strings .TrimSpace (out ))
1348
+ require .NotEmpty (t , strings .TrimSpace (out ))
1349
+ })
1350
+
1246
1351
t .Run ("CacheAndPushAuth" , func (t * testing.T ) {
1247
1352
t .Parallel ()
1248
1353
1249
- srv := createGitServer (t , gitServerOptions {
1250
- files : map [string ]string {
1354
+ srv := gittest . CreateGitServer (t , gittest. Options {
1355
+ Files : map [string ]string {
1251
1356
".devcontainer/Dockerfile" : fmt .Sprintf (`FROM %s
1252
1357
USER root
1253
1358
ARG WORKDIR=/
@@ -1323,8 +1428,8 @@ RUN date --utc > /root/date.txt`, testImageAlpine),
1323
1428
t .Run ("CacheAndPushAuthFail" , func (t * testing.T ) {
1324
1429
t .Parallel ()
1325
1430
1326
- srv := createGitServer (t , gitServerOptions {
1327
- files : map [string ]string {
1431
+ srv := gittest . CreateGitServer (t , gittest. Options {
1432
+ Files : map [string ]string {
1328
1433
".devcontainer/Dockerfile" : fmt .Sprintf (`FROM %s
1329
1434
USER root
1330
1435
ARG WORKDIR=/
@@ -1390,8 +1495,8 @@ RUN date --utc > /root/date.txt`, testImageAlpine),
1390
1495
t .Skip ("TODO: https://github.com/coder/envbuilder/issues/230" )
1391
1496
t .Parallel ()
1392
1497
1393
- srv := createGitServer (t , gitServerOptions {
1394
- files : map [string ]string {
1498
+ srv := gittest . CreateGitServer (t , gittest. Options {
1499
+ Files : map [string ]string {
1395
1500
"Dockerfile" : fmt .Sprintf (`FROM %s AS a
1396
1501
RUN date --utc > /root/date.txt
1397
1502
FROM %s as b
@@ -1448,8 +1553,8 @@ COPY --from=a /root/date.txt /date.txt`, testImageAlpine, testImageAlpine),
1448
1553
t .Run ("PushImageRequiresCache" , func (t * testing.T ) {
1449
1554
t .Parallel ()
1450
1555
1451
- srv := createGitServer (t , gitServerOptions {
1452
- files : map [string ]string {
1556
+ srv := gittest . CreateGitServer (t , gittest. Options {
1557
+ Files : map [string ]string {
1453
1558
".devcontainer/Dockerfile" : fmt .Sprintf (`FROM %s
1454
1559
USER root
1455
1560
ARG WORKDIR=/
@@ -1480,8 +1585,8 @@ RUN date --utc > /root/date.txt`, testImageAlpine),
1480
1585
t .Run ("PushErr" , func (t * testing.T ) {
1481
1586
t .Parallel ()
1482
1587
1483
- srv := createGitServer (t , gitServerOptions {
1484
- files : map [string ]string {
1588
+ srv := gittest . CreateGitServer (t , gittest. Options {
1589
+ Files : map [string ]string {
1485
1590
".devcontainer/Dockerfile" : fmt .Sprintf (`FROM %s
1486
1591
USER root
1487
1592
ARG WORKDIR=/
@@ -1518,8 +1623,8 @@ func TestChownHomedir(t *testing.T) {
1518
1623
t .Parallel ()
1519
1624
1520
1625
// Ensures that a Git repository with a devcontainer.json is cloned and built.
1521
- srv := createGitServer (t , gitServerOptions {
1522
- files : map [string ]string {
1626
+ srv := gittest . CreateGitServer (t , gittest. Options {
1627
+ Files : map [string ]string {
1523
1628
".devcontainer/devcontainer.json" : `{
1524
1629
"name": "Test",
1525
1630
"build": {
@@ -1591,33 +1696,6 @@ func TestMain(m *testing.M) {
1591
1696
m .Run ()
1592
1697
}
1593
1698
1594
- type gitServerOptions struct {
1595
- files map [string ]string
1596
- username string
1597
- password string
1598
- authMW func (http.Handler ) http.Handler
1599
- tls bool
1600
- }
1601
-
1602
- // createGitServer creates a git repository with an in-memory filesystem
1603
- // and serves it over HTTP using a httptest.Server.
1604
- func createGitServer (t * testing.T , opts gitServerOptions ) * httptest.Server {
1605
- t .Helper ()
1606
- if opts .authMW == nil {
1607
- opts .authMW = mwtest .BasicAuthMW (opts .username , opts .password )
1608
- }
1609
- commits := make ([]gittest.CommitFunc , 0 )
1610
- for path , content := range opts .files {
1611
- commits = append (commits , gittest .Commit (t , path , content , "my test commit" ))
1612
- }
1613
- fs := memfs .New ()
1614
- _ = gittest .NewRepo (t , fs , commits ... )
1615
- if opts .tls {
1616
- return httptest .NewTLSServer (opts .authMW (gittest .NewServer (fs )))
1617
- }
1618
- return httptest .NewServer (opts .authMW (gittest .NewServer (fs )))
1619
- }
1620
-
1621
1699
func checkTestRegistry () {
1622
1700
resp , err := http .Get ("http://localhost:5000/v2/_catalog" )
1623
1701
if err != nil {
0 commit comments