-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1231a82
commit 484f477
Showing
6 changed files
with
68 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package aghtest | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"runtime" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// PrepareTestDir returns the full path to temporary created directory and | ||
// registers the appropriate cleanup for *t. | ||
func PrepareTestDir(t *testing.T) (dir string) { | ||
t.Helper() | ||
|
||
wd, err := os.Getwd() | ||
require.Nil(t, err) | ||
|
||
dir, err = ioutil.TempDir(wd, "agh-test") | ||
require.Nil(t, err) | ||
require.NotEmpty(t, dir) | ||
|
||
t.Cleanup(func() { | ||
// TODO(e.burkov): Replace with t.TempDir methods after updating | ||
// go version to 1.15. | ||
start := time.Now() | ||
for { | ||
err := os.RemoveAll(dir) | ||
if err == nil { | ||
break | ||
} | ||
|
||
if runtime.GOOS != "windows" || time.Since(start) >= 500*time.Millisecond { | ||
break | ||
} | ||
time.Sleep(5 * time.Millisecond) | ||
} | ||
assert.Nil(t, err) | ||
}) | ||
|
||
return dir | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters