[gitfame] Add tests.

This commit is contained in:
Arseny Balobanov 2021-02-28 20:35:21 +03:00
parent 7773e306d9
commit bf34e93d49
40 changed files with 283 additions and 0 deletions

View 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())
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,5 @@
# Empty .md file, old revision
name: empty file, old revision
args: [--format, csv, --revision, 49e9ed8b0c32adfa6b30ebe5d94d9d8811ba4d26]
bundle: simple.bundle

View file

@ -0,0 +1,2 @@
Name,Lines,Commits,Files
Russ Cox,0,1,1

View file

@ -0,0 +1,5 @@
# .md with space in name
name: space in filename
args: [--format, csv, --revision, d5e9958063725c54e82b2e77427bd0dcbaf43fef]
bundle: breaker.bundle

View file

@ -0,0 +1,2 @@
Name,Lines,Commits,Files
Brad Fitzpatrick,4,1,1

View 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

View file

@ -0,0 +1,2 @@
Name,Lines,Commits,Files
My name is Tabby,7,1,1

View 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

View file

@ -0,0 +1,2 @@
Name,Lines,Commits,Files
My name is Tabby,0,1,1

View 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

View file

@ -0,0 +1,3 @@
Name,Lines,Commits,Files
My name is Tabby,7,2,2
Brad Fitzpatrick,4,1,1

View 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

View 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

View file

@ -0,0 +1,5 @@
# go-cmp, HEAD
name: go-cmp HEAD
args: [--format, csv]
bundle: go-cmp.bundle

View 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

View file

@ -0,0 +1,5 @@
# go-cmp, HEAD, committer
name: go-cmp HEAD committer
args: [--format, csv, --use-committer]
bundle: go-cmp.bundle

View file

@ -0,0 +1,4 @@
Name,Lines,Commits,Files
GitHub,11199,100,55
Joe Tsai,3009,12,29
Ross Light,2,1,1

View 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

View 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

View 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

View 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

View file

@ -0,0 +1,5 @@
# Empty project
name: empty project
args: [--format, csv, --revision, dff562439f0406fb00229e3e95a8d2048f265683]
bundle: simple.bundle

View file

@ -0,0 +1 @@
Name,Lines,Commits,Files

View file

@ -0,0 +1,5 @@
# .md with single line
name: single line
args: [--format, csv, --revision, a7b4f155866102b0559392440f4217bc3c19bf62]
bundle: simple.bundle

View file

@ -0,0 +1,2 @@
Name,Lines,Commits,Files
Rober Griesemer,1,1,1

View 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

View file

@ -0,0 +1 @@
Name,Lines,Commits,Files

View 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

View file

@ -0,0 +1 @@
Name,Lines,Commits,Files

View file

@ -0,0 +1,5 @@
# .md with single line, excluded
name: single file excluded
args: [--format, csv, --revision, a7b4f155866102b0559392440f4217bc3c19bf62, --exclude, read*]
bundle: simple.bundle

View file

@ -0,0 +1 @@
Name,Lines,Commits,Files

View file

@ -0,0 +1,5 @@
# .md + .go x 2
name: HEAD^1
args: [--format, csv, --revision, HEAD^1]
bundle: simple.bundle

View file

@ -0,0 +1,3 @@
Name,Lines,Commits,Files
Rob Pike,7,3,2
Brad Fitzpatrick,1,1,1

View file

@ -0,0 +1,5 @@
# .md + .go x 2, tag,
name: tag
args: [--format, csv, --revision, v1.0]
bundle: simple.bundle

View file

@ -0,0 +1,3 @@
Name,Lines,Commits,Files
Rob Pike,12,4,3
Brad Fitzpatrick,1,1,1

View 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

View file

@ -0,0 +1,4 @@
Name,Lines,Commits,Files
Rob Pike,7,3,2
Randall77,5,1,1
Brad Fitzpatrick,1,1,1