mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-30 13:47:05 +02:00
Replaced ImportResult.ImportErrors with ImportResult.ImportLog
This commit is contained in:
parent
91f9b62db3
commit
8a2ddb7772
5 changed files with 55 additions and 13 deletions
|
@ -164,11 +164,24 @@ type ListensResult ExportResult[ListensList]
|
|||
|
||||
type LovesResult ExportResult[LovesList]
|
||||
|
||||
type LogEntryType string
|
||||
|
||||
const (
|
||||
Info LogEntryType = "Info"
|
||||
Warning LogEntryType = "Warning"
|
||||
Error LogEntryType = "Error"
|
||||
)
|
||||
|
||||
type LogEntry struct {
|
||||
Type LogEntryType
|
||||
Message string
|
||||
}
|
||||
|
||||
type ImportResult struct {
|
||||
TotalCount int
|
||||
ImportCount int
|
||||
LastTimestamp time.Time
|
||||
ImportErrors []string
|
||||
ImportLog []LogEntry
|
||||
|
||||
// Error is only set if an unrecoverable import error occurred
|
||||
Error error
|
||||
|
@ -185,7 +198,14 @@ func (i *ImportResult) Update(from ImportResult) {
|
|||
i.TotalCount = from.TotalCount
|
||||
i.ImportCount = from.ImportCount
|
||||
i.UpdateTimestamp(from.LastTimestamp)
|
||||
i.ImportErrors = append(i.ImportErrors, from.ImportErrors...)
|
||||
i.ImportLog = append(i.ImportLog, from.ImportLog...)
|
||||
}
|
||||
|
||||
func (i *ImportResult) Log(t LogEntryType, msg string) {
|
||||
i.ImportLog = append(i.ImportLog, LogEntry{
|
||||
Type: t,
|
||||
Message: msg,
|
||||
})
|
||||
}
|
||||
|
||||
type Progress struct {
|
||||
|
|
|
@ -117,23 +117,45 @@ func TestLovesListSort(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestImportResultUpdate(t *testing.T) {
|
||||
logEntry1 := models.LogEntry{
|
||||
Type: models.Warning,
|
||||
Message: "foo",
|
||||
}
|
||||
logEntry2 := models.LogEntry{
|
||||
Type: models.Error,
|
||||
Message: "bar",
|
||||
}
|
||||
result := models.ImportResult{
|
||||
TotalCount: 100,
|
||||
ImportCount: 20,
|
||||
LastTimestamp: time.Now(),
|
||||
ImportErrors: []string{"foo"},
|
||||
ImportLog: []models.LogEntry{logEntry1},
|
||||
}
|
||||
newResult := models.ImportResult{
|
||||
TotalCount: 120,
|
||||
ImportCount: 50,
|
||||
LastTimestamp: time.Now().Add(1 * time.Hour),
|
||||
ImportErrors: []string{"bar"},
|
||||
ImportLog: []models.LogEntry{logEntry2},
|
||||
}
|
||||
result.Update(newResult)
|
||||
assert.Equal(t, 120, result.TotalCount)
|
||||
assert.Equal(t, 50, result.ImportCount)
|
||||
assert.Equal(t, newResult.LastTimestamp, result.LastTimestamp)
|
||||
assert.Equal(t, []string{"foo", "bar"}, result.ImportErrors)
|
||||
assert.Equal(t, []models.LogEntry{logEntry1, logEntry2}, result.ImportLog)
|
||||
}
|
||||
|
||||
func TestImportResultLog(t *testing.T) {
|
||||
result := models.ImportResult{}
|
||||
result.Log(models.Warning, "foo")
|
||||
result.Log(models.Error, "bar")
|
||||
expected := []models.LogEntry{{
|
||||
Type: models.Warning,
|
||||
Message: "foo",
|
||||
}, {
|
||||
Type: models.Error,
|
||||
Message: "bar",
|
||||
}}
|
||||
assert.Equal(t, expected, result.ImportLog)
|
||||
}
|
||||
|
||||
func TestImportResultUpdateTimestamp(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue