test: add git helper and guard annotations
This commit is contained in:
committed by
Steve Yegge
parent
f3dcafca66
commit
713c569e6e
@@ -46,31 +46,17 @@ func TestCheckGitHooks(t *testing.T) {
|
||||
// This test needs to run in a git repository
|
||||
// We test the basic case where hooks are not installed
|
||||
t.Run("not in git repo returns N/A", func(t *testing.T) {
|
||||
// Save current directory
|
||||
origDir, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() {
|
||||
if err := os.Chdir(origDir); err != nil {
|
||||
t.Fatalf("failed to restore directory: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Change to a non-git directory
|
||||
tmpDir := t.TempDir()
|
||||
if err := os.Chdir(tmpDir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
runInDir(t, tmpDir, func() {
|
||||
check := CheckGitHooks()
|
||||
|
||||
check := CheckGitHooks()
|
||||
|
||||
if check.Status != StatusOK {
|
||||
t.Errorf("expected status %q, got %q", StatusOK, check.Status)
|
||||
}
|
||||
if check.Message != "N/A (not a git repository)" {
|
||||
t.Errorf("unexpected message: %s", check.Message)
|
||||
}
|
||||
if check.Status != StatusOK {
|
||||
t.Errorf("expected status %q, got %q", StatusOK, check.Status)
|
||||
}
|
||||
if check.Message != "N/A (not a git repository)" {
|
||||
t.Errorf("unexpected message: %s", check.Message)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -374,24 +360,16 @@ func TestCheckGitHooks_CorruptedHookFiles(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
tt.setup(t, tmpDir)
|
||||
|
||||
origDir, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Chdir(origDir)
|
||||
runInDir(t, tmpDir, func() {
|
||||
check := CheckGitHooks()
|
||||
|
||||
if err := os.Chdir(tmpDir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check := CheckGitHooks()
|
||||
|
||||
if check.Status != tt.expectedStatus {
|
||||
t.Errorf("expected status %q, got %q (message: %s)", tt.expectedStatus, check.Status, check.Message)
|
||||
}
|
||||
if tt.expectInMsg != "" && !strings.Contains(check.Message, tt.expectInMsg) {
|
||||
t.Errorf("expected message to contain %q, got %q", tt.expectInMsg, check.Message)
|
||||
}
|
||||
if check.Status != tt.expectedStatus {
|
||||
t.Errorf("expected status %q, got %q (message: %s)", tt.expectedStatus, check.Status, check.Message)
|
||||
}
|
||||
if tt.expectInMsg != "" && !strings.Contains(check.Message, tt.expectInMsg) {
|
||||
t.Errorf("expected message to contain %q, got %q", tt.expectInMsg, check.Message)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user