mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-08 22:31:04 +00:00
Command -generate should work on non-existent dir
This commit is contained in:
parent
0cc815d816
commit
b2ed32b118
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user