accounting: populate transfer snapshot with "what" value
This commit is contained in:
@@ -176,6 +176,7 @@ Returns the following values:
|
||||
"size": size of the file in bytes,
|
||||
"bytes": total transferred bytes for this file,
|
||||
"checked": if the transfer is only checked (skipped, deleted),
|
||||
"what": the purpose of the transfer (transferring, deleting, checking, importing, hashing, merging, listing, moving, renaming),
|
||||
"timestamp": integer representing millisecond unix epoch,
|
||||
"error": string description of the error (empty if successful),
|
||||
"jobid": id of the job that this transfer belongs to
|
||||
|
||||
@@ -17,6 +17,7 @@ type TransferSnapshot struct {
|
||||
Size int64 `json:"size"`
|
||||
Bytes int64 `json:"bytes"`
|
||||
Checked bool `json:"checked"`
|
||||
What string `json:"what"`
|
||||
StartedAt time.Time `json:"started_at"`
|
||||
CompletedAt time.Time `json:"completed_at,omitempty"`
|
||||
Error error `json:"-"`
|
||||
@@ -184,11 +185,18 @@ func (tr *Transfer) Snapshot() TransferSnapshot {
|
||||
if tr.acc != nil {
|
||||
b, s = tr.acc.progress()
|
||||
}
|
||||
|
||||
what := tr.what
|
||||
if what == "" {
|
||||
what = "transferring"
|
||||
}
|
||||
|
||||
snapshot := TransferSnapshot{
|
||||
Name: tr.remote,
|
||||
Checked: tr.checking,
|
||||
Size: s,
|
||||
Bytes: b,
|
||||
Checked: tr.checking,
|
||||
What: what,
|
||||
StartedAt: tr.startedAt,
|
||||
CompletedAt: tr.completedAt,
|
||||
Error: tr.err,
|
||||
|
||||
@@ -31,6 +31,7 @@ func TestTransfer(t *testing.T) {
|
||||
assert.Equal(t, int64(0), snap.Size)
|
||||
assert.Equal(t, int64(0), snap.Bytes)
|
||||
assert.Equal(t, false, snap.Checked)
|
||||
assert.Equal(t, "transferring", snap.What)
|
||||
assert.Equal(t, false, snap.StartedAt.IsZero())
|
||||
assert.Equal(t, true, snap.CompletedAt.IsZero())
|
||||
assert.Equal(t, nil, snap.Error)
|
||||
@@ -46,6 +47,7 @@ func TestTransfer(t *testing.T) {
|
||||
assert.Equal(t, int64(0), snap.Size)
|
||||
assert.Equal(t, int64(0), snap.Bytes)
|
||||
assert.Equal(t, false, snap.Checked)
|
||||
assert.Equal(t, "transferring", snap.What)
|
||||
assert.Equal(t, false, snap.StartedAt.IsZero())
|
||||
assert.Equal(t, false, snap.CompletedAt.IsZero())
|
||||
assert.Equal(t, true, errors.Is(snap.Error, io.EOF))
|
||||
@@ -63,4 +65,21 @@ func TestTransfer(t *testing.T) {
|
||||
"dstFs": "dstFs:dstFs",
|
||||
}, out)
|
||||
})
|
||||
|
||||
t.Run("Snapshot checking transfer", func(t *testing.T) {
|
||||
ctr := newCheckingTransfer(s, o, "checking")
|
||||
snap := ctr.Snapshot()
|
||||
|
||||
assert.Equal(t, "obj", snap.Name)
|
||||
assert.Equal(t, int64(0), snap.Size)
|
||||
assert.Equal(t, int64(0), snap.Bytes)
|
||||
assert.Equal(t, true, snap.Checked)
|
||||
assert.Equal(t, "checking", snap.What)
|
||||
assert.Equal(t, false, snap.StartedAt.IsZero())
|
||||
assert.Equal(t, true, snap.CompletedAt.IsZero())
|
||||
assert.Equal(t, nil, snap.Error)
|
||||
assert.Equal(t, "", snap.Group)
|
||||
assert.Equal(t, "", snap.SrcFs)
|
||||
assert.Equal(t, "", snap.DstFs)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user