Skip to content

Commit 1d43088

Browse files
committed
test(git): update Clone method mock to accept additional argument
Modified all instances of the Clone method mock to include an additional argument, ensuring compatibility with recent changes in the Git operations. This update enhances the test coverage and maintains alignment with the updated method signature across various test files.
1 parent c67dd8e commit 1d43088

22 files changed

Lines changed: 182 additions & 154 deletions

internal/config/defaults.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// Package config provides configuration defaults and helpers for go-broadcast.
22
package config
33

4+
// DefaultBlobSizeLimit is the default maximum blob size for partial clone.
5+
// Blobs larger than this are excluded during git clone operations.
6+
// Use "0" to disable filtering and clone all blobs.
7+
const DefaultBlobSizeLimit = "10m"
8+
49
// DefaultExclusions returns smart default exclusions for development artifacts
510
func DefaultExclusions() []string {
611
return []string{

internal/config/parser.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ func applyDefaults(config *Config) {
7070
group.Source.Branch = "main"
7171
}
7272

73+
// Set default blob size limit for source
74+
if group.Source.BlobSizeLimit == "" {
75+
group.Source.BlobSizeLimit = DefaultBlobSizeLimit
76+
}
77+
7378
// Set default branch prefix if not specified
7479
if group.Defaults.BranchPrefix == "" {
7580
group.Defaults.BranchPrefix = "chore/sync-files"
@@ -87,6 +92,11 @@ func applyDefaults(config *Config) {
8792

8893
// Apply directory defaults to group targets
8994
for j := range group.Targets {
95+
// Set default blob size limit for targets (inherits from source if not set)
96+
if group.Targets[j].BlobSizeLimit == "" {
97+
group.Targets[j].BlobSizeLimit = group.Source.BlobSizeLimit
98+
}
99+
90100
for k := range group.Targets[j].Directories {
91101
ApplyDirectoryDefaults(&group.Targets[j].Directories[k])
92102
}

internal/config/types.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ type Config struct {
1212

1313
// SourceConfig defines the source repository settings
1414
type SourceConfig struct {
15-
Repo string `yaml:"repo"` // Format: org/repo
16-
Branch string `yaml:"branch"` // Default: master
17-
SecurityEmail string `yaml:"security_email,omitempty"` // Security contact email address (for transformation)
18-
SupportEmail string `yaml:"support_email,omitempty"` // Support/contact email address (for transformation)
15+
Repo string `yaml:"repo"` // Format: org/repo
16+
Branch string `yaml:"branch"` // Default: master
17+
BlobSizeLimit string `yaml:"blob_size_limit,omitempty"` // Max blob size for partial clone (e.g., "10m"), "0" to disable
18+
SecurityEmail string `yaml:"security_email,omitempty"` // Security contact email address (for transformation)
19+
SupportEmail string `yaml:"support_email,omitempty"` // Support/contact email address (for transformation)
1920
}
2021

2122
// GlobalConfig contains global settings applied across all targets
@@ -40,6 +41,7 @@ type DefaultConfig struct {
4041
type TargetConfig struct {
4142
Repo string `yaml:"repo"` // Format: org/repo
4243
Branch string `yaml:"branch,omitempty"` // Target branch for PR base (defaults to repo's default branch)
44+
BlobSizeLimit string `yaml:"blob_size_limit,omitempty"` // Override source blob size limit for partial clone
4345
Files []FileMapping `yaml:"files,omitempty"` // Files to sync
4446
Directories []DirectoryMapping `yaml:"directories,omitempty"` // Directories to sync
4547
FileListRefs []string `yaml:"file_list_refs,omitempty"` // References to file lists by ID

internal/git/client.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,25 @@ type RepositoryInfo struct {
1212
IsGitHub bool // Whether this is a GitHub repository
1313
}
1414

15+
// CloneOptions configures git clone behavior
16+
type CloneOptions struct {
17+
// BlobSizeLimit sets the maximum blob size for partial clone.
18+
// Uses git's --filter=blob:limit=<size> option.
19+
// Examples: "10m" (10 megabytes), "1g" (1 gigabyte)
20+
// Use "0" or empty string to disable filtering (clone all blobs).
21+
BlobSizeLimit string
22+
}
23+
1524
// Client defines the interface for Git operations
1625
type Client interface {
17-
// Clone clones a repository to the specified path
18-
Clone(ctx context.Context, url, path string) error
19-
20-
// CloneWithBranch clones a repository to the specified path with a specific branch
21-
// If branch is empty, behaves like Clone
22-
CloneWithBranch(ctx context.Context, url, path, branch string) error
26+
// Clone clones a repository to the specified path.
27+
// opts can be nil to use default behavior.
28+
Clone(ctx context.Context, url, path string, opts *CloneOptions) error
29+
30+
// CloneWithBranch clones a repository to the specified path with a specific branch.
31+
// If branch is empty, behaves like Clone.
32+
// opts can be nil to use default behavior.
33+
CloneWithBranch(ctx context.Context, url, path, branch string, opts *CloneOptions) error
2334

2435
// Checkout switches to the specified branch
2536
Checkout(ctx context.Context, repoPath, branch string) error

internal/git/git_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestGitClient_FullWorkflow_Integration(t *testing.T) {
2626

2727
// Clone a real repository
2828
t.Run("Clone", func(t *testing.T) {
29-
err := client.Clone(ctx, "https://github.com/octocat/Hello-World.git", repoPath)
29+
err := client.Clone(ctx, "https://github.com/octocat/Hello-World.git", repoPath, nil)
3030
require.NoError(t, err)
3131
assert.DirExists(t, filepath.Join(repoPath, ".git"))
3232

internal/git/git_retry_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func TestGitClient_CloneWithRetry(t *testing.T) {
155155
require.NoError(t, cmd.Run())
156156

157157
// Clone should succeed on first attempt
158-
err = client.Clone(ctx, sourceRepo, repoPath)
158+
err = client.Clone(ctx, sourceRepo, repoPath, nil)
159159
require.NoError(t, err)
160160

161161
// Verify the repository was cloned
@@ -173,7 +173,7 @@ func TestGitClient_CloneWithRetry(t *testing.T) {
173173
// Create the directory first
174174
require.NoError(t, os.MkdirAll(repoPath, 0o750))
175175

176-
err = client.Clone(ctx, "https://example.com/repo.git", repoPath)
176+
err = client.Clone(ctx, "https://example.com/repo.git", repoPath, nil)
177177
require.Error(t, err)
178178
assert.Contains(t, err.Error(), "repository already exists")
179179
})
@@ -190,7 +190,7 @@ func TestGitClient_CloneWithRetry(t *testing.T) {
190190
defer cancel()
191191

192192
// Use a URL that will trigger network errors
193-
err = client.Clone(cancelCtx, "https://invalid-url-that-causes-timeout.invalid/repo.git", repoPath)
193+
err = client.Clone(cancelCtx, "https://invalid-url-that-causes-timeout.invalid/repo.git", repoPath, nil)
194194
require.Error(t, err)
195195
// Should get either context canceled or network error
196196
assert.True(t, errors.Is(err, context.DeadlineExceeded) || strings.Contains(err.Error(), "clone repository"))

internal/git/git_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ func TestGitClient_Clone(t *testing.T) {
543543
repoPath := filepath.Join(tmpDir, "test-repo")
544544

545545
// Clone a small public repository
546-
err = client.Clone(ctx, "https://github.com/octocat/Hello-World.git", repoPath)
546+
err = client.Clone(ctx, "https://github.com/octocat/Hello-World.git", repoPath, nil)
547547
require.NoError(t, err)
548548

549549
// Verify the repository was cloned
@@ -568,7 +568,7 @@ func TestGitClient_Clone_AlreadyExists(t *testing.T) {
568568
require.NoError(t, err)
569569

570570
// Try to clone into existing directory
571-
err = client.Clone(ctx, "https://github.com/octocat/Hello-World.git", repoPath)
571+
err = client.Clone(ctx, "https://github.com/octocat/Hello-World.git", repoPath, nil)
572572
require.Error(t, err)
573573
assert.ErrorIs(t, err, ErrRepositoryExists)
574574
}
@@ -606,7 +606,7 @@ func TestGitClient_CloneWithBranch(t *testing.T) {
606606
repoPath := filepath.Join(tmpDir, "test-repo-"+tt.name)
607607

608608
// Clone with specific branch
609-
err = client.CloneWithBranch(ctx, "https://github.com/octocat/Hello-World.git", repoPath, tt.branch)
609+
err = client.CloneWithBranch(ctx, "https://github.com/octocat/Hello-World.git", repoPath, tt.branch, nil)
610610
require.NoError(t, err)
611611

612612
// Verify the repository was cloned
@@ -640,7 +640,7 @@ func TestGitClient_CloneWithBranch_AlreadyExists(t *testing.T) {
640640
require.NoError(t, err)
641641

642642
// Try to clone with branch into existing directory
643-
err = client.CloneWithBranch(ctx, "https://github.com/octocat/Hello-World.git", repoPath, "master")
643+
err = client.CloneWithBranch(ctx, "https://github.com/octocat/Hello-World.git", repoPath, "master", nil)
644644
require.Error(t, err)
645645
assert.ErrorIs(t, err, ErrRepositoryExists)
646646
}
@@ -658,7 +658,7 @@ func TestGitClient_CloneWithBranch_InvalidBranch(t *testing.T) {
658658
repoPath := filepath.Join(tmpDir, "test-repo")
659659

660660
// Try to clone with non-existent branch
661-
err = client.CloneWithBranch(ctx, "https://github.com/octocat/Hello-World.git", repoPath, "non-existent-branch")
661+
err = client.CloneWithBranch(ctx, "https://github.com/octocat/Hello-World.git", repoPath, "non-existent-branch", nil)
662662
require.Error(t, err)
663663
assert.Contains(t, err.Error(), "clone repository with branch non-existent-branch")
664664
}
@@ -747,7 +747,7 @@ func TestGitClient_GetRemoteURL(t *testing.T) {
747747
repoPath := filepath.Join(tmpDir, "test-repo")
748748

749749
// Clone a repository with a remote
750-
err = client.Clone(ctx, "https://github.com/octocat/Hello-World.git", repoPath)
750+
err = client.Clone(ctx, "https://github.com/octocat/Hello-World.git", repoPath, nil)
751751
require.NoError(t, err)
752752

753753
// Get remote URL
@@ -892,7 +892,7 @@ func TestGitClient_CloneError(t *testing.T) {
892892
ctx := context.Background()
893893

894894
// Test clone with invalid URL
895-
err = client.Clone(ctx, "invalid://url", "/tmp/test-clone-error")
895+
err = client.Clone(ctx, "invalid://url", "/tmp/test-clone-error", nil)
896896
require.Error(t, err)
897897
assert.Contains(t, err.Error(), "failed to clone repository")
898898
}

internal/git/mock.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ func NewMockClient() *MockClient {
1919
}
2020

2121
// Clone mock implementation
22-
func (m *MockClient) Clone(ctx context.Context, url, path string) error {
23-
args := m.Called(ctx, url, path)
22+
func (m *MockClient) Clone(ctx context.Context, url, path string, opts *CloneOptions) error {
23+
args := m.Called(ctx, url, path, opts)
2424
return testutil.ExtractError(args)
2525
}
2626

2727
// CloneWithBranch mock implementation
28-
func (m *MockClient) CloneWithBranch(ctx context.Context, url, path, branch string) error {
29-
args := m.Called(ctx, url, path, branch)
28+
func (m *MockClient) CloneWithBranch(ctx context.Context, url, path, branch string, opts *CloneOptions) error {
29+
args := m.Called(ctx, url, path, branch, opts)
3030
return testutil.ExtractError(args)
3131
}
3232

internal/git/mock_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,37 @@ func TestMockClientImplementation(t *testing.T) {
2929
t.Run("Clone", func(t *testing.T) {
3030
t.Run("success case", func(t *testing.T) {
3131
mock := NewMockClient()
32-
mock.On("Clone", ctx, "https://github.com/test/repo.git", "/tmp/repo").Return(nil)
32+
mock.On("Clone", ctx, "https://github.com/test/repo.git", "/tmp/repo", (*CloneOptions)(nil)).Return(nil)
3333

34-
err := mock.Clone(ctx, "https://github.com/test/repo.git", "/tmp/repo")
34+
err := mock.Clone(ctx, "https://github.com/test/repo.git", "/tmp/repo", nil)
3535
require.NoError(t, err)
3636
mock.AssertExpectations(t)
3737
})
3838

3939
t.Run("error case", func(t *testing.T) {
4040
mock := NewMockClient()
41-
mock.On("Clone", ctx, "https://github.com/test/repo.git", "/tmp/repo").Return(errCloneFailed)
41+
mock.On("Clone", ctx, "https://github.com/test/repo.git", "/tmp/repo", (*CloneOptions)(nil)).Return(errCloneFailed)
4242

43-
err := mock.Clone(ctx, "https://github.com/test/repo.git", "/tmp/repo")
43+
err := mock.Clone(ctx, "https://github.com/test/repo.git", "/tmp/repo", nil)
4444
require.Error(t, err)
4545
require.Equal(t, errCloneFailed, err)
4646
mock.AssertExpectations(t)
4747
})
4848

4949
t.Run("improperly configured mock", func(t *testing.T) {
5050
mock := NewMockClient()
51-
mock.On("Clone", ctx, "url", "path").Return()
51+
mock.On("Clone", ctx, "url", "path", (*CloneOptions)(nil)).Return()
5252

53-
err := mock.Clone(ctx, "url", "path")
53+
err := mock.Clone(ctx, "url", "path", nil)
5454
require.Error(t, err)
5555
require.Contains(t, err.Error(), "mock not properly configured")
5656
})
5757

5858
t.Run("mock returns non-error type", func(t *testing.T) {
5959
mock := NewMockClient()
60-
mock.On("Clone", ctx, "url", "path").Return("not an error")
60+
mock.On("Clone", ctx, "url", "path", (*CloneOptions)(nil)).Return("not an error")
6161

62-
err := mock.Clone(ctx, "url", "path")
62+
err := mock.Clone(ctx, "url", "path", nil)
6363
require.Error(t, err)
6464
require.Contains(t, err.Error(), "mock returned non-error type")
6565
})
@@ -272,8 +272,8 @@ func TestMockClientDefensiveProgramming(t *testing.T) {
272272
mock := NewMockClient()
273273

274274
// Test methods that return only error
275-
mock.On("Clone", ctx, "url", "path").Return(nil).Once()
276-
err := mock.Clone(ctx, "url", "path")
275+
mock.On("Clone", ctx, "url", "path", (*CloneOptions)(nil)).Return(nil).Once()
276+
err := mock.Clone(ctx, "url", "path", nil)
277277
require.NoError(t, err)
278278

279279
mock.On("Checkout", ctx, "repo", "branch").Return(nil).Once()
@@ -322,7 +322,7 @@ func TestMockClientConcurrency(_ *testing.T) {
322322
mock := NewMockClient()
323323

324324
// Set up expectations for concurrent calls
325-
mock.On("Clone", ctx, "url", "path").Return(nil).Maybe()
325+
mock.On("Clone", ctx, "url", "path", (*CloneOptions)(nil)).Return(nil).Maybe()
326326
mock.On("Checkout", ctx, "repo", "branch").Return(nil).Maybe()
327327
mock.On("CreateBranch", ctx, "repo", "branch").Return(nil).Maybe()
328328
mock.On("Add", ctx, "repo", []string{"file"}).Return(nil).Maybe()
@@ -338,7 +338,7 @@ func TestMockClientConcurrency(_ *testing.T) {
338338
// Launch goroutines for each method
339339
go func() {
340340
for i := 0; i < 10; i++ {
341-
_ = mock.Clone(ctx, "url", "path")
341+
_ = mock.Clone(ctx, "url", "path", nil)
342342
}
343343
done <- true
344344
}()

0 commit comments

Comments
 (0)