Remove duplicate code in command tests
This commit is contained in:
parent
e26879425f
commit
07ed716279
3 changed files with 190 additions and 213 deletions
|
|
@ -8,25 +8,6 @@ import (
|
|||
"gitlab.com/revalus/grm/config"
|
||||
)
|
||||
|
||||
func createTempDir() string {
|
||||
checkErrorDuringPreparation := func(err error) {
|
||||
if err != nil {
|
||||
fmt.Printf("Cannot prepare a temporary directory for testing! %v ", err.Error())
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
|
||||
baseTmp := fmt.Sprintf("%v/grmTest", os.TempDir())
|
||||
if _, ok := os.Stat(baseTmp); ok != nil {
|
||||
err := os.Mkdir(baseTmp, 0777)
|
||||
checkErrorDuringPreparation(err)
|
||||
}
|
||||
tempDir, err := os.MkdirTemp(baseTmp, "*")
|
||||
checkErrorDuringPreparation(err)
|
||||
|
||||
return tempDir
|
||||
}
|
||||
|
||||
func TestSyncInit(t *testing.T) {
|
||||
sync := NewSynchronizer("test")
|
||||
if sync.workspace != "test" {
|
||||
|
|
@ -36,10 +17,7 @@ func TestSyncInit(t *testing.T) {
|
|||
|
||||
func TestSyncCommand(t *testing.T) {
|
||||
|
||||
workdir := createTempDir()
|
||||
defer func() {
|
||||
os.RemoveAll(workdir)
|
||||
}()
|
||||
workdir := createTmpDir()
|
||||
|
||||
sync := Synchronizer{
|
||||
workspace: workdir,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue