MCPcopy Create free account
hub / github.com/go-git/go-git / testAlternates

Function testAlternates

storage/filesystem/dotgit/dotgit_test.go:838–919  ·  view source on GitHub ↗
(t *testing.T, dotFS, altFS billy.Filesystem)

Source from the content-addressed store, hash-verified

836}
837
838func 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.

Callers 3

TestAlternatesDefaultFunction · 0.85
TestAlternatesWithFSFunction · 0.85

Calls 10

NewWithOptionsFunction · 0.85
JoinMethod · 0.80
RootMethod · 0.80
MkdirAllMethod · 0.80
InitializeMethod · 0.80
CreateMethod · 0.80
AlternatesMethod · 0.80
CloseMethod · 0.65
WriteMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected