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

     1  package filesystem
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  // parseOwnershipIdentifierTestCase represents a test case for
     8  // ParseOwnershipIdentifier.
     9  type parseOwnershipIdentifierTestCase struct {
    10  	// specification is the ownership specification.
    11  	specification string
    12  	// expectedKind is the expected OwnershipIdentifierKind.
    13  	expectedKind OwnershipIdentifierKind
    14  	// expectedValue is the expected ownership specification value.
    15  	expectedValue string
    16  }
    17  
    18  // run executes the test in the provided test context.
    19  func (c *parseOwnershipIdentifierTestCase) run(t *testing.T) {
    20  	// Mark ourselves as a helper function.
    21  	t.Helper()
    22  
    23  	// Perform the parsing.
    24  	kind, value := ParseOwnershipIdentifier(c.specification)
    25  
    26  	// Check results.
    27  	if kind != c.expectedKind {
    28  		t.Error("parsed kind does not match expected:", kind, "!=", c.expectedKind)
    29  	}
    30  	if value != c.expectedValue {
    31  		t.Error("parsed value does not match expected:", value, "!=", c.expectedValue)
    32  	}
    33  }
    34  
    35  // TestParseOwnershipIdentifierEmpty tests that parsing of an empty ownership
    36  // specification fails.
    37  func TestParseOwnershipIdentifierEmpty(t *testing.T) {
    38  	// Create the test case.
    39  	testCase := &parseOwnershipIdentifierTestCase{
    40  		specification: "",
    41  		expectedKind:  OwnershipIdentifierKindInvalid,
    42  		expectedValue: "",
    43  	}
    44  
    45  	// Run the test case.
    46  	testCase.run(t)
    47  }
    48  
    49  // TestParseOwnershipIdentifierPOSIXIDEmpty tests that parsing of an empty POSIX
    50  // ID specification fails.
    51  func TestParseOwnershipIdentifierPOSIXIDEmpty(t *testing.T) {
    52  	// Create the test case.
    53  	testCase := &parseOwnershipIdentifierTestCase{
    54  		specification: "id:",
    55  		expectedKind:  OwnershipIdentifierKindInvalid,
    56  		expectedValue: "",
    57  	}
    58  
    59  	// Run the test case.
    60  	testCase.run(t)
    61  }
    62  
    63  // TestParseOwnershipIdentifierPOSIXIDOctal tests that parsing of an octal POSIX
    64  // ID specification fails.
    65  func TestParseOwnershipIdentifierPOSIXIDOctal(t *testing.T) {
    66  	// Create the test case.
    67  	testCase := &parseOwnershipIdentifierTestCase{
    68  		specification: "id:0442",
    69  		expectedKind:  OwnershipIdentifierKindInvalid,
    70  		expectedValue: "",
    71  	}
    72  
    73  	// Run the test case.
    74  	testCase.run(t)
    75  }
    76  
    77  // TestParseOwnershipIdentifierPOSIXIDAlphaNumeric tests that parsing of an
    78  // alphanumeric POSIX ID specification fails.
    79  func TestParseOwnershipIdentifierPOSIXIDAlphaNumeric(t *testing.T) {
    80  	// Create the test case.
    81  	testCase := &parseOwnershipIdentifierTestCase{
    82  		specification: "id:5a42",
    83  		expectedKind:  OwnershipIdentifierKindInvalid,
    84  		expectedValue: "",
    85  	}
    86  
    87  	// Run the test case.
    88  	testCase.run(t)
    89  }
    90  
    91  // TestParseOwnershipIdentifierPOSIXIDRoot tests that parsing of a root POSIX ID
    92  // specification succeeds.
    93  func TestParseOwnershipIdentifierPOSIXIDRoot(t *testing.T) {
    94  	// Create the test case.
    95  	testCase := &parseOwnershipIdentifierTestCase{
    96  		specification: "id:0",
    97  		expectedKind:  OwnershipIdentifierKindPOSIXID,
    98  		expectedValue: "0",
    99  	}
   100  
   101  	// Run the test case.
   102  	testCase.run(t)
   103  }
   104  
   105  // TestParseOwnershipIdentifierPOSIXIDSingleDigit tests that parsing of a
   106  // single-digit POSIX ID specification succeeds.
   107  func TestParseOwnershipIdentifierPOSIXIDSingleDigit(t *testing.T) {
   108  	// Create the test case.
   109  	testCase := &parseOwnershipIdentifierTestCase{
   110  		specification: "id:4",
   111  		expectedKind:  OwnershipIdentifierKindPOSIXID,
   112  		expectedValue: "4",
   113  	}
   114  
   115  	// Run the test case.
   116  	testCase.run(t)
   117  }
   118  
   119  // TestParseOwnershipIdentifierPOSIXIDMultiDigit tests that parsing of a
   120  // multi-digit POSIX ID specification succeeds.
   121  func TestParseOwnershipIdentifierPOSIXIDMultiDigit(t *testing.T) {
   122  	// Create the test case.
   123  	testCase := &parseOwnershipIdentifierTestCase{
   124  		specification: "id:454",
   125  		expectedKind:  OwnershipIdentifierKindPOSIXID,
   126  		expectedValue: "454",
   127  	}
   128  
   129  	// Run the test case.
   130  	testCase.run(t)
   131  }
   132  
   133  // TestParseOwnershipIdentifierWindowsSIDEmpty tests that parsing of an empty
   134  // Windows SID specification fails.
   135  func TestParseOwnershipIdentifierWindowsSIDEmpty(t *testing.T) {
   136  	// Create the test case.
   137  	testCase := &parseOwnershipIdentifierTestCase{
   138  		specification: "sid:",
   139  		expectedKind:  OwnershipIdentifierKindInvalid,
   140  		expectedValue: "",
   141  	}
   142  
   143  	// Run the test case.
   144  	testCase.run(t)
   145  }
   146  
   147  // TestParseOwnershipIdentifierWindowsSIDStringConstant tests that parsing of a
   148  // string-constant-based Windows SID specification succeeds.
   149  func TestParseOwnershipIdentifierWindowsSIDStringConstant(t *testing.T) {
   150  	// Create the test case.
   151  	testCase := &parseOwnershipIdentifierTestCase{
   152  		specification: "sid:BA",
   153  		expectedKind:  OwnershipIdentifierKindWindowsSID,
   154  		expectedValue: "BA",
   155  	}
   156  
   157  	// Run the test case.
   158  	testCase.run(t)
   159  }
   160  
   161  // TestParseOwnershipIdentifierWindowsSIDWellKnown tests that parsing of a
   162  // well-known Windows SID specification succeeds.
   163  func TestParseOwnershipIdentifierWindowsSIDWellKnown(t *testing.T) {
   164  	// Create the test case.
   165  	testCase := &parseOwnershipIdentifierTestCase{
   166  		specification: "sid:S-1-3-0",
   167  		expectedKind:  OwnershipIdentifierKindWindowsSID,
   168  		expectedValue: "S-1-3-0",
   169  	}
   170  
   171  	// Run the test case.
   172  	testCase.run(t)
   173  }
   174  
   175  // TestParseOwnershipIdentifierName tests that parsing of a name specification
   176  // succeeds.
   177  func TestParseOwnershipIdentifierName(t *testing.T) {
   178  	// Create the test case.
   179  	testCase := &parseOwnershipIdentifierTestCase{
   180  		specification: "george",
   181  		expectedKind:  OwnershipIdentifierKindName,
   182  		expectedValue: "george",
   183  	}
   184  
   185  	// Run the test case.
   186  	testCase.run(t)
   187  }