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