tests: spin off TestPasswd from TestInit

Also, capture all stderr and stdout but pass "-q".
This way we get to see error messages if there are any, or
spurious output when there should be none due to "-q".
This commit is contained in:
Jakob Unterwurzacher 2016-06-14 23:11:54 +02:00
parent a2c73cfde5
commit 218bf83ce3

View File

@ -3,8 +3,10 @@ package integration_tests
// Test CLI operations like "-init", "-password" etc // Test CLI operations like "-init", "-password" etc
import ( import (
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"testing" "testing"
"github.com/rfjakob/gocryptfs/internal/configfile" "github.com/rfjakob/gocryptfs/internal/configfile"
@ -15,35 +17,46 @@ import (
// Test -init flag // Test -init flag
func TestInit(t *testing.T) { func TestInit(t *testing.T) {
dir := test_helpers.TmpDir + "TestInit/" dir, err := ioutil.TempDir(test_helpers.TmpDir, "TestInit")
err := os.Mkdir(dir, 0777)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
cmd := exec.Command(test_helpers.GocryptfsBinary, "-init", "-extpass", "echo test", "-scryptn=10", dir) cmd := exec.Command(test_helpers.GocryptfsBinary, "-q", "-init", "-extpass", "echo test", "-scryptn=10", dir)
if testing.Verbose() { cmd.Stdout = os.Stdout
cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr
cmd.Stderr = os.Stderr
}
err = cmd.Run() err = cmd.Run()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
_, err = os.Stat(dir + configfile.ConfDefaultName) _, err = os.Stat(filepath.Join(dir, configfile.ConfDefaultName))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
}
// Test -passwd // Test -passwd flag
cmd2 := exec.Command(test_helpers.GocryptfsBinary, "-passwd", "-extpass", "echo test", dir) func TestPasswd(t *testing.T) {
if testing.Verbose() { // Create FS
cmd2.Stdout = os.Stdout dir, err := ioutil.TempDir(test_helpers.TmpDir, "TestPasswd")
cmd2.Stderr = os.Stderr if err != nil {
t.Fatal(err)
} }
cmd := exec.Command(test_helpers.GocryptfsBinary, "-q", "-init", "-extpass", "echo test", "-scryptn=10", dir)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
t.Fatal(err)
}
// Change password using "-extpass"
cmd2 := exec.Command(test_helpers.GocryptfsBinary, "-q", "-passwd", "-extpass", "echo test", dir)
cmd2.Stdout = os.Stdout
cmd2.Stderr = os.Stderr
err = cmd2.Run() err = cmd2.Run()
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
} }
// Test -init & -config flag // Test -init & -config flag
@ -54,12 +67,10 @@ func TestInitConfig(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
cmd := exec.Command(test_helpers.GocryptfsBinary, "-init", "-extpass", "echo test", cmd := exec.Command(test_helpers.GocryptfsBinary, "-q", "-init", "-extpass", "echo test",
"-config", config, "-scryptn=10", dir) "-config", config, "-scryptn=10", dir)
if testing.Verbose() { cmd.Stdout = os.Stdout
cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr
cmd.Stderr = os.Stderr
}
err = cmd.Run() err = cmd.Run()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -70,12 +81,10 @@ func TestInitConfig(t *testing.T) {
} }
// Test -passwd & -config // Test -passwd & -config
cmd2 := exec.Command(test_helpers.GocryptfsBinary, "-passwd", "-extpass", "echo test", cmd2 := exec.Command(test_helpers.GocryptfsBinary, "-q", "-passwd", "-extpass", "echo test",
"-config", config, dir) "-config", config, dir)
if testing.Verbose() { cmd2.Stdout = os.Stdout
cmd2.Stdout = os.Stdout cmd2.Stderr = os.Stderr
cmd2.Stderr = os.Stderr
}
err = cmd2.Run() err = cmd2.Run()
if err != nil { if err != nil {
t.Error(err) t.Error(err)
@ -89,12 +98,10 @@ func TestInitPlaintextNames(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
cmd := exec.Command(test_helpers.GocryptfsBinary, "-init", "-extpass", "echo test", cmd := exec.Command(test_helpers.GocryptfsBinary, "-q", "-init", "-extpass", "echo test",
"-scryptn=10", "-plaintextnames", dir) "-scryptn=10", "-plaintextnames", dir)
if testing.Verbose() { cmd.Stdout = os.Stdout
cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr
cmd.Stderr = os.Stderr
}
err = cmd.Run() err = cmd.Run()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)