Skip to content

Commit

Permalink
chore: integration test of cache-export ignore-error
Browse files Browse the repository at this point in the history
Signed-off-by: JordanGoasdoue <jordan.goasdoue@dailymotion.com>
  • Loading branch information
JordanGoasdoue committed Dec 28, 2022
1 parent 991b863 commit e79d169
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 11 deletions.
127 changes: 127 additions & 0 deletions client/client_test.go
Expand Up @@ -168,6 +168,7 @@ func TestIntegration(t *testing.T) {
testBuildInfoInline,
testBuildInfoNoExport,
testZstdLocalCacheExport,
testCacheExportIgnoreError,
testZstdRegistryCacheImportExport,
testZstdLocalCacheImportExport,
testUncompressedLocalCacheImportExport,
Expand Down Expand Up @@ -4351,6 +4352,132 @@ func testZstdLocalCacheExport(t *testing.T, sb integration.Sandbox) {
require.Equal(t, dt[:4], []byte{0x28, 0xb5, 0x2f, 0xfd})
}

func testCacheExportIgnoreError(t *testing.T, sb integration.Sandbox) {
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport)
c, err := New(sb.Context(), sb.Address())
require.NoError(t, err)
defer c.Close()

busybox := llb.Image("busybox:latest")
cmd := `sh -e -c "echo -n ignore-error > data"`

st := llb.Scratch()
st = busybox.Run(llb.Shlex(cmd), llb.Dir("/wd")).AddMount("/wd", st)

def, err := st.Marshal(sb.Context())
require.NoError(t, err)

tests := map[string]struct {
ExportCacheType string
ExportType string
Attrs map[string]string
expectedError bool
}{
"local-ignore-error": {
ExportType: ExporterLocal,
ExportCacheType: "local",
Attrs: map[string]string{
"dest": "éèç",
"ignore-error": "true",
},
expectedError: false,
},
"local-no-ignore-error": {
ExportType: ExporterLocal,
ExportCacheType: "local",
Attrs: map[string]string{
"dest": "éèç",
"ignore-error": "false",
},
expectedError: true,
},
"registry-ignore-error": {
ExportType: ExporterImage,
ExportCacheType: "registry",
Attrs: map[string]string{
"ref": "http://fake-url:5000/myrepo:buildcache",
"ignore-error": "true",
},
expectedError: false,
},
"registry-no-ignore-error": {
ExportType: ExporterImage,
ExportCacheType: "registry",
Attrs: map[string]string{
"ref": "http://fake-url:5000/myrepo:buildcache",
"ignore-error": "false",
},
expectedError: true,
},
"s3-ignore-error": {
ExportType: ExporterLocal,
ExportCacheType: "s3",
Attrs: map[string]string{
"endpoint_url": "http://fake-url:9000",
"bucket": "my-bucket",
"region": "us-east-1",
"access_key_id": "minioadmin",
"secret_access_key": "minioadmin",
"use_path_style": "true",
"ignore-error": "true",
},
expectedError: false,
},
"s3-no-ignore-error": {
ExportType: ExporterLocal,
ExportCacheType: "s3",
Attrs: map[string]string{
"endpoint_url": "http://fake-url:9000",
"bucket": "my-bucket",
"region": "us-east-1",
"access_key_id": "minioadmin",
"secret_access_key": "minioadmin",
"use_path_style": "true",
"ignore-error": "false",
},
expectedError: true,
},
}
for testName, test := range tests {
t.Run(testName, func(t *testing.T) {
var exports []ExportEntry
switch test.ExportType {
case ExporterImage:
exports = []ExportEntry{
{
Type: test.ExportType,
Attrs: map[string]string{
"name": testName,
"push": "false",
},
},
}
default:
exports = []ExportEntry{
{
Type: test.ExportType,
OutputDir: t.TempDir(),
},
}
}
_, err = c.Solve(sb.Context(), def, SolveOpt{
Exports: exports,
CacheExports: []CacheOptionsEntry{
{
Type: test.ExportCacheType,
Attrs: test.Attrs,
},
},
}, nil)
if test.expectedError {
require.Error(t, err)
} else {
require.NoError(t, err)
}
})
}
}

func testUncompressedLocalCacheImportExport(t *testing.T, sb integration.Sandbox) {
integration.CheckFeatureCompat(t, sb, integration.FeatureCacheExport)
dir := t.TempDir()
Expand Down
12 changes: 1 addition & 11 deletions hack/s3_test/test.sh
Expand Up @@ -20,17 +20,7 @@ done

export default_options="type=s3,bucket=my-bucket,region=us-east-1,endpoint_url=http://127.0.0.1:9000,access_key_id=minioadmin,secret_access_key=minioadmin,use_path_style=true"

rm -rf /tmp/destdir0 /tmp/destdir1 /tmp/destdir2

# Check --export-cache with ignore-error=true and fake non reachable endpoint_url
# Should ignore error and skip the remote cache export
buildctl build \
--progress plain \
--frontend dockerfile.v0 \
--local context=/test/test1 \
--local dockerfile=/test/test1 \
--export-cache "$default_options,endpoint_url=http://fake-url:9000,ignore-error=true" \
--output type=local,dest=/tmp/destdir0
rm -rf /tmp/destdir1 /tmp/destdir2

# First build: no cache on s3
# 4 files should be exported (2 blobs + 2 manifests)
Expand Down

0 comments on commit e79d169

Please sign in to comment.