add test for SwitchToMain
This commit is contained in:
parent
8d076a308a
commit
730fef09a3
42
pkg/git/init_test.go
Normal file
42
pkg/git/init_test.go
Normal file
@ -0,0 +1,42 @@
|
||||
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"
|
||||
)
|
||||
|
||||
func TestSwitchToMain(t *testing.T) {
|
||||
// Create a new in-memory repository
|
||||
storage := memory.NewStorage()
|
||||
repo, err := git.Init(storage, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create in-memory repository: %v", err)
|
||||
}
|
||||
|
||||
// Call the function under test
|
||||
err = SwitchToMain(repo)
|
||||
if err != nil {
|
||||
t.Fatalf("SwitchToMain failed: %v", err)
|
||||
}
|
||||
|
||||
// Verify that HEAD points to the 'main' branch
|
||||
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())
|
||||
}
|
||||
|
||||
// Verify that the default branch is set to 'main' in the config
|
||||
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)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user