(t *testing.T, dotFS, altFS billy.Filesystem)
| 861 | } |
| 862 | |
| 863 | func testAlternates(t *testing.T, dotFS, altFS billy.Filesystem) { |
| 864 | tests := []struct { |
| 865 | name string |
| 866 | in []string |
| 867 | inWindows []string |
| 868 | setup func() |
| 869 | wantErr bool |
| 870 | wantRoots []string |
| 871 | }{ |
| 872 | { |
| 873 | name: "no alternates", |
| 874 | }, |
| 875 | { |
| 876 | name: "abs path", |
| 877 | in: []string{filepath.Join(altFS.Root(), "./repo1/.git/objects")}, |
| 878 | inWindows: []string{filepath.Join(altFS.Root(), ".\\repo1\\.git\\objects")}, |
| 879 | setup: func() { |
| 880 | err := altFS.MkdirAll(filepath.Join("repo1", ".git", "objects"), 0o700) |
| 881 | assert.NoError(t, err) |
| 882 | }, |
| 883 | wantRoots: []string{filepath.Join("repo1", ".git")}, |
| 884 | }, |
| 885 | { |
| 886 | name: "rel path", |
| 887 | in: []string{"../../../repo3//.git/objects"}, |
| 888 | inWindows: []string{"..\\..\\..\\repo3\\.git\\objects"}, |
| 889 | setup: func() { |
| 890 | err := altFS.MkdirAll(filepath.Join("repo3", ".git", "objects"), 0o700) |
| 891 | assert.NoError(t, err) |
| 892 | }, |
| 893 | wantRoots: []string{filepath.Join("repo3", ".git")}, |
| 894 | }, |
| 895 | { |
| 896 | name: "invalid abs path", |
| 897 | in: []string{"/alt/target2"}, |
| 898 | inWindows: []string{"\\alt\\target2"}, |
| 899 | wantErr: true, |
| 900 | }, |
| 901 | { |
| 902 | name: "invalid rel path", |
| 903 | in: []string{"../../../alt/target3"}, |
| 904 | inWindows: []string{"..\\..\\..\\alt\\target3"}, |
| 905 | wantErr: true, |
| 906 | }, |
| 907 | } |
| 908 | |
| 909 | for _, tc := range tests { |
| 910 | t.Run(tc.name, func(t *testing.T) { |
| 911 | dir := NewWithOptions(dotFS, Options{AlternatesFS: altFS}) |
| 912 | err := dir.Initialize() |
| 913 | assert.NoError(t, err) |
| 914 | |
| 915 | content := strings.Join(tc.in, "\n") |
| 916 | if runtime.GOOS == "windows" { |
| 917 | content = strings.Join(tc.inWindows, "\r\n") |
| 918 | } |
| 919 | |
| 920 | // Create alternates file. |
no test coverage detected
searching dependent graphs…