Add live tests for some methods in the git package
We relied too much on stubs for these methods. These new tests actually invoke `git` commands in the context of a test repository.
This commit is contained in:
parent
0f85304e3e
commit
d97e8fe172
11 changed files with 54 additions and 0 deletions
1
git/fixtures/.gitignore
vendored
Normal file
1
git/fixtures/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
*.git/COMMIT_EDITMSG
|
||||
1
git/fixtures/simple.git/HEAD
Normal file
1
git/fixtures/simple.git/HEAD
Normal file
|
|
@ -0,0 +1 @@
|
|||
ref: refs/heads/main
|
||||
9
git/fixtures/simple.git/config
Normal file
9
git/fixtures/simple.git/config
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
;bare = true
|
||||
ignorecase = true
|
||||
precomposeunicode = true
|
||||
[user]
|
||||
name = Mona the Cat
|
||||
email = monalisa@github.com
|
||||
BIN
git/fixtures/simple.git/index
Normal file
BIN
git/fixtures/simple.git/index
Normal file
Binary file not shown.
2
git/fixtures/simple.git/logs/HEAD
Normal file
2
git/fixtures/simple.git/logs/HEAD
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
0000000000000000000000000000000000000000 d1e0abfb7d158ed544a202a6958c62d4fc22e12f Mona the Cat <monalisa@github.com> 1614174263 +0100 commit (initial): Initial commit
|
||||
d1e0abfb7d158ed544a202a6958c62d4fc22e12f 6f1a2405cace1633d89a79c74c65f22fe78f9659 Mona the Cat <monalisa@github.com> 1614174275 +0100 commit: Second commit
|
||||
2
git/fixtures/simple.git/logs/refs/heads/main
Normal file
2
git/fixtures/simple.git/logs/refs/heads/main
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
0000000000000000000000000000000000000000 d1e0abfb7d158ed544a202a6958c62d4fc22e12f Mona the Cat <monalisa@github.com> 1614174263 +0100 commit (initial): Initial commit
|
||||
d1e0abfb7d158ed544a202a6958c62d4fc22e12f 6f1a2405cace1633d89a79c74c65f22fe78f9659 Mona the Cat <monalisa@github.com> 1614174275 +0100 commit: Second commit
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,3 @@
|
|||
x²NK
|
||||
б0t²S╪╫ ILc
|
||||
"┌+Н╪@▓╬≤MМК╒╥7"^@≤мС▀╣bпZНxF°Н├h█▌аbХ╫╢;▓l╞²KяТр©r╝3<ЙД│3бм3°Kc#-ЧЗ"нk8дZ.═╛2Йd╢=б^*)ESш&Цiq÷┬и▐П╜Б≥i│├о▀P┤
j┌╡A╒yА÷И
3*H/
|
||||
1
git/fixtures/simple.git/refs/heads/main
Normal file
1
git/fixtures/simple.git/refs/heads/main
Normal file
|
|
@ -0,0 +1 @@
|
|||
6f1a2405cace1633d89a79c74c65f22fe78f9659
|
||||
|
|
@ -1,12 +1,47 @@
|
|||
package git
|
||||
|
||||
import (
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/cli/cli/internal/run"
|
||||
)
|
||||
|
||||
func setGitDir(t *testing.T, dir string) {
|
||||
// TODO: also set XDG_CONFIG_HOME, GIT_CONFIG_NOSYSTEM
|
||||
old_GIT_DIR := os.Getenv("GIT_DIR")
|
||||
os.Setenv("GIT_DIR", dir)
|
||||
t.Cleanup(func() {
|
||||
os.Setenv("GIT_DIR", old_GIT_DIR)
|
||||
})
|
||||
}
|
||||
|
||||
func TestLastCommit(t *testing.T) {
|
||||
setGitDir(t, "./fixtures/simple.git")
|
||||
c, err := LastCommit()
|
||||
if err != nil {
|
||||
t.Fatalf("LastCommit error: %v", err)
|
||||
}
|
||||
if c.Sha != "6f1a2405cace1633d89a79c74c65f22fe78f9659" {
|
||||
t.Errorf("expected sha %q, got %q", "6f1a2405cace1633d89a79c74c65f22fe78f9659", c.Sha)
|
||||
}
|
||||
if c.Title != "Second commit" {
|
||||
t.Errorf("expected title %q, got %q", "Second commit", c.Title)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommitBody(t *testing.T) {
|
||||
setGitDir(t, "./fixtures/simple.git")
|
||||
body, err := CommitBody("6f1a2405cace1633d89a79c74c65f22fe78f9659")
|
||||
if err != nil {
|
||||
t.Fatalf("CommitBody error: %v", err)
|
||||
}
|
||||
if body != "I'm starting to get the hang of things\n" {
|
||||
t.Errorf("expected %q, got %q", "I'm starting to get the hang of things\n", body)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_UncommittedChangeCount(t *testing.T) {
|
||||
type c struct {
|
||||
Label string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue