abra/pkg/git/init_test.go
Ammar Hussein 28c7676413
Some checks failed
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is failing
replace code-descriptive comments with method level comments
2024-12-15 09:53:28 -08:00

37 lines
986 B
Go

package git
import (
"testing"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/storage/memory"
)
// Verify that SwitchToMain has the desired effect on the repo
func TestSwitchToMain(t *testing.T) {
storage := memory.NewStorage()
repo, err := git.Init(storage, nil)
if err != nil {
t.Fatalf("failed to create in-memory repository: %v", err)
}
err = SwitchToMain(repo)
if err != nil {
t.Fatalf("SwitchToMain failed: %v", err)
}
ref, err := repo.Reference(plumbing.HEAD, false)
if err != nil {
t.Fatalf("failed to get HEAD reference: %v", err)
}
if ref.Target().String() != "refs/heads/main" {
t.Errorf("expected HEAD to point to 'refs/heads/main', got %s", ref.Target().String())
}
cfg, err := repo.Config()
if err != nil {
t.Fatalf("failed to get repository config: %v", err)
}
if cfg.Init.DefaultBranch != "main" {
t.Errorf("expected default branch to be 'main', got %s", cfg.Init.DefaultBranch)
}
}