Skip to content

Commit fb2ce5c

Browse files
leodidoona-agent
andcommitted
fix(test): update dummyDocker mock to handle OCI layout export
Update the dummyDocker mock script to handle 'docker buildx build --output type=oci' commands by creating a minimal OCI layout tar file. This fixes the TestBuildDocker_ExportToCache test which was failing because the mock didn't support the new OCI layout export format introduced in PR #286. Co-authored-by: Ona <no-reply@ona.com>
1 parent 41e72e9 commit fb2ce5c

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

pkg/leeway/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const (
114114
var buildProcessVersions = map[PackageType]int{
115115
YarnPackage: 7,
116116
GoPackage: 2,
117-
DockerPackage: 4, // Bumped for OCI layout format change (PR #286)
117+
DockerPackage: 4,
118118
GenericPackage: 1,
119119
}
120120

pkg/leeway/build_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func boolPtr(b bool) *bool {
1818
const dummyDocker = `#!/bin/bash
1919
2020
POSITIONAL_ARGS=()
21+
OUTPUT=""
2122
2223
while [[ $# -gt 0 ]]; do
2324
case $1 in
@@ -26,6 +27,15 @@ while [[ $# -gt 0 ]]; do
2627
shift # past argument
2728
shift # past value
2829
;;
30+
--output)
31+
# Handle --output type=oci,dest=path
32+
OUTPUT_ARG="$2"
33+
if [[ "$OUTPUT_ARG" =~ dest=(.+) ]]; then
34+
OUTPUT="${BASH_REMATCH[1]}"
35+
fi
36+
shift # past argument
37+
shift # past value
38+
;;
2939
inspect)
3040
# Mock docker inspect to return a valid ID
3141
echo '[{"Id":"sha256:1234567890abcdef"}]'
@@ -40,9 +50,21 @@ done
4050
4151
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
4252
43-
if [ "${POSITIONAL_ARGS}" == "save" ]; then
53+
# Handle docker save
54+
if [[ " ${POSITIONAL_ARGS[@]} " =~ " save " ]]; then
4455
tar cvvfz "${OUTPUT}" -T /dev/null
4556
fi
57+
58+
# Handle docker buildx build --output type=oci
59+
if [[ " ${POSITIONAL_ARGS[@]} " =~ " buildx " ]] && [[ " ${POSITIONAL_ARGS[@]} " =~ " build " ]] && [[ -n "${OUTPUT}" ]]; then
60+
# Create a minimal OCI layout tar
61+
mkdir -p /tmp/oci-layout-$$
62+
echo '{"imageLayoutVersion": "1.0.0"}' > /tmp/oci-layout-$$/oci-layout
63+
echo '{"schemaVersion": 2, "manifests": []}' > /tmp/oci-layout-$$/index.json
64+
mkdir -p /tmp/oci-layout-$$/blobs/sha256
65+
tar -cf "${OUTPUT}" -C /tmp/oci-layout-$$ .
66+
rm -rf /tmp/oci-layout-$$
67+
fi
4668
`
4769

4870
// Create a mock for extractImageWithOCILibs to avoid dependency on actual Docker daemon

0 commit comments

Comments
 (0)