(t *testing.T, dotFS, altFS billy.Filesystem)
| 836 | } |
| 837 | |
| 838 | func testAlternates(t *testing.T, dotFS, altFS billy.Filesystem) { |
| 839 | tests := []struct { |
| 840 | name string |
| 841 | in []string |
| 842 | inWindows []string |
| 843 | setup func() |
| 844 | wantErr bool |
| 845 | wantRoots []string |
| 846 | }{ |
| 847 | { |
| 848 | name: "no alternates", |
| 849 | }, |
| 850 | { |
| 851 | name: "abs path", |
| 852 | in: []string{filepath.Join(altFS.Root(), "./repo1/.git/objects")}, |
| 853 | inWindows: []string{filepath.Join(altFS.Root(), ".\\repo1\\.git\\objects")}, |
| 854 | setup: func() { |
| 855 | err := altFS.MkdirAll(filepath.Join("repo1", ".git", "objects"), 0o700) |
| 856 | assert.NoError(t, err) |
| 857 | }, |
| 858 | wantRoots: []string{filepath.Join("repo1", ".git")}, |
| 859 | }, |
| 860 | { |
| 861 | name: "rel path", |
| 862 | in: []string{"../../../repo3//.git/objects"}, |
| 863 | inWindows: []string{"..\\..\\..\\repo3\\.git\\objects"}, |
| 864 | setup: func() { |
| 865 | err := altFS.MkdirAll(filepath.Join("repo3", ".git", "objects"), 0o700) |
| 866 | assert.NoError(t, err) |
| 867 | }, |
| 868 | wantRoots: []string{filepath.Join("repo3", ".git")}, |
| 869 | }, |
| 870 | { |
| 871 | name: "invalid abs path", |
| 872 | in: []string{"/alt/target2"}, |
| 873 | inWindows: []string{"\\alt\\target2"}, |
| 874 | wantErr: true, |
| 875 | }, |
| 876 | { |
| 877 | name: "invalid rel path", |
| 878 | in: []string{"../../../alt/target3"}, |
| 879 | inWindows: []string{"..\\..\\..\\alt\\target3"}, |
| 880 | wantErr: true, |
| 881 | }, |
| 882 | } |
| 883 | |
| 884 | for _, tc := range tests { |
| 885 | t.Run(tc.name, func(t *testing.T) { |
| 886 | dir := NewWithOptions(dotFS, Options{AlternatesFS: altFS}) |
| 887 | err := dir.Initialize() |
| 888 | assert.NoError(t, err) |
| 889 | |
| 890 | content := strings.Join(tc.in, "\n") |
| 891 | if runtime.GOOS == "windows" { |
| 892 | content = strings.Join(tc.inWindows, "\r\n") |
| 893 | } |
| 894 | |
| 895 | // Create alternates file. |
no test coverage detected