...

Source file src/github.com/containerd/continuity/fs/dtype_linux_test.go

Documentation: github.com/containerd/continuity/fs

     1  //go:build linux
     2  // +build linux
     3  
     4  /*
     5     Copyright The containerd Authors.
     6  
     7     Licensed under the Apache License, Version 2.0 (the "License");
     8     you may not use this file except in compliance with the License.
     9     You may obtain a copy of the License at
    10  
    11         http://www.apache.org/licenses/LICENSE-2.0
    12  
    13     Unless required by applicable law or agreed to in writing, software
    14     distributed under the License is distributed on an "AS IS" BASIS,
    15     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16     See the License for the specific language governing permissions and
    17     limitations under the License.
    18  */
    19  
    20  package fs
    21  
    22  import (
    23  	"os/exec"
    24  	"testing"
    25  
    26  	"github.com/containerd/continuity/testutil"
    27  	"github.com/containerd/continuity/testutil/loopback"
    28  )
    29  
    30  func testSupportsDType(t *testing.T, expected bool, mkfs ...string) {
    31  	testutil.RequiresRoot(t)
    32  	mnt := t.TempDir()
    33  
    34  	loop, err := loopback.New(100 << 20) // 100 MB
    35  	if err != nil {
    36  		t.Fatal(err)
    37  	}
    38  	if out, err := exec.Command(mkfs[0], append(mkfs[1:], loop.Device)...).CombinedOutput(); err != nil {
    39  		// not fatal
    40  		t.Skipf("could not mkfs (%v) %s: %v (out: %q)", mkfs, loop.Device, err, string(out))
    41  	}
    42  	if out, err := exec.Command("mount", loop.Device, mnt).CombinedOutput(); err != nil {
    43  		// not fatal
    44  		t.Skipf("could not mount %s: %v (out: %q)", loop.Device, err, string(out))
    45  	}
    46  	defer func() {
    47  		testutil.Unmount(t, mnt)
    48  		loop.Close()
    49  	}()
    50  	// check whether it supports d_type
    51  	result, err := SupportsDType(mnt)
    52  	if err != nil {
    53  		t.Fatal(err)
    54  	}
    55  	t.Logf("Supports d_type: %v", result)
    56  	if expected != result {
    57  		t.Fatalf("expected %+v, got: %+v", expected, result)
    58  	}
    59  }
    60  
    61  func TestSupportsDTypeWithFType0XFS(t *testing.T) {
    62  	testSupportsDType(t, false, "mkfs.xfs", "-m", "crc=0", "-n", "ftype=0")
    63  }
    64  
    65  func TestSupportsDTypeWithFType1XFS(t *testing.T) {
    66  	testSupportsDType(t, true, "mkfs.xfs", "-m", "crc=0", "-n", "ftype=1")
    67  }
    68  
    69  func TestSupportsDTypeWithExt4(t *testing.T) {
    70  	testSupportsDType(t, true, "mkfs.ext4", "-F")
    71  }
    72  

View as plain text