mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-14 14:10:12 +01:00
Session report collection and report templates (#981)
* wip: notification stats * make report notifications optional * linting/documentation fixes * linting/documentation fixes * merge types.Container and container.Interface * smaller naming/format fixes * use typed image/container IDs * simplify notifier and update tests * add missed doc comments * lint fixes * remove unused constructors * rename old/new current/latest
This commit is contained in:
parent
d0ecc23d72
commit
e3dd8d688a
32 changed files with 853 additions and 598 deletions
46
internal/actions/mocks/progress.go
Normal file
46
internal/actions/mocks/progress.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package mocks
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/containrrr/watchtower/pkg/session"
|
||||
wt "github.com/containrrr/watchtower/pkg/types"
|
||||
)
|
||||
|
||||
// CreateMockProgressReport creates a mock report from a given set of container states
|
||||
// All containers will be given a unique ID and name based on its state and index
|
||||
func CreateMockProgressReport(states ...session.State) wt.Report {
|
||||
|
||||
stateNums := make(map[session.State]int)
|
||||
progress := session.Progress{}
|
||||
failed := make(map[wt.ContainerID]error)
|
||||
|
||||
for _, state := range states {
|
||||
index := stateNums[state]
|
||||
|
||||
switch state {
|
||||
case session.SkippedState:
|
||||
c, _ := CreateContainerForProgress(index, 41, "skip%d")
|
||||
progress.AddSkipped(c, errors.New("unpossible"))
|
||||
break
|
||||
case session.FreshState:
|
||||
c, _ := CreateContainerForProgress(index, 31, "frsh%d")
|
||||
progress.AddScanned(c, c.ImageID())
|
||||
break
|
||||
case session.UpdatedState:
|
||||
c, newImage := CreateContainerForProgress(index, 11, "updt%d")
|
||||
progress.AddScanned(c, newImage)
|
||||
progress.MarkForUpdate(c.ID())
|
||||
break
|
||||
case session.FailedState:
|
||||
c, newImage := CreateContainerForProgress(index, 21, "fail%d")
|
||||
progress.AddScanned(c, newImage)
|
||||
failed[c.ID()] = errors.New("accidentally the whole container")
|
||||
}
|
||||
|
||||
stateNums[state] = index + 1
|
||||
}
|
||||
progress.UpdateFailed(failed)
|
||||
|
||||
return progress.Report()
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue