diff --git a/statediff/publisher/csv.go b/statediff/publisher/csv.go index 01c7477cf..6ee62f7e8 100644 --- a/statediff/publisher/csv.go +++ b/statediff/publisher/csv.go @@ -22,16 +22,17 @@ var ( updatedAccountAction = "updated" ) -func createCSVFilePath(path string) string { +func createCSVFilePath(path, blockNumber string) string { now := time.Now() timeStamp := now.Format(timeStampFormat) - filePath := filepath.Join(path, timeStamp) + suffix := timeStamp + "-" + blockNumber + filePath := filepath.Join(path, suffix) filePath = filePath + ".csv" return filePath } func (p *publisher) publishStateDiffToCSV(sd builder.StateDiff) (string, error) { - filePath := createCSVFilePath(p.Config.Path) + filePath := createCSVFilePath(p.Config.Path, strconv.FormatInt(sd.BlockNumber, 10)) file, err := os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) if err != nil { diff --git a/statediff/publisher/publisher_test.go b/statediff/publisher/publisher_test.go index 5dae5a2f1..073e2cb0d 100644 --- a/statediff/publisher/publisher_test.go +++ b/statediff/publisher/publisher_test.go @@ -116,6 +116,10 @@ func testFileName(t *testing.T) { if !strings.HasPrefix(fileName, dir) { t.Errorf(testhelpers.TestFailureFormatString, t.Name(), dir, fileName) } + blockNumberWithFileExt := strconv.FormatInt(testhelpers.BlockNumber, 10) + ".csv" + if !strings.HasSuffix(fileName, blockNumberWithFileExt) { + t.Errorf(testhelpers.TestFailureFormatString, t.Name(), blockNumberWithFileExt, fileName) + } } func testColumnHeaders(t *testing.T) {