Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions testing/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func (g *GitRepo) Sync(ctx context.Context) error {
return errors.New("missing git dir")
}

if g.Branch == "" {
return errors.New("missing git branch")
}

dir, err := filepath.Abs(g.Dir)
if err != nil {
return fmt.Errorf("error getting abs path for %q: %w", g.Dir, err)
Expand Down
45 changes: 45 additions & 0 deletions testing/git_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package testing

import (
"context"
"errors"
"testing"
)

func TestGitRepoSyncValidation(t *testing.T) {
ctx := context.Background()

tests := []struct {
name string
repo GitRepo
want error
}{
{
name: "missing name",
repo: GitRepo{Dir: "/tmp/repo", Branch: "main"},
want: errors.New("missing git repo name"),
},
{
name: "missing dir",
repo: GitRepo{Name: "owner/repo", Branch: "main"},
want: errors.New("missing git dir"),
},
{
name: "missing branch",
repo: GitRepo{Name: "owner/repo", Dir: "/tmp/repo"},
want: errors.New("missing git branch"),
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.repo.Sync(ctx)
if err == nil {
t.Fatalf("expected error %q, got nil", tt.want)
}
if err.Error() != tt.want.Error() {
t.Errorf("expected error %q, got %q", tt.want, err)
}
})
}
}