github.com/tsuyoshiwada/git-prout@v0.0.0-20170402150409-5c51421d4bdb/helpers_test.go (about)

     1  package main
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"os/exec"
     7  	"path/filepath"
     8  )
     9  
    10  func checkPanic(err error) {
    11  	if err != nil {
    12  		panic(err)
    13  	}
    14  }
    15  
    16  func createTestRepo() func() {
    17  	var err error
    18  	tmpdir, err := ioutil.TempDir(".", "git-prout-test")
    19  	checkPanic(err)
    20  
    21  	prevdir, err := filepath.Abs(".")
    22  	checkPanic(err)
    23  
    24  	os.Chdir(tmpdir)
    25  
    26  	_, err = exec.Command("git", "init").Output()
    27  	checkPanic(err)
    28  
    29  	_, err = exec.Command("git", "config", "--local", "user.name", "'testuser'").Output()
    30  	checkPanic(err)
    31  	_, err = exec.Command("git", "config", "--local", "user.email", "'testuser@email.com'").Output()
    32  	checkPanic(err)
    33  
    34  	tmpfile := "README.md"
    35  	readme, err := os.Create(tmpfile)
    36  	checkPanic(err)
    37  	_, err = readme.WriteString("foo\n")
    38  	checkPanic(err)
    39  
    40  	_, err = exec.Command("git", "add", "-A").Output()
    41  	checkPanic(err)
    42  	_, err = exec.Command("git", "commit", "-m", "'testing'").Output()
    43  	checkPanic(err)
    44  	_, err = exec.Command("git", "remote", "add", "origin", "https://github.com/tsuyoshiwada/git-prout.git").Output()
    45  	checkPanic(err)
    46  
    47  	return func() {
    48  		os.Chdir(prevdir)
    49  		os.RemoveAll(tmpdir)
    50  	}
    51  }