forked from AdguardTeam/AdGuardHome
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull request: 2639 use testify require vol.2
Merge in DNS/adguard-home from 2639-testify-require-2 to master Updates AdguardTeam#2639. Squashed commit of the following: commit 31cc29a Author: Eugene Burkov <[email protected]> Date: Tue Feb 9 18:48:31 2021 +0300 all: deal with t.Run commit 484f477 Author: Eugene Burkov <[email protected]> Date: Tue Feb 9 17:44:02 2021 +0300 all: fix readability, imp tests commit 1231a82 Author: Eugene Burkov <[email protected]> Date: Tue Feb 9 16:06:29 2021 +0300 all: imp tests
- Loading branch information
1 parent
caa2e33
commit c7514a8
Showing
10 changed files
with
350 additions
and
274 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
Oops, something went wrong.