Explorar o código

fix csv update, avoid existing file with empty file

Signed-off-by: r2k1 <yokree@gmail.com>
r2k1 %!s(int64=3) %!d(string=hai) anos
pai
achega
f6852e9813
Modificáronse 2 ficheiros con 4 adicións e 4 borrados
  1. 3 3
      pkg/costmodel/csv_export.go
  2. 1 1
      pkg/costmodel/csv_export_test.go

+ 3 - 3
pkg/costmodel/csv_export.go

@@ -96,18 +96,18 @@ func (e *csvExporter) Update(ctx context.Context) error {
 }
 
 func (e *csvExporter) updateExportCSV(ctx context.Context, previousExportTmp *os.File, allocationDates map[time.Time]struct{}, result *os.File) error {
-	csvDates, err := e.loadDates(previousExportTmp)
+	previousDates, err := e.loadDates(previousExportTmp)
 	if err != nil {
 		return err
 	}
 
-	for date := range csvDates {
+	for date := range previousDates {
 		delete(allocationDates, date)
 	}
 
 	if len(allocationDates) == 0 {
 		log.Info("export file in cloud storage already contain data for all dates, skipping update")
-		return nil
+		return errNoData
 	}
 
 	newExportTmp, err := os.CreateTemp("", "opencost-new-export-*.csv")

+ 1 - 1
pkg/costmodel/csv_export_test.go

@@ -121,7 +121,7 @@ func Test_UpdateCSV(t *testing.T) {
 			},
 		}
 		err := UpdateCSV(context.TODO(), storage, model)
-		require.NoError(t, err)
+		require.Equal(t, err, errNoData)
 		assert.Equal(t, string(storage.Data), data)
 		assert.Len(t, model.ComputeAllocationCalls(), 0)
 	})