[gitfame] Add tests.
This commit is contained in:
parent
7773e306d9
commit
bf34e93d49
40 changed files with 283 additions and 0 deletions
107
gitfame/test/integration/gitfame_test.go
Normal file
107
gitfame/test/integration/gitfame_test.go
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
package integration
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
|
||||||
|
"gitlab.com/slon/shad-go/tools/testtool"
|
||||||
|
)
|
||||||
|
|
||||||
|
const importPath = "gitlab.com/slon/shad-go/gitfame/cmd/gitfame"
|
||||||
|
|
||||||
|
var binCache testtool.BinCache
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
os.Exit(func() int {
|
||||||
|
var teardown testtool.CloseFunc
|
||||||
|
binCache, teardown = testtool.NewBinCache()
|
||||||
|
defer teardown()
|
||||||
|
|
||||||
|
return m.Run()
|
||||||
|
}())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGitFame(t *testing.T) {
|
||||||
|
binary, err := binCache.GetBinary(importPath)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
bundlesDir := path.Join("./testdata", "bundles")
|
||||||
|
testsDir := path.Join("./testdata", "good")
|
||||||
|
files, err := ioutil.ReadDir(testsDir)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
for _, f := range files {
|
||||||
|
if !f.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
tc := ReadTestCase(t, filepath.Join(testsDir, f.Name()))
|
||||||
|
|
||||||
|
t.Run(f.Name()+"/"+tc.Name, func(t *testing.T) {
|
||||||
|
dir, err := ioutil.TempDir("", "gitfame-")
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer func() { _ = os.RemoveAll(dir) }()
|
||||||
|
|
||||||
|
args := []string{"--repository", dir}
|
||||||
|
args = append(args, tc.Args...)
|
||||||
|
|
||||||
|
Unbundle(t, filepath.Join(bundlesDir, tc.Bundle), dir)
|
||||||
|
|
||||||
|
cmd := exec.Command(binary, args...)
|
||||||
|
cmd.Stderr = ioutil.Discard
|
||||||
|
|
||||||
|
output, err := cmd.Output()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.Equal(t, string(tc.Expected), string(output))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type TestCase struct {
|
||||||
|
*TestDescription
|
||||||
|
Expected []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadTestCase(t *testing.T, path string) *TestCase {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
desc := ReadTestDescription(t, path)
|
||||||
|
|
||||||
|
expected, err := ioutil.ReadFile(filepath.Join(path, "expected.out"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
return &TestCase{TestDescription: desc, Expected: expected}
|
||||||
|
}
|
||||||
|
|
||||||
|
type TestDescription struct {
|
||||||
|
Name string `yaml:"name"`
|
||||||
|
Args []string `yaml:"args"`
|
||||||
|
Bundle string `yaml:"bundle"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadTestDescription(t *testing.T, path string) *TestDescription {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
data, err := ioutil.ReadFile(filepath.Join(path, "description.yaml"))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
var desc TestDescription
|
||||||
|
require.NoError(t, yaml.Unmarshal(data, &desc))
|
||||||
|
|
||||||
|
return &desc
|
||||||
|
}
|
||||||
|
|
||||||
|
func Unbundle(t *testing.T, src, dst string) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
cmd := exec.Command("git", "clone", src, dst)
|
||||||
|
require.NoError(t, cmd.Run())
|
||||||
|
}
|
BIN
gitfame/test/integration/testdata/bundles/breaker.bundle
vendored
Normal file
BIN
gitfame/test/integration/testdata/bundles/breaker.bundle
vendored
Normal file
Binary file not shown.
BIN
gitfame/test/integration/testdata/bundles/go-cmp.bundle
vendored
Normal file
BIN
gitfame/test/integration/testdata/bundles/go-cmp.bundle
vendored
Normal file
Binary file not shown.
BIN
gitfame/test/integration/testdata/bundles/simple.bundle
vendored
Normal file
BIN
gitfame/test/integration/testdata/bundles/simple.bundle
vendored
Normal file
Binary file not shown.
5
gitfame/test/integration/testdata/good/1/description.yaml
vendored
Normal file
5
gitfame/test/integration/testdata/good/1/description.yaml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# Empty .md file, old revision
|
||||||
|
|
||||||
|
name: empty file, old revision
|
||||||
|
args: [--format, csv, --revision, 49e9ed8b0c32adfa6b30ebe5d94d9d8811ba4d26]
|
||||||
|
bundle: simple.bundle
|
2
gitfame/test/integration/testdata/good/1/expected.out
vendored
Normal file
2
gitfame/test/integration/testdata/good/1/expected.out
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
Name,Lines,Commits,Files
|
||||||
|
Russ Cox,0,1,1
|
5
gitfame/test/integration/testdata/good/10/description.yaml
vendored
Normal file
5
gitfame/test/integration/testdata/good/10/description.yaml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# .md with space in name
|
||||||
|
|
||||||
|
name: space in filename
|
||||||
|
args: [--format, csv, --revision, d5e9958063725c54e82b2e77427bd0dcbaf43fef]
|
||||||
|
bundle: breaker.bundle
|
2
gitfame/test/integration/testdata/good/10/expected.out
vendored
Normal file
2
gitfame/test/integration/testdata/good/10/expected.out
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
Name,Lines,Commits,Files
|
||||||
|
Brad Fitzpatrick,4,1,1
|
5
gitfame/test/integration/testdata/good/11/description.yaml
vendored
Normal file
5
gitfame/test/integration/testdata/good/11/description.yaml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# author with tabs in name
|
||||||
|
|
||||||
|
name: tabs in author name
|
||||||
|
args: [--format, csv, --revision, 400683875aad1234a51d9fe6e8b6137556702ae6, --restrict-to, main.go]
|
||||||
|
bundle: breaker.bundle
|
2
gitfame/test/integration/testdata/good/11/expected.out
vendored
Normal file
2
gitfame/test/integration/testdata/good/11/expected.out
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
Name,Lines,Commits,Files
|
||||||
|
My name is Tabby,7,1,1
|
5
gitfame/test/integration/testdata/good/12/description.yaml
vendored
Normal file
5
gitfame/test/integration/testdata/good/12/description.yaml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# author with tabs in name, empty file
|
||||||
|
|
||||||
|
name: tabs in author name, empty file
|
||||||
|
args: [--format, csv, --revision, 17f8121d7a01af4dd79e2e9cba387f96edc64bd6, --restrict-to, empty.txt]
|
||||||
|
bundle: breaker.bundle
|
2
gitfame/test/integration/testdata/good/12/expected.out
vendored
Normal file
2
gitfame/test/integration/testdata/good/12/expected.out
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
Name,Lines,Commits,Files
|
||||||
|
My name is Tabby,0,1,1
|
5
gitfame/test/integration/testdata/good/13/description.yaml
vendored
Normal file
5
gitfame/test/integration/testdata/good/13/description.yaml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# author with name consisting of printable characters, empty commit
|
||||||
|
|
||||||
|
name: printable in author name, empty commit
|
||||||
|
args: [--format, csv, --revision, 861af9ed3975a7e247547331c2d1e029a8415da0]
|
||||||
|
bundle: breaker.bundle
|
3
gitfame/test/integration/testdata/good/13/expected.out
vendored
Normal file
3
gitfame/test/integration/testdata/good/13/expected.out
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
Name,Lines,Commits,Files
|
||||||
|
My name is Tabby,7,2,2
|
||||||
|
Brad Fitzpatrick,4,1,1
|
5
gitfame/test/integration/testdata/good/14/description.yaml
vendored
Normal file
5
gitfame/test/integration/testdata/good/14/description.yaml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# author with name consisting of printable characters, empty commit
|
||||||
|
|
||||||
|
name: printable in author name, empty commit
|
||||||
|
args: [--format, csv, --revision, 68cc2ccd318dce0e86c86c0adc53a9d967e2192c]
|
||||||
|
bundle: breaker.bundle
|
4
gitfame/test/integration/testdata/good/14/expected.out
vendored
Normal file
4
gitfame/test/integration/testdata/good/14/expected.out
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
Name,Lines,Commits,Files
|
||||||
|
My name is Tabby,7,2,2
|
||||||
|
Brad Fitzpatrick,4,1,1
|
||||||
|
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV WXYZ!""#$%&'()*+,-./:;=?@[\]^_`{|}~",0,1,1
|
5
gitfame/test/integration/testdata/good/15/description.yaml
vendored
Normal file
5
gitfame/test/integration/testdata/good/15/description.yaml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# go-cmp, HEAD
|
||||||
|
|
||||||
|
name: go-cmp HEAD
|
||||||
|
args: [--format, csv]
|
||||||
|
bundle: go-cmp.bundle
|
17
gitfame/test/integration/testdata/good/15/expected.out
vendored
Normal file
17
gitfame/test/integration/testdata/good/15/expected.out
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
Name,Lines,Commits,Files
|
||||||
|
Joe Tsai,13818,94,54
|
||||||
|
colinnewell,130,1,1
|
||||||
|
A. Ishikawa,92,1,2
|
||||||
|
Roger Peppe,59,1,2
|
||||||
|
Tobias Klauser,35,2,3
|
||||||
|
178inaba,27,2,5
|
||||||
|
Kyle Lemons,11,1,1
|
||||||
|
Dmitri Shuralyov,8,1,2
|
||||||
|
ferhat elmas,7,1,4
|
||||||
|
Christian Muehlhaeuser,6,3,4
|
||||||
|
k.nakada,5,1,3
|
||||||
|
LMMilewski,5,1,2
|
||||||
|
Ernest Galbrun,3,1,1
|
||||||
|
Ross Light,2,1,1
|
||||||
|
Chris Morrow,1,1,1
|
||||||
|
Fiisio,1,1,1
|
5
gitfame/test/integration/testdata/good/16/description.yaml
vendored
Normal file
5
gitfame/test/integration/testdata/good/16/description.yaml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# go-cmp, HEAD, committer
|
||||||
|
|
||||||
|
name: go-cmp HEAD committer
|
||||||
|
args: [--format, csv, --use-committer]
|
||||||
|
bundle: go-cmp.bundle
|
4
gitfame/test/integration/testdata/good/16/expected.out
vendored
Normal file
4
gitfame/test/integration/testdata/good/16/expected.out
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
Name,Lines,Commits,Files
|
||||||
|
GitHub,11199,100,55
|
||||||
|
Joe Tsai,3009,12,29
|
||||||
|
Ross Light,2,1,1
|
5
gitfame/test/integration/testdata/good/17/description.yaml
vendored
Normal file
5
gitfame/test/integration/testdata/good/17/description.yaml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# go-cmp, HEAD, order by commits
|
||||||
|
|
||||||
|
name: go-cmp HEAD order-by commits
|
||||||
|
args: [--format, csv, --order-by, commits]
|
||||||
|
bundle: go-cmp.bundle
|
17
gitfame/test/integration/testdata/good/17/expected.out
vendored
Normal file
17
gitfame/test/integration/testdata/good/17/expected.out
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
Name,Lines,Commits,Files
|
||||||
|
Joe Tsai,13818,94,54
|
||||||
|
Christian Muehlhaeuser,6,3,4
|
||||||
|
Tobias Klauser,35,2,3
|
||||||
|
178inaba,27,2,5
|
||||||
|
colinnewell,130,1,1
|
||||||
|
A. Ishikawa,92,1,2
|
||||||
|
Roger Peppe,59,1,2
|
||||||
|
Kyle Lemons,11,1,1
|
||||||
|
Dmitri Shuralyov,8,1,2
|
||||||
|
ferhat elmas,7,1,4
|
||||||
|
k.nakada,5,1,3
|
||||||
|
LMMilewski,5,1,2
|
||||||
|
Ernest Galbrun,3,1,1
|
||||||
|
Ross Light,2,1,1
|
||||||
|
Chris Morrow,1,1,1
|
||||||
|
Fiisio,1,1,1
|
5
gitfame/test/integration/testdata/good/18/description.yaml
vendored
Normal file
5
gitfame/test/integration/testdata/good/18/description.yaml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# go-cmp, HEAD, order by files
|
||||||
|
|
||||||
|
name: go-cmp HEAD order-by files
|
||||||
|
args: [--format, csv, --order-by, files]
|
||||||
|
bundle: go-cmp.bundle
|
17
gitfame/test/integration/testdata/good/18/expected.out
vendored
Normal file
17
gitfame/test/integration/testdata/good/18/expected.out
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
Name,Lines,Commits,Files
|
||||||
|
Joe Tsai,13818,94,54
|
||||||
|
178inaba,27,2,5
|
||||||
|
ferhat elmas,7,1,4
|
||||||
|
Christian Muehlhaeuser,6,3,4
|
||||||
|
Tobias Klauser,35,2,3
|
||||||
|
k.nakada,5,1,3
|
||||||
|
A. Ishikawa,92,1,2
|
||||||
|
Roger Peppe,59,1,2
|
||||||
|
Dmitri Shuralyov,8,1,2
|
||||||
|
LMMilewski,5,1,2
|
||||||
|
colinnewell,130,1,1
|
||||||
|
Kyle Lemons,11,1,1
|
||||||
|
Ernest Galbrun,3,1,1
|
||||||
|
Ross Light,2,1,1
|
||||||
|
Chris Morrow,1,1,1
|
||||||
|
Fiisio,1,1,1
|
5
gitfame/test/integration/testdata/good/2/description.yaml
vendored
Normal file
5
gitfame/test/integration/testdata/good/2/description.yaml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# Empty project
|
||||||
|
|
||||||
|
name: empty project
|
||||||
|
args: [--format, csv, --revision, dff562439f0406fb00229e3e95a8d2048f265683]
|
||||||
|
bundle: simple.bundle
|
1
gitfame/test/integration/testdata/good/2/expected.out
vendored
Normal file
1
gitfame/test/integration/testdata/good/2/expected.out
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Name,Lines,Commits,Files
|
5
gitfame/test/integration/testdata/good/3/description.yaml
vendored
Normal file
5
gitfame/test/integration/testdata/good/3/description.yaml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# .md with single line
|
||||||
|
|
||||||
|
name: single line
|
||||||
|
args: [--format, csv, --revision, a7b4f155866102b0559392440f4217bc3c19bf62]
|
||||||
|
bundle: simple.bundle
|
2
gitfame/test/integration/testdata/good/3/expected.out
vendored
Normal file
2
gitfame/test/integration/testdata/good/3/expected.out
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
Name,Lines,Commits,Files
|
||||||
|
Rober Griesemer,1,1,1
|
5
gitfame/test/integration/testdata/good/4/description.yaml
vendored
Normal file
5
gitfame/test/integration/testdata/good/4/description.yaml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# .md with single line, filtered out with --extensions
|
||||||
|
|
||||||
|
name: single file, extensions filter
|
||||||
|
args: [--format, csv, --revision, a7b4f155866102b0559392440f4217bc3c19bf62, --extensions, .go]
|
||||||
|
bundle: simple.bundle
|
1
gitfame/test/integration/testdata/good/4/expected.out
vendored
Normal file
1
gitfame/test/integration/testdata/good/4/expected.out
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Name,Lines,Commits,Files
|
5
gitfame/test/integration/testdata/good/5/description.yaml
vendored
Normal file
5
gitfame/test/integration/testdata/good/5/description.yaml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# .md with single line, filtered out with --languages
|
||||||
|
|
||||||
|
name: single file, languages filter
|
||||||
|
args: [--format, csv, --revision, a7b4f155866102b0559392440f4217bc3c19bf62, --languages, c++]
|
||||||
|
bundle: simple.bundle
|
1
gitfame/test/integration/testdata/good/5/expected.out
vendored
Normal file
1
gitfame/test/integration/testdata/good/5/expected.out
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Name,Lines,Commits,Files
|
5
gitfame/test/integration/testdata/good/6/description.yaml
vendored
Normal file
5
gitfame/test/integration/testdata/good/6/description.yaml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# .md with single line, excluded
|
||||||
|
|
||||||
|
name: single file excluded
|
||||||
|
args: [--format, csv, --revision, a7b4f155866102b0559392440f4217bc3c19bf62, --exclude, read*]
|
||||||
|
bundle: simple.bundle
|
1
gitfame/test/integration/testdata/good/6/expected.out
vendored
Normal file
1
gitfame/test/integration/testdata/good/6/expected.out
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Name,Lines,Commits,Files
|
5
gitfame/test/integration/testdata/good/7/description.yaml
vendored
Normal file
5
gitfame/test/integration/testdata/good/7/description.yaml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# .md + .go x 2
|
||||||
|
|
||||||
|
name: HEAD^1
|
||||||
|
args: [--format, csv, --revision, HEAD^1]
|
||||||
|
bundle: simple.bundle
|
3
gitfame/test/integration/testdata/good/7/expected.out
vendored
Normal file
3
gitfame/test/integration/testdata/good/7/expected.out
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
Name,Lines,Commits,Files
|
||||||
|
Rob Pike,7,3,2
|
||||||
|
Brad Fitzpatrick,1,1,1
|
5
gitfame/test/integration/testdata/good/8/description.yaml
vendored
Normal file
5
gitfame/test/integration/testdata/good/8/description.yaml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# .md + .go x 2, tag,
|
||||||
|
|
||||||
|
name: tag
|
||||||
|
args: [--format, csv, --revision, v1.0]
|
||||||
|
bundle: simple.bundle
|
3
gitfame/test/integration/testdata/good/8/expected.out
vendored
Normal file
3
gitfame/test/integration/testdata/good/8/expected.out
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
Name,Lines,Commits,Files
|
||||||
|
Rob Pike,12,4,3
|
||||||
|
Brad Fitzpatrick,1,1,1
|
5
gitfame/test/integration/testdata/good/9/description.yaml
vendored
Normal file
5
gitfame/test/integration/testdata/good/9/description.yaml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# .md + .go x 2, tag, --use-committer
|
||||||
|
|
||||||
|
name: tag committer
|
||||||
|
args: [--format, csv, --revision, v1.0, --use-committer]
|
||||||
|
bundle: simple.bundle
|
4
gitfame/test/integration/testdata/good/9/expected.out
vendored
Normal file
4
gitfame/test/integration/testdata/good/9/expected.out
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
Name,Lines,Commits,Files
|
||||||
|
Rob Pike,7,3,2
|
||||||
|
Randall77,5,1,1
|
||||||
|
Brad Fitzpatrick,1,1,1
|
Loading…
Reference in a new issue