github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/filesystem/mode_posix_test.go (about)

     1  //go:build !windows
     2  
     3  package filesystem
     4  
     5  import (
     6  	"testing"
     7  
     8  	"golang.org/x/sys/unix"
     9  )
    10  
    11  // TestPermissionModesMatchExpected verifies that the cross-platform permission
    12  // modes we define match their expected value on each platform. This should be
    13  // guaranteed by a combination of POSIX specifications (on POSIX systems) and
    14  // the Go os package implementation (on Windows).
    15  func TestModePermissionsMaskMatchesOS(t *testing.T) {
    16  	// Verify ModePermissionsMask.
    17  	if ModePermissionsMask != Mode(unix.S_IRWXU|unix.S_IRWXG|unix.S_IRWXO) {
    18  		t.Error("ModePermissionsMask does not match expected value")
    19  	}
    20  
    21  	// Verify ModePermissionUserRead.
    22  	if ModePermissionUserRead != Mode(unix.S_IRUSR) {
    23  		t.Error("ModePermissionUserRead does not match expected")
    24  	}
    25  
    26  	// Verify ModePermissionUserWrite.
    27  	if ModePermissionUserWrite != Mode(unix.S_IWUSR) {
    28  		t.Error("ModePermissionUserWrite does not match expected")
    29  	}
    30  
    31  	// Verify ModePermissionUserExecute.
    32  	if ModePermissionUserExecute != Mode(unix.S_IXUSR) {
    33  		t.Error("ModePermissionUserExecute does not match expected")
    34  	}
    35  
    36  	// Verify ModePermissionGroupRead.
    37  	if ModePermissionGroupRead != Mode(unix.S_IRGRP) {
    38  		t.Error("ModePermissionGroupRead does not match expected")
    39  	}
    40  
    41  	// Verify ModePermissionGroupWrite.
    42  	if ModePermissionGroupWrite != Mode(unix.S_IWGRP) {
    43  		t.Error("ModePermissionGroupWrite does not match expected")
    44  	}
    45  
    46  	// Verify ModePermissionGroupExecute.
    47  	if ModePermissionGroupExecute != Mode(unix.S_IXGRP) {
    48  		t.Error("ModePermissionGroupExecute does not match expected")
    49  	}
    50  
    51  	// Verify ModePermissionOthersRead.
    52  	if ModePermissionOthersRead != Mode(unix.S_IROTH) {
    53  		t.Error("ModePermissionOthersRead does not match expected")
    54  	}
    55  
    56  	// Verify ModePermissionOthersWrite.
    57  	if ModePermissionOthersWrite != Mode(unix.S_IWOTH) {
    58  		t.Error("ModePermissionOthersWrite does not match expected")
    59  	}
    60  
    61  	// Verify ModePermissionOthersExecute.
    62  	if ModePermissionOthersExecute != Mode(unix.S_IXOTH) {
    63  		t.Error("ModePermissionOthersExecute does not match expected")
    64  	}
    65  }