mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
The testhook post-test hooks only work if you use a TestMain to invoke them, otherwise the cleanups can be registered but never actually get run. This deletes the etcd sockets, and temp directories, that we created from our test runs. We also fix the test creating a temp file directly to create it in a TempDir (which gets cleaned up after the test), and fix the name of the top-level tests displayed in TestMain.
30 lines
567 B
Go
30 lines
567 B
Go
// Copyright 2021 Molecula Corp. All rights reserved.
|
|
package test_test
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"testing"
|
|
|
|
"net/http"
|
|
_ "net/http/pprof"
|
|
|
|
"github.com/molecula/featurebase/v3/testhook"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
l, err := net.Listen("tcp", "localhost:0")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
port := l.Addr().(*net.TCPAddr).Port
|
|
fmt.Printf("test/ TestMain: online stack-traces: curl http://localhost:%v/debug/pprof/goroutine?debug=2\n", port)
|
|
go func() {
|
|
err := http.Serve(l, nil)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}()
|
|
testhook.RunTestsWithHooks(m)
|
|
|
|
}
|