f-29: watchdog: add checksubnet #29
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
ea60c0db54
commit
0fa84b8320
7 changed files with 497 additions and 2 deletions
|
|
@ -7,10 +7,18 @@ import (
|
|||
"git.g3e.fr/syonad/two/internal/state"
|
||||
"git.g3e.fr/syonad/two/internal/watchdog/notify"
|
||||
"git.g3e.fr/syonad/two/pkg/db/kv"
|
||||
"git.g3e.fr/syonad/two/pkg/systemd"
|
||||
|
||||
"github.com/dgraph-io/badger/v4"
|
||||
)
|
||||
|
||||
func seedKV(t *testing.T, db *badger.DB, key, value string) {
|
||||
t.Helper()
|
||||
if err := kv.AddInDB(db, key, value); err != nil {
|
||||
t.Fatalf("seedKV %s: %v", key, err)
|
||||
}
|
||||
}
|
||||
|
||||
type notification struct {
|
||||
kind string
|
||||
name string
|
||||
|
|
@ -46,6 +54,47 @@ func (r *recorder) hasProblemContaining(substr string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
type fakeUnits struct {
|
||||
status map[string]*systemd.ServiceStatus
|
||||
err map[string]error
|
||||
asked []string
|
||||
}
|
||||
|
||||
var _ unitChecker = (*fakeUnits)(nil)
|
||||
|
||||
func newFakeUnits() *fakeUnits {
|
||||
return &fakeUnits{
|
||||
status: map[string]*systemd.ServiceStatus{},
|
||||
err: map[string]error{},
|
||||
}
|
||||
}
|
||||
|
||||
func (f *fakeUnits) active(unit string) *fakeUnits {
|
||||
f.status[unit] = &systemd.ServiceStatus{Name: unit, LoadState: "loaded", ActiveState: "active", SubState: "running"}
|
||||
return f
|
||||
}
|
||||
|
||||
func (f *fakeUnits) inactive(unit, sub string) *fakeUnits {
|
||||
f.status[unit] = &systemd.ServiceStatus{Name: unit, LoadState: "loaded", ActiveState: "inactive", SubState: sub}
|
||||
return f
|
||||
}
|
||||
|
||||
func (f *fakeUnits) failing(unit string, err error) *fakeUnits {
|
||||
f.err[unit] = err
|
||||
return f
|
||||
}
|
||||
|
||||
func (f *fakeUnits) Status(unit string) (*systemd.ServiceStatus, error) {
|
||||
f.asked = append(f.asked, unit)
|
||||
if err, ok := f.err[unit]; ok {
|
||||
return nil, err
|
||||
}
|
||||
if st, ok := f.status[unit]; ok {
|
||||
return st, nil
|
||||
}
|
||||
return &systemd.ServiceStatus{Name: unit, LoadState: "not-found", ActiveState: "inactive", SubState: "dead"}, nil
|
||||
}
|
||||
|
||||
func newTestDB(t *testing.T) *badger.DB {
|
||||
t.Helper()
|
||||
db := kv.InitDB(kv.Config{Path: t.TempDir()}, false)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue