Command -generate should work on non-existent dir

This commit is contained in:
Jakob Borg 2014-12-12 21:39:03 +01:00
parent 0cc815d816
commit b2ed32b118
2 changed files with 33 additions and 4 deletions

View File

@ -261,12 +261,15 @@ func main() {
}
info, err := os.Stat(dir)
if err != nil {
l.Fatalln("generate:", err)
}
if !info.IsDir() {
if err == nil && !info.IsDir() {
l.Fatalln(dir, "is not a directory")
}
if err!=nil&&os.IsNotExist(err){
err=os.MkdirAll(dir, 0700)
if err != nil {
l.Fatalln("generate:",err)
}
}
cert, err := loadCert(dir, "")
if err == nil {

View File

@ -54,3 +54,29 @@ func TestCLIReset(t *testing.T) {
}
}
}
func TestCLIGenerate(t *testing.T) {
err := os.RemoveAll("home.out")
if err != nil {
t.Fatal(err)
}
// -generate should create a bunch of stuff
cmd := exec.Command("../bin/syncthing", "-generate", "home.out")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stdout
err = cmd.Run()
if err != nil {
t.Fatal(err)
}
// Verify that the files that should have been created have been
for _, f := range []string{"home.out/config.xml", "home.out/cert.pem", "home.out/key.pem"} {
_, err := os.Stat(f)
if err != nil {
t.Errorf("%s is not correctly generated", f)
}
}
}