[Fix Fix pack blob parse in TestRestoreFail
Fix parsing of pack blob ID by using a specific regex
instead of a strings.Contains. This prevents the test from
misidentifying other blob IDs as pack blobs, such as
`kopia.maintenance`.
package endtoend_test
import (
+ "fmt"
"path/filepath"
+ "regexp"
"strings"
"testing"
@@ -52,14 +54,7 @@ func TestRestoreFail(t *testing.T) {
newBlobIDs := getNewBlobIDs(beforeBlobList, afterBlobList)
- var blobIDToDelete string
-
- for _, blobID := range newBlobIDs {
- if strings.Contains(blobID, string(content.PackBlobIDPrefixRegular)) {
- blobIDToDelete = blobID
- }
- }
-
+ blobIDToDelete := findPackBlob(newBlobIDs)
if blobIDToDelete == "" {
t.Fatal("Could not find a pack blob in the list of blobs created by snapshot")
}
@@ -71,6 +66,21 @@ func TestRestoreFail(t *testing.T) {
e.RunAndExpectFailure(t, "snapshot", "restore", snapID, targetDir)
}
+func findPackBlob(blobIDs []string) string {
+ // Pattern to match "p" followed by hexadecimal digits
+ // Ex) "pd4c69d72b75a9d3d7d9da21096c6b60a"
+ patternStr := fmt.Sprintf("^%s[0-9a-f]+$", content.PackBlobIDPrefixRegular)
+ pattern := regexp.MustCompile(patternStr)
+
+ for _, blobID := range blobIDs {
+ if pattern.MatchString(blobID) {
+ return blobID
+ }
+ }
+
+ return ""
+}
+
func getNewBlobIDs(before, after []string) []string {
newIDMap := make(map[string]struct{})
