Skip to content

Commit 45e6f8d

Browse files
authored
Merge pull request #1 from MaxxtonGroup/bug-fixes
Bug fixes
2 parents 0d60788 + 2f87d2a commit 45e6f8d

4 files changed

Lines changed: 27 additions & 11 deletions

File tree

pkg/backup/elasticsearch-backup-provider.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import (
55
"fmt"
66
"log"
77
"sort"
8-
"strconv"
98
"strings"
109
"time"
1110

1211
"github.com/MaxxtonGroup/backup-validator/pkg/runtime"
12+
"github.com/dustin/go-humanize"
1313
)
1414

1515
type ElasticsearchBackupProvider struct {
@@ -91,12 +91,12 @@ func (p ElasticsearchBackupProvider) Restore(testName string, dir string, snapsh
9191
done := true
9292
for _, restore := range esRestores {
9393
if restore.Repository == "backup" && restore.Snapshot == snapshot.Name {
94-
bTotal, err := strconv.ParseInt(restore.BytesTotal, 10, 64)
94+
bTotal, err := humanize.ParseBytes(restore.BytesTotal)
9595
if err != nil {
9696
return err
9797
}
9898
bytesTotal += float64(bTotal)
99-
bRecovered, err := strconv.ParseInt(restore.BytesRecovered, 10, 64)
99+
bRecovered, err := humanize.ParseBytes(restore.BytesRecovered)
100100
if err != nil {
101101
return err
102102
}

pkg/backup/restic-backup-provider.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package backup
22

33
import (
4+
"bytes"
45
"encoding/json"
56
"io/ioutil"
67
"log"
@@ -79,14 +80,19 @@ func (p ResticBackupProvider) ListSnapshots(testName string, dir string) ([]*Sna
7980
}
8081
cmd.Env = env
8182

82-
output, err := cmd.Output()
83+
// Set output to Byte Buffers
84+
var outb, errb bytes.Buffer
85+
cmd.Stdout = &outb
86+
cmd.Stderr = &errb
87+
err := cmd.Run()
8388
if err != nil {
89+
log.Printf("[%s] Restic: %s", testName, errb.String())
8490
return nil, err
8591
}
8692

8793
// parse output
8894
resticSnapshots := make([]*ResticSnapshot, 0)
89-
err = json.Unmarshal(output, &resticSnapshots)
95+
err = json.Unmarshal(outb.Bytes(), &resticSnapshots)
9096
if err != nil {
9197
return nil, err
9298
}

pkg/format/postgresql-format-provider.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ func (p PostgresqlFormatProvider) Destroy(testName string, dir string) error {
3232

3333
func (p PostgresqlFormatProvider) ImportData(testName string, dir string, options []string) error {
3434
_, err := p.runtimeProvider.Exec(testName, "pg_restore", options...)
35-
log.Printf("[%s] Import complete\n", testName)
35+
if err != nil {
36+
log.Printf("[%s] Import Failed: %s", testName, err.Error())
37+
} else {
38+
log.Printf("[%s] Import complete", testName)
39+
}
3640
return err
3741
}
3842

pkg/runtime/docker-runtime-provider.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,14 @@ func (p DockerRuntimeProvider) Destroy(testName string, dir string) error {
118118
log.Printf("[%s] Dump docker container logs:%s", testName, *p.runtime.containerID)
119119
logCmd := exec.Command("docker", "logs", *p.runtime.containerID)
120120

121-
logs, err := logCmd.Output()
121+
logs, err := logCmd.CombinedOutput()
122122
if err != nil {
123123
log.Printf("Failed to get logs: %s", err)
124-
} else {
125124
println("output: " + string(logs))
125+
} else {
126+
for _, line := range strings.Split(string(logs), "\n") {
127+
log.Printf("[%s] logs: %s", testName, line)
128+
}
126129
}
127130
}
128131

@@ -166,17 +169,20 @@ func (p DockerRuntimeProvider) Exec(testName string, command string, args ...str
166169
if err != nil {
167170
return nil, err
168171
}
172+
stdErrSlurp, _ := ioutil.ReadAll(stderr)
173+
if err != nil {
174+
return nil, err
175+
}
169176

170177
if err := cmd.Wait(); err != nil {
171178
output := strings.TrimSpace(string(stdOutSlurp))
172179
if len(output) > 0 {
173-
log.Printf("[%s] %s", testName, output)
180+
log.Printf("[%s] exec: %s", testName, output)
174181
}
175182

176-
stdErrSlurp, _ := ioutil.ReadAll(stderr)
177183
errOutput := strings.TrimSpace(string(stdErrSlurp))
178184
if len(errOutput) > 0 {
179-
log.Printf("[%s] %s", testName, errOutput)
185+
log.Printf("[%s] exec: %s", testName, errOutput)
180186
}
181187
return nil, fmt.Errorf("command [%s %s] failed: %s", "docker", strings.Join(append(cmdArgs, args...), " "), err)
182188
}

0 commit comments

Comments
 (0)