| 2945 | } |
| 2946 | |
| 2947 | func TestValidPath(t *testing.T) { |
| 2948 | type testcase struct { |
| 2949 | path string |
| 2950 | wantErr bool |
| 2951 | } |
| 2952 | |
| 2953 | tests := []testcase{ |
| 2954 | {".git", true}, |
| 2955 | {".git/b", true}, |
| 2956 | {".git\\b", true}, |
| 2957 | {"git~1", true}, |
| 2958 | {"a/../b", true}, |
| 2959 | {"a\\..\\b", true}, |
| 2960 | {"/", true}, |
| 2961 | {"", true}, |
| 2962 | {".gitmodules", false}, |
| 2963 | {".gitignore", false}, |
| 2964 | {"a..b", false}, |
| 2965 | {".", false}, |
| 2966 | {"a/.git", false}, |
| 2967 | {"a\\.git", false}, |
| 2968 | {"a/.git/b", false}, |
| 2969 | {"a\\.git\\b", false}, |
| 2970 | } |
| 2971 | |
| 2972 | if runtime.GOOS == "windows" { |
| 2973 | tests = append(tests, []testcase{ |
| 2974 | {"\\\\a\\b", true}, |
| 2975 | {"C:\\a\\b", true}, |
| 2976 | {".git . . .", true}, |
| 2977 | {".git . . ", true}, |
| 2978 | {".git ", true}, |
| 2979 | {".git.", true}, |
| 2980 | {".git::$INDEX_ALLOCATION", true}, |
| 2981 | }...) |
| 2982 | } |
| 2983 | |
| 2984 | for _, tc := range tests { |
| 2985 | t.Run(fmt.Sprintf("%s", tc.path), func(t *testing.T) { |
| 2986 | err := validPath(tc.path) |
| 2987 | if tc.wantErr { |
| 2988 | assert.Error(t, err) |
| 2989 | } else { |
| 2990 | assert.NoError(t, err) |
| 2991 | } |
| 2992 | }) |
| 2993 | } |
| 2994 | } |
| 2995 | |
| 2996 | func TestWindowsValidPath(t *testing.T) { |
| 2997 | tests := []struct { |