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
1 changed files with 35 additions and 28 deletions

View File

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