diff --git a/cmd/backup_test.go b/cmd/backup_test.go new file mode 100644 index 000000000..cacd6510b --- /dev/null +++ b/cmd/backup_test.go @@ -0,0 +1,39 @@ +package cmd_test + +import ( + "strings" + "testing" + + "github.com/pilosa/pilosa/cmd" +) + +func TestBackupHelp(t *testing.T) { + output, err := ExecNewRootCommand(t, "backup", "--help") + if !strings.Contains(output, "Usage:") || + !strings.Contains(output, "Flags:") || + !strings.Contains(output, "pilosa backup") || err != nil { + t.Fatalf("Command 'backup --help' not working, err: '%v', output: '%s'", err, output) + } +} + +func TestBackupConfig(t *testing.T) { + tests := []commandTest{ + { + args: []string{"backup", "--output-file", "/somefile"}, + env: map[string]string{"PILOSA_HOST": "localhost:12345"}, + cfgFileContent: ` +database = "mydb" +frame = "f1" +`, + validation: func() error { + v := validator{} + v.Check(cmd.Backuper.Host, "localhost:12345") + v.Check(cmd.Backuper.Database, "mydb") + v.Check(cmd.Backuper.Frame, "f1") + v.Check(cmd.Backuper.Path, "/somefile") + return v.Error() + }, + }, + } + executeDry(t, tests) +} diff --git a/cmd/root_test.go b/cmd/root_test.go index b62a14bbf..7e132137f 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -112,6 +112,21 @@ func (ct *commandTest) reset() { } } +func executeDry(t *testing.T, tests []commandTest) { + for i, test := range tests { + test.args = append(test.args[:1], append([]string{"--dry-run"}, test.args[1:]...)...) + com := test.setupCommand(t) + err := com.Execute() + if err.Error() != "dry run" { + t.Fatalf("Problem with test %d, err: '%v'", i, err) + } + if err := test.validation(); err != nil { + t.Fatalf("Failed test %d due to: %v", i, err) + } + test.reset() + } +} + func TestRootCommand(t *testing.T) { outStr, err := ExecNewRootCommand(t, "--help") if !strings.Contains(outStr, "Usage:") ||