-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
storage: add smoking test for chunk dedup
Add smoking test case for chunk dedup. Signed-off-by: Jiang Liu <[email protected]>
- Loading branch information
Showing
4 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.ChunkDedupDb = 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}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters