MCPcopy
hub / github.com/containerd/containerd / testUsage

Function testUsage

plugins/snapshots/devmapper/snapshotter_test.go:72–110  ·  view source on GitHub ↗

testUsage tests devmapper's Usage implementation. This is an approximate test as it's hard to predict how many blocks will be consumed under different conditions and parameters.

(t *testing.T, snapshotter snapshots.Snapshotter)

Source from the content-addressed store, hash-verified

70// testUsage tests devmapper's Usage implementation. This is an approximate test as it's hard to
71// predict how many blocks will be consumed under different conditions and parameters.
72func testUsage(t *testing.T, snapshotter snapshots.Snapshotter) {
73 ctx := context.Background()
74
75 // Create empty base layer
76 _, err := snapshotter.Prepare(ctx, "prepare-1", "")
77 assert.NoError(t, err)
78
79 emptyLayerUsage, err := snapshotter.Usage(ctx, "prepare-1")
80 assert.NoError(t, err)
81
82 // Should be > 0 as just written file system also consumes blocks
83 assert.Greater(t, emptyLayerUsage.Size, int64(0))
84
85 err = snapshotter.Commit(ctx, "layer-1", "prepare-1")
86 assert.NoError(t, err)
87
88 // Create child layer with 1MB file
89
90 var (
91 sizeBytes int64 = 1048576 // 1MB
92 baseApplier = fstest.Apply(fstest.CreateRandomFile("/a", 12345679, sizeBytes, 0777))
93 )
94
95 mounts, err := snapshotter.Prepare(ctx, "prepare-2", "layer-1")
96 assert.NoError(t, err)
97
98 err = mount.WithTempMount(ctx, mounts, baseApplier.Apply)
99 assert.NoError(t, err)
100
101 err = snapshotter.Commit(ctx, "layer-2", "prepare-2")
102 assert.NoError(t, err)
103
104 layer2Usage, err := snapshotter.Usage(ctx, "layer-2")
105 assert.NoError(t, err)
106
107 // Should be at least 1 MB + fs metadata
108 assert.GreaterOrEqual(t, layer2Usage.Size, sizeBytes,
109 "%d > %d", layer2Usage.Size, sizeBytes)
110}
111
112func TestMkfsExt4(t *testing.T) {
113 ctx := context.Background()

Callers 1

TestSnapshotterSuiteFunction · 0.85

Calls 5

WithTempMountFunction · 0.92
PrepareMethod · 0.65
UsageMethod · 0.65
CommitMethod · 0.65
ApplyMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…