Skip to content

Commit aabb12b

Browse files
committed
test now passes
1 parent 2a473d1 commit aabb12b

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

GNUmakefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,29 @@ terraform-provider-envbuilder: internal/provider/*.go main.go
2222
update-envbuilder-version:
2323
go get github.com/coder/envbuilder@main
2424
go mod tidy
25+
26+
# Starts a local Docker registry on port 5000 with a local disk cache.
27+
.PHONY: test-registry
28+
test-registry: test-registry-container test-images-pull test-images-push
29+
30+
.PHONY: test-registry-container
31+
test-registry-container: .registry-cache
32+
if ! curl -fsSL http://localhost:5000/v2/_catalog > /dev/null 2>&1; then \
33+
docker rm -f tfprov-envbuilder-registry && \
34+
docker run -d -p 5000:5000 --name envbuilder-registry --volume $(PWD)/.registry-cache:/var/lib/registry registry:2; \
35+
fi
36+
37+
# Pulls images referenced in integration tests and pushes them to the local cache.
38+
.PHONY: test-images-push
39+
test-images-push: .registry-cache/docker/registry/v2/repositories/test-ubuntu
40+
41+
.PHONY: test-images-pull
42+
test-images-pull:
43+
docker pull ubuntu:latest
44+
docker tag ubuntu:latest localhost:5000/test-ubuntu:latest
45+
46+
.registry-cache:
47+
mkdir -p .registry-cache && chmod -R ag+w .registry-cache
48+
49+
.registry-cache/docker/registry/v2/repositories/test-ubuntu:
50+
docker push localhost:5000/test-ubuntu:latest

internal/provider/cached_image_data_source_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestAccCachedImageDataSource(t *testing.T) {
1818
t.Cleanup(cancel)
1919
files := map[string]string{
2020
"devcontainer.json": `{"build": { "dockerfile": "Dockerfile" }}`,
21-
"Dockerfile": `FROM ubuntu:latest
21+
"Dockerfile": `FROM localhost:5000/test-ubuntu:latest
2222
RUN apt-get update && apt-get install -y cowsay`,
2323
}
2424
deps := setup(ctx, t, files)
@@ -52,8 +52,10 @@ func TestAccCachedImageDataSource(t *testing.T) {
5252
resource.TestCheckResourceAttr("data.envbuilder_cached_image.test", "exists", "true"),
5353
resource.TestCheckResourceAttrSet("data.envbuilder_cached_image.test", "image"),
5454
resource.TestCheckResourceAttrWith("data.envbuilder_cached_image.test", "image", func(value string) error {
55+
// value is enclosed in quotes
56+
value = strings.Trim(value, `"`)
5557
if !strings.HasPrefix(value, deps.CacheRepo) {
56-
return fmt.Errorf("expected prefix %q", deps.CacheRepo)
58+
return fmt.Errorf("expected image %q to have prefix %q", value, deps.CacheRepo)
5759
}
5860
return nil
5961
}),

internal/provider/provider_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ func setup(ctx context.Context, t testing.TB, files map[string]string) testDepen
8383
"ENVBUILDER_DEVCONTAINER_DIR=" + repoDir,
8484
"ENVBUILDER_EXIT_ON_BUILD_FAILURE=true",
8585
"ENVBUILDER_INIT_SCRIPT=exit",
86-
"ENVBUILDER_PUSH_IMAGE=true",
86+
// FIXME: Enabling this options causes envbuilder to add its binary to the image under the path
87+
// /.envbuilder/bin/envbuilder. This file will have ownership root:root and permissions 0o755.
88+
// Because of this, t.Cleanup() will be unable to delete the temp dir, causing the test to fail.
89+
// "ENVBUILDER_PUSH_IMAGE=true",
8790
},
8891
Labels: map[string]string{
8992
testContainerLabel: "true",

0 commit comments

Comments
 (0)