tests: use TestMain() instead of Init() to compile mock-dnf-json
Lets us have teardown code so we can clean up the temporary directory where the binary was built.
This commit is contained in:
parent
86536f11e7
commit
b56ff56189
3 changed files with 20 additions and 3 deletions
|
|
@ -31,7 +31,7 @@ import (
|
|||
var testState *TestState
|
||||
var dnfjsonPath string
|
||||
|
||||
func init() {
|
||||
func setupDNFJSON() string {
|
||||
// compile the mock-dnf-json binary to speed up tests
|
||||
tmpdir, err := os.MkdirTemp("", "")
|
||||
if err != nil {
|
||||
|
|
@ -42,6 +42,7 @@ func init() {
|
|||
if err := cmd.Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return tmpdir
|
||||
}
|
||||
|
||||
func executeTests(m *testing.M) int {
|
||||
|
|
@ -111,5 +112,7 @@ func executeTests(m *testing.M) int {
|
|||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
tmpdir := setupDNFJSON()
|
||||
defer os.RemoveAll(tmpdir)
|
||||
os.Exit(executeTests(m))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue