From cc5d5a3fcdabca0ecd86646091c545509351dbbe Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Mon, 6 Jun 2016 22:30:39 +0200 Subject: tests: error out properly on mount failure In TestMain we call os.Exit as before, but inside actual tests we now call t.Fatal(). --- integration_tests/helpers.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'integration_tests/helpers.go') diff --git a/integration_tests/helpers.go b/integration_tests/helpers.go index bdb781f..4881a4b 100644 --- a/integration_tests/helpers.go +++ b/integration_tests/helpers.go @@ -60,7 +60,7 @@ func resetTmpDir(plaintextNames bool) { } // mount CIPHERDIR "c" on PLAINDIR "p" -func mount(c string, p string, extraArgs ...string) { +func mount(c string, p string, extraArgs ...string) error { var args []string args = append(args, extraArgs...) args = append(args, "-nosyslog", "-q", "-wpanic") @@ -70,16 +70,27 @@ func mount(c string, p string, extraArgs ...string) { args = append(args, p) cmd := exec.Command(gocryptfsBinary, args...) cmd.Stderr = os.Stderr - if testing.Verbose() { - cmd.Stdout = os.Stdout - } - err := cmd.Run() + cmd.Stdout = os.Stdout + return cmd.Run() +} + +// mountOrExit calls mount() and exits on failure. +func mountOrExit(c string, p string, extraArgs ...string) { + err := mount(c, p, extraArgs...) if err != nil { - fmt.Println(err) + fmt.Printf("mount failed: %v", err) os.Exit(1) } } +// mountOrFatal calls mount() and calls t.Fatal() on failure. +func mountOrFatal(t *testing.T, c string, p string, extraArgs ...string) { + err := mount(c, p, extraArgs...) + if err != nil { + t.Fatal(fmt.Errorf("mount failed: %v", err)) + } +} + // unmount PLAINDIR "p" func unmount(p string) error { fu := exec.Command("fusermount", "-u", "-z", p) -- cgit v1.2.3