f-29: watchdog: add checkvpc #29
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
f05c4e1fce
commit
ea60c0db54
6 changed files with 457 additions and 0 deletions
61
internal/watchdog/helpers_test.go
Normal file
61
internal/watchdog/helpers_test.go
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
package watchdog
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.g3e.fr/syonad/two/internal/state"
|
||||
"git.g3e.fr/syonad/two/internal/watchdog/notify"
|
||||
"git.g3e.fr/syonad/two/pkg/db/kv"
|
||||
|
||||
"github.com/dgraph-io/badger/v4"
|
||||
)
|
||||
|
||||
type notification struct {
|
||||
kind string
|
||||
name string
|
||||
problem string
|
||||
}
|
||||
|
||||
type recorder struct {
|
||||
calls []notification
|
||||
}
|
||||
|
||||
var _ notify.Notifier = (*recorder)(nil)
|
||||
|
||||
func (r *recorder) Notify(kind, name, problem string) {
|
||||
r.calls = append(r.calls, notification{kind: kind, name: name, problem: problem})
|
||||
}
|
||||
|
||||
func (r *recorder) forName(name string) []notification {
|
||||
var out []notification
|
||||
for _, c := range r.calls {
|
||||
if c.name == name {
|
||||
out = append(out, c)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (r *recorder) hasProblemContaining(substr string) bool {
|
||||
for _, c := range r.calls {
|
||||
if strings.Contains(c.problem, substr) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func newTestDB(t *testing.T) *badger.DB {
|
||||
t.Helper()
|
||||
db := kv.InitDB(kv.Config{Path: t.TempDir()}, false)
|
||||
t.Cleanup(func() { db.Close() })
|
||||
return db
|
||||
}
|
||||
|
||||
func seedResource(t *testing.T, db *badger.DB, prefix, name string, s state.State) {
|
||||
t.Helper()
|
||||
if err := state.Set(db, prefix+name, s); err != nil {
|
||||
t.Fatalf("seedResource %s%s: %v", prefix, name, err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue