Skip to content

Commit

Permalink
🐞 fix: handle db collection w/ dash in regex #61
Browse files Browse the repository at this point in the history
  • Loading branch information
maxisam committed Sep 9, 2023
1 parent 291d005 commit 0a36377
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/backup/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func dump(plan config.Plan, tmpPath string, ts time.Time) (string, string, error

func getDumpedDocMap(output string) map[string]string {
result := map[string]string{}
dbDocCapRegex := `done dumping\s\w*\.(\S*)\s\((\d*).document`
dbDocCapRegex := `done dumping\s[\w,-]*\.(\S*)\s\((\d*).document`
reg := regexp.MustCompile(dbDocCapRegex)
lines := strings.Split(output, "\n")

Expand Down
19 changes: 19 additions & 0 deletions pkg/backup/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,22 @@ func Test_getDumpedDocMap(t *testing.T) {
// test "." in the collection name
assert.Equal(t, strconv.Itoa(1), result["Contents.Published_Count"])
}

func Test_getDumpedDocMapWithDash(t *testing.T) {
dumpOutput := []byte(`2022-09-12T23:00:00.102+0000 writing db-collection.Contents_Published to archive '/tmp/content-1663023600.gz'
2022-09-12T23:00:00.102+0000 writing db-collection.Contents_Count to archive '/tmp/content-1663023600.gz'
2022-09-12T23:00:00.102+0000 writing db-collection.Contents_Published_Count to archive '/tmp/content-1663023600.gz'
2022-09-12T23:00:00.116+0000 writing db-collection.Contents_All to archive '/tmp/content-1663023600.gz'
2022-09-12T23:00:00.128+0000 done dumping db-collection.Contents.Published_Count (1 document)
2022-09-12T23:00:00.140+0000 done dumping db-collection.Contents_Count (3 documents)
2022-09-12T23:00:00.565+0000 done dumping db-collection.Contents_Published (7415 documents)
2022-09-12T23:00:03.010+0000 [####################....] db-collection.Contents_All 84357/99427 (84.8%)
2022-09-12T23:00:03.171+0000 [########################] db-collection.Contents_All 99427/99427 (100.0%)
2022-09-12T23:00:03.294+0000 done dumping db-collection.Contents_All (99427 documents)
`)
result := getDumpedDocMap(string(dumpOutput))
assert.Len(t, result, 4)
assert.Equal(t, strconv.Itoa(7415), result["Contents_Published"])
// test "." in the collection name
assert.Equal(t, strconv.Itoa(1), result["Contents.Published_Count"])
}

0 comments on commit 0a36377

Please sign in to comment.