mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-07-28 21:38:51 +00:00
Avoid all os.Exit and log.Fatal (#1279)
* Avoid all os.Exit and log.Fatal * Exit test with 1 by default, to catch panic errors. * Fix log messages.
This commit is contained in:
@@ -16,11 +16,22 @@ import (
|
||||
var test_dbm TestDBManager = TestDBManager{}
|
||||
|
||||
func UnitTestRun(m *testing.M) {
|
||||
exitCode := 1
|
||||
defer func() {
|
||||
os.Exit(exitCode)
|
||||
}()
|
||||
|
||||
flag.Parse()
|
||||
os.Exit(m.Run())
|
||||
|
||||
exitCode = m.Run()
|
||||
}
|
||||
|
||||
func IntegrationTestRun(m *testing.M) {
|
||||
exitCode := 1
|
||||
defer func() {
|
||||
os.Exit(exitCode)
|
||||
}()
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if flags.Database {
|
||||
@@ -38,7 +49,7 @@ func IntegrationTestRun(m *testing.M) {
|
||||
terminateWorkers := executable_worker.Initialize()
|
||||
defer terminateWorkers()
|
||||
|
||||
os.Exit(m.Run())
|
||||
exitCode = m.Run()
|
||||
}
|
||||
|
||||
func FilesystemTest(t *testing.T) {
|
||||
|
||||
@@ -32,12 +32,12 @@ func ApiListenUrl() *url.URL {
|
||||
|
||||
listenPort, err := strconv.Atoi(listenPortStr)
|
||||
if err != nil {
|
||||
log.Fatalf("%s must be a number: '%s'\n%s", EnvListenPort.GetName(), listenPortStr, err)
|
||||
log.Panicf("%q must be a number %q: %v", EnvListenPort.GetName(), listenPortStr, err)
|
||||
}
|
||||
|
||||
apiUrl, err := url.Parse(fmt.Sprintf("http://%s:%d", listenAddr, listenPort))
|
||||
if err != nil {
|
||||
log.Fatalf("Could not format api url: %s", err)
|
||||
log.Panicf("Could not format api url: %v", err)
|
||||
}
|
||||
apiUrl.Path = apiPrefix
|
||||
|
||||
@@ -56,8 +56,8 @@ func ApiEndpointUrl() *url.URL {
|
||||
|
||||
apiEndpointURL, err := url.Parse(apiEndpointStr)
|
||||
if err != nil {
|
||||
log.Fatalf("ERROR: Environment variable %s is not a proper url (%s)",
|
||||
EnvAPIEndpoint.GetName(), EnvAPIEndpoint.GetValue())
|
||||
log.Panicf("ERROR: Environment variable %s is not a proper url (%s): %v",
|
||||
EnvAPIEndpoint.GetName(), EnvAPIEndpoint.GetValue(), err)
|
||||
}
|
||||
|
||||
if shouldServeUI {
|
||||
@@ -75,8 +75,8 @@ func UiEndpointUrl() *url.URL {
|
||||
|
||||
uiEndpointURL, err := url.Parse(EnvUIEndpoint.GetValue())
|
||||
if err != nil {
|
||||
log.Fatalf("ERROR: Environment variable %s is not a proper url (%s)",
|
||||
EnvUIEndpoint.GetName(), EnvUIEndpoint.GetValue())
|
||||
log.Panicf("ERROR: Environment variable %s is not a proper url (%s): %v",
|
||||
EnvUIEndpoint.GetName(), EnvUIEndpoint.GetValue(), err)
|
||||
}
|
||||
|
||||
return uiEndpointURL
|
||||
|
||||
@@ -23,7 +23,7 @@ func GenerateToken() string {
|
||||
|
||||
n, err := rand.Int(rand.Reader, charLen)
|
||||
if err != nil {
|
||||
log.Fatalf("Could not generate random number: %s\n", err)
|
||||
log.Panicf("Could not generate random number: %v", err)
|
||||
}
|
||||
b[i] = charset[n.Int64()]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user