Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions private/pkg/git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,49 @@ func TestGitCloner(t *testing.T) {
_, err = readBucket.Stat(ctx, "nonexistent")
assert.ErrorIs(t, err, fs.ErrNotExist)
})

t.Run("env_override=GIT_DIR", func(t *testing.T) {
t.Parallel()
readBucket := readBucketForName(ctx, t, workDir, readBucketForNameOptions{
envOverrides: map[string]string{
"GIT_DIR": filepath.Join(t.TempDir(), "nonexistent"),
},
})

content, err := storage.ReadPath(ctx, readBucket, "a.proto")
require.NoError(t, err)
assert.Equal(t, "// commit 2", string(content))
})

t.Run("env_override=GIT_INDEX_FILE", func(t *testing.T) {
t.Parallel()
readBucket := readBucketForName(ctx, t, workDir, readBucketForNameOptions{
envOverrides: map[string]string{
// Parent dir intentionally absent so git cannot create the index file
// here; without the override, the clone would fail to write the index.
"GIT_INDEX_FILE": filepath.Join(t.TempDir(), "nonexistent-parent", "index"),
},
})

content, err := storage.ReadPath(ctx, readBucket, "a.proto")
require.NoError(t, err)
assert.Equal(t, "// commit 2", string(content))
})

t.Run("env_override=GIT_DIR,GIT_INDEX_FILE", func(t *testing.T) {
t.Parallel()
tempDir := t.TempDir()
readBucket := readBucketForName(ctx, t, workDir, readBucketForNameOptions{
envOverrides: map[string]string{
"GIT_DIR": filepath.Join(tempDir, "nonexistent-dir"),
"GIT_INDEX_FILE": filepath.Join(tempDir, "nonexistent-parent", "index"),
},
})

content, err := storage.ReadPath(ctx, readBucket, "a.proto")
require.NoError(t, err)
assert.Equal(t, "// commit 2", string(content))
})
}

type readBucketForNameOptions struct {
Expand All @@ -349,6 +392,7 @@ type readBucketForNameOptions struct {
recurseSubmodules bool
subDir string
filter string
envOverrides map[string]string
}

func readBucketForName(ctx context.Context, t *testing.T, path string, options readBucketForNameOptions) storage.ReadBucket {
Expand All @@ -357,6 +401,9 @@ func readBucketForName(ctx context.Context, t *testing.T, path string, options r
cloner := NewCloner(slogtestext.NewLogger(t), storageosProvider, ClonerOptions{})
envContainer, err := app.NewEnvContainerForOS()
require.NoError(t, err)
if len(options.envOverrides) > 0 {
envContainer = app.NewEnvContainerWithOverrides(envContainer, options.envOverrides)
}

depth := options.depth
if depth == 0 {
Expand Down
Loading