Fix review suggestions

Signed-off-by: Vadim Markovtsev <vadim@sourced.tech>
This commit is contained in:
Vadim Markovtsev 2017-10-26 15:37:18 +02:00
parent 250519bb51
commit c97a180da5
3 changed files with 25 additions and 13 deletions

View File

@ -23,6 +23,7 @@ var (
overcomeLanguages []string
samples []*sample
samplesDir string
cloned bool
)
func TestMain(m *testing.M) {
@ -35,7 +36,9 @@ func TestMain(m *testing.M) {
if err := cloneLinguist(linguistURL); err != nil {
log.Fatal(err)
}
defer os.RemoveAll(filepath.Dir(samplesDir))
if cloned {
defer os.RemoveAll(filepath.Dir(samplesDir))
}
var err error
samples, err = getSamples(samplesDir)
@ -47,16 +50,23 @@ func TestMain(m *testing.M) {
}
func cloneLinguist(linguistURL string) error {
repoLinguist, err := ioutil.TempDir("", "linguist-")
if err != nil {
return err
repoLinguist := os.Getenv(linguistClonedEnvVar)
cloned = repoLinguist == ""
if cloned {
var err error
repoLinguist, err = ioutil.TempDir("", "linguist-")
if err != nil {
return err
}
}
samplesDir = filepath.Join(repoLinguist, "samples")
cmd := exec.Command("git", "clone", linguistURL, repoLinguist)
if err := cmd.Run(); err != nil {
return err
if cloned {
cmd := exec.Command("git", "clone", linguistURL, repoLinguist)
if err := cmd.Run(); err != nil {
return err
}
}
cwd, err := os.Getwd()
@ -68,7 +78,7 @@ func cloneLinguist(linguistURL string) error {
return err
}
cmd = exec.Command("git", "checkout", data.LinguistCommit)
cmd := exec.Command("git", "checkout", data.LinguistCommit)
if err := cmd.Run(); err != nil {
return err
}

View File

@ -15,6 +15,7 @@ import (
)
const linguistURL = "https://github.com/github/linguist.git"
const linguistClonedEnvVar = "ENRY_TEST_REPO"
type EnryTestSuite struct {
suite.Suite
@ -29,8 +30,8 @@ func TestEnryTestSuite(t *testing.T) {
func (s *EnryTestSuite) SetupSuite() {
var err error
s.repoLinguist = os.Getenv("ENRY_TEST_REPO")
s.cloned = len(s.repoLinguist) == 0
s.repoLinguist = os.Getenv(linguistClonedEnvVar)
s.cloned = s.repoLinguist == ""
if s.cloned {
s.repoLinguist, err = ioutil.TempDir("", "linguist-")
assert.NoError(s.T(), err)

View File

@ -13,7 +13,8 @@ import (
)
const (
linguistURL = "https://github.com/github/linguist.git"
linguistURL = "https://github.com/github/linguist.git"
linguistClonedEnvVar = "ENRY_TEST_REPO"
commit = "d5c8db3fb91963c4b2762ca2ea2ff7cfac109f68"
samplesDir = "samples"
languagesFile = "lib/linguist/languages.yml"
@ -89,8 +90,8 @@ func TestGeneratorTestSuite(t *testing.T) {
func (s *GeneratorTestSuite) SetupSuite() {
var err error
s.tmpLinguist = os.Getenv("ENRY_TEST_REPO")
s.cloned = len(s.tmpLinguist) == 0
s.tmpLinguist = os.Getenv(linguistClonedEnvVar)
s.cloned = s.tmpLinguist == ""
if s.cloned {
s.tmpLinguist, err = ioutil.TempDir("", "linguist-")
assert.NoError(s.T(), err)