MCPcopy
hub / github.com/containerd/containerd / TestGetCommonDirectory

Function TestGetCommonDirectory

core/mount/mount_linux_test.go:623–699  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

621}
622
623func TestGetCommonDirectory(t *testing.T) {
624 testCases := []struct {
625 name string
626 lowerDirs []string
627 expected string
628 expectError bool
629 errorMsg string
630 }{
631 {
632 name: "no lowerdirs",
633 lowerDirs: []string{},
634 expectError: true,
635 errorMsg: "no common prefix found",
636 },
637 {
638 name: "normal snapshots",
639 lowerDirs: []string{
640 "/mnt/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/37712/fs",
641 "/mnt/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/16590/fs",
642 "/mnt/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/16585/fs",
643 },
644 expected: "/mnt/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots",
645 },
646 {
647 name: "no common prefix at all",
648 lowerDirs: []string{
649 "/completely/different/path/1",
650 "/totally/unrelated/path/2",
651 },
652 expectError: true,
653 errorMsg: "invalid common directory:",
654 },
655 {
656 name: "single dir",
657 lowerDirs: []string{
658 "/mnt/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/16585/fs",
659 },
660 expected: "/mnt/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/16585",
661 },
662 {
663 name: "snapshots with common prefix in snapshot id",
664 lowerDirs: []string{
665 "/mnt/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/79/fs",
666 "/mnt/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/78/fs",
667 "/mnt/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/77/fs",
668 "/mnt/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/76/fs",
669 "/mnt/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/75/fs",
670 "/mnt/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots/73/fs",
671 },
672 expected: "/mnt/containerd/io.containerd.snapshotter.v1.overlayfs/snapshots",
673 },
674 }
675
676 for _, tc := range testCases {
677 t.Run(tc.name, func(t *testing.T) {
678 result, err := getCommonDirectory(tc.lowerDirs)
679
680 if tc.expectError {

Callers

nothing calls this directly

Calls 3

getCommonDirectoryFunction · 0.85
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…