diff --git a/smoke/tests/chunk_dedup.go b/smoke/tests/chunk_dedup.go new file mode 100644 index 00000000000..208621d9002 --- /dev/null +++ b/smoke/tests/chunk_dedup.go @@ -0,0 +1,75 @@ +// Copyright 2023 Nydus Developers. All rights reserved. +// +// SPDX-License-Identifier: Apache-2.0 + +package tests + +import ( + "path/filepath" + "testing" + + "github.com/containerd/nydus-snapshotter/pkg/converter" + "github.com/dragonflyoss/image-service/smoke/tests/texture" + "github.com/dragonflyoss/image-service/smoke/tests/tool" + "github.com/dragonflyoss/image-service/smoke/tests/tool/test" + "github.com/opencontainers/go-digest" + "github.com/stretchr/testify/require" +) + +const ( + paramIteration = "iteration" +) + +type ChunkDedupTestSuite struct { + t *testing.T +} + +func (z *ChunkDedupTestSuite) TestChunkDedup() test.Generator { + + scenarios := tool.DescartesIterator{} + scenarios.Dimension(paramIteration, []interface{}{1, 2}) + + return func() (name string, testCase test.Case) { + if !scenarios.HasNext() { + return + } + scenario := scenarios.Next() + + ctx := tool.DefaultContext(z.t) + ctx.Runtime.ChunkDedupDbFile = ctx.Env.WorkDir + "/cas.db" + + return scenario.Str(), func(t *testing.T) { + z.testMakeLayers(*ctx, t) + } + } +} + +func (z *ChunkDedupTestSuite) testMakeLayers(ctx tool.Context, t *testing.T) { + + // Prepare work directory + ctx.PrepareWorkDir(t) + defer ctx.Destroy(t) + + lowerLayer := texture.MakeLowerLayer(t, filepath.Join(ctx.Env.WorkDir, "source")) + lowerOCIBlobDigest, lowerRafsBlobDigest := lowerLayer.PackRef(t, ctx, ctx.Env.BlobDir, ctx.Build.OCIRefGzip) + mergeOption := converter.MergeOption{ + BuilderPath: ctx.Binary.Builder, + ChunkDictPath: "", + OCIRef: true, + } + actualDigests, lowerBootstrap := tool.MergeLayers(t, ctx, mergeOption, []converter.Layer{ + { + Digest: lowerRafsBlobDigest, + OriginalDigest: &lowerOCIBlobDigest, + }, + }) + require.Equal(t, []digest.Digest{lowerOCIBlobDigest}, actualDigests) + + // Verify lower layer mounted by nydusd + ctx.Env.BootstrapPath = lowerBootstrap + tool.Verify(t, ctx, lowerLayer.FileTree) +} + +func TestChunkDedup(t *testing.T) { + test.Run(t, &ChunkDedupTestSuite{t: t}) +} diff --git a/smoke/tests/tool/context.go b/smoke/tests/tool/context.go index 7d409d3b996..7673232693e 100644 --- a/smoke/tests/tool/context.go +++ b/smoke/tests/tool/context.go @@ -39,6 +39,7 @@ type RuntimeContext struct { RafsMode string EnablePrefetch bool AmplifyIO uint64 + ChunkDedupDb string } type EnvContext struct { diff --git a/smoke/tests/tool/nydusd.go b/smoke/tests/tool/nydusd.go index a56b85aeeb0..b73bb83f628 100644 --- a/smoke/tests/tool/nydusd.go +++ b/smoke/tests/tool/nydusd.go @@ -69,6 +69,7 @@ type NydusdConfig struct { AccessPattern bool PrefetchFiles []string AmplifyIO uint64 + ChunkDedupDb string } type Nydusd struct { @@ -205,6 +206,9 @@ func (nydusd *Nydusd) Mount() error { if len(nydusd.BootstrapPath) > 0 { args = append(args, "--bootstrap", nydusd.BootstrapPath) } + if len(nydusd.ChunkDedupDb) > 0 { + args = append(args, "--dedup", nydusd.ChunkDedupDb) + } cmd := exec.Command(nydusd.NydusdPath, args...) cmd.Stdout = os.Stdout diff --git a/smoke/tests/tool/verify.go b/smoke/tests/tool/verify.go index d2d4ad277d2..55104aa26b5 100644 --- a/smoke/tests/tool/verify.go +++ b/smoke/tests/tool/verify.go @@ -30,6 +30,7 @@ func Verify(t *testing.T, ctx Context, expectedFiles map[string]*File) { RafsMode: ctx.Runtime.RafsMode, DigestValidate: false, AmplifyIO: ctx.Runtime.AmplifyIO, + ChunkDedupDb: ctx.Runtime.ChunkDedupDb, } nydusd, err := NewNydusd(config)