Check if pg_dump is available before running database export
This commit is contained in:
@@ -11,6 +11,11 @@ type Dump struct {
|
||||
Table string
|
||||
}
|
||||
|
||||
func (d *Dump) CanExport() bool {
|
||||
err := exec.Command("pg_dump", "--version").Run()
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (d *Dump) Export(url string, writer io.Writer) error {
|
||||
errOutput := bytes.NewBuffer(nil)
|
||||
|
||||
|
||||
@@ -24,8 +24,12 @@ func test_DumpExport(t *testing.T) {
|
||||
os.Remove(savePath)
|
||||
}()
|
||||
|
||||
// Test full db dump
|
||||
dump := Dump{}
|
||||
|
||||
// Test for pg_dump presence
|
||||
assert.True(t, dump.CanExport())
|
||||
|
||||
// Test full db dump
|
||||
err = dump.Export(url, saveFile)
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user