From 97efbe20747d6acd8a46764fb6f6c31fb8547fa2 Mon Sep 17 00:00:00 2001 From: Maya Chen <275405107+otjdiepluong@users.noreply.github.com> Date: Tue, 9 Jun 2026 12:42:47 +0000 Subject: [PATCH] chore: improve actions-runner-controller maintenance path --- testing/git.go | 4 ++++ testing/git_test.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 testing/git_test.go diff --git a/testing/git.go b/testing/git.go index d6ff5b53b5..93c9c2fe7a 100644 --- a/testing/git.go +++ b/testing/git.go @@ -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) diff --git a/testing/git_test.go b/testing/git_test.go new file mode 100644 index 0000000000..c12dfff48e --- /dev/null +++ b/testing/git_test.go @@ -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) + } + }) + } +}