forked from containerd/containerd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testcases added for to test Stat() Interface.
Two test cases added - Prepare, Stat on new layer, should return Active layer. - Prepare & Commit , Stat on new layer, should return Committed layer Signed-off-by: Kunal Kushwaha <kushwaha_kunal_v7@lab.ntt.co.jp>
- Loading branch information
1 parent
be20bb1
commit d9dd68e
Showing
2 changed files
with
91 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
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,89 @@ | ||
package snapshot | ||
|
||
import ( | ||
"context" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/docker/containerd" | ||
"github.com/docker/containerd/testutil" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// Create a New Layer on top of base layer with Prepare, Stat on new layer, should return Active layer. | ||
func checkSnapshotterStatActive(t *testing.T, snapshotter Snapshotter, work string) { | ||
ctx := context.TODO() | ||
preparing := filepath.Join(work, "preparing") | ||
if err := os.MkdirAll(preparing, 0777); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
mounts, err := snapshotter.Prepare(ctx, preparing, "") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if len(mounts) < 1 { | ||
t.Fatal("expected mounts to have entries") | ||
} | ||
|
||
if err = containerd.MountAll(mounts, preparing); err != nil { | ||
t.Fatal(err) | ||
} | ||
defer testutil.Unmount(t, preparing) | ||
|
||
if err = ioutil.WriteFile(filepath.Join(preparing, "foo"), []byte("foo\n"), 0777); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
si, err := snapshotter.Stat(ctx, preparing) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
assert.Equal(t, si.Name, preparing) | ||
assert.Equal(t, KindActive, si.Kind) | ||
assert.Equal(t, "", si.Parent) | ||
} | ||
|
||
// Commit a New Layer on top of base layer with Prepare & Commit , Stat on new layer, should return Committed layer. | ||
func checkSnapshotterStatCommitted(t *testing.T, snapshotter Snapshotter, work string) { | ||
ctx := context.TODO() | ||
preparing := filepath.Join(work, "preparing") | ||
if err := os.MkdirAll(preparing, 0777); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
mounts, err := snapshotter.Prepare(ctx, preparing, "") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if len(mounts) < 1 { | ||
t.Fatal("expected mounts to have entries") | ||
} | ||
|
||
if err = containerd.MountAll(mounts, preparing); err != nil { | ||
t.Fatal(err) | ||
} | ||
defer testutil.Unmount(t, preparing) | ||
|
||
if err = ioutil.WriteFile(filepath.Join(preparing, "foo"), []byte("foo\n"), 0777); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
committed := filepath.Join(work, "committed") | ||
if err = snapshotter.Commit(ctx, committed, preparing); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
si, err := snapshotter.Stat(ctx, committed) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
assert.Equal(t, si.Name, committed) | ||
assert.Equal(t, KindCommitted, si.Kind) | ||
assert.Equal(t, "", si.Parent) | ||
|
||
} |