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

     1  package synchronization
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  // TestScanModeUnmarshal tests that unmarshaling from a string specification
     8  // succeeeds for ScanMode.
     9  func TestScanModeUnmarshal(t *testing.T) {
    10  	// Set up test cases.
    11  	testCases := []struct {
    12  		text          string
    13  		expectedMode  ScanMode
    14  		expectFailure bool
    15  	}{
    16  		{"", ScanMode_ScanModeDefault, true},
    17  		{"asdf", ScanMode_ScanModeDefault, true},
    18  		{"full", ScanMode_ScanModeFull, false},
    19  		{"accelerated", ScanMode_ScanModeAccelerated, false},
    20  	}
    21  
    22  	// Process test cases.
    23  	for _, testCase := range testCases {
    24  		var mode ScanMode
    25  		if err := mode.UnmarshalText([]byte(testCase.text)); err != nil {
    26  			if !testCase.expectFailure {
    27  				t.Errorf("unable to unmarshal text (%s): %s", testCase.text, err)
    28  			}
    29  		} else if testCase.expectFailure {
    30  			t.Error("unmarshaling succeeded unexpectedly for text:", testCase.text)
    31  		} else if mode != testCase.expectedMode {
    32  			t.Errorf(
    33  				"unmarshaled mode (%s) does not match expected (%s)",
    34  				mode,
    35  				testCase.expectedMode,
    36  			)
    37  		}
    38  	}
    39  }
    40  
    41  // TestScanModeSupported tests that ScanMode support detection works as
    42  // expected.
    43  func TestScanModeSupported(t *testing.T) {
    44  	// Set up test cases.
    45  	testCases := []struct {
    46  		mode            ScanMode
    47  		expectSupported bool
    48  	}{
    49  		{ScanMode_ScanModeDefault, false},
    50  		{ScanMode_ScanModeFull, true},
    51  		{ScanMode_ScanModeAccelerated, true},
    52  		{(ScanMode_ScanModeAccelerated + 1), false},
    53  	}
    54  
    55  	// Process test cases.
    56  	for _, testCase := range testCases {
    57  		if supported := testCase.mode.Supported(); supported != testCase.expectSupported {
    58  			t.Errorf(
    59  				"mode support status (%t) does not match expected (%t)",
    60  				supported,
    61  				testCase.expectSupported,
    62  			)
    63  		}
    64  	}
    65  }
    66  
    67  // TestScanModeDescription tests that ScanMode description generation works as
    68  // expected.
    69  func TestScanModeDescription(t *testing.T) {
    70  	// Set up test cases.
    71  	testCases := []struct {
    72  		mode                ScanMode
    73  		expectedDescription string
    74  	}{
    75  		{ScanMode_ScanModeDefault, "Default"},
    76  		{ScanMode_ScanModeFull, "Full"},
    77  		{ScanMode_ScanModeAccelerated, "Accelerated"},
    78  		{(ScanMode_ScanModeAccelerated + 1), "Unknown"},
    79  	}
    80  
    81  	// Process test cases.
    82  	for _, testCase := range testCases {
    83  		if description := testCase.mode.Description(); description != testCase.expectedDescription {
    84  			t.Errorf(
    85  				"mode description (%s) does not match expected (%s)",
    86  				description,
    87  				testCase.expectedDescription,
    88  			)
    89  		}
    90  	}
    91  }