Add systemd resource budgets with TOML profiles
This commit is contained in:
commit
be8749a384
1 changed files with 2591 additions and 0 deletions
75
internal/budget/fake_test.go
Normal file
75
internal/budget/fake_test.go
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
package budget
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/godbus/dbus/v5"
|
||||
)
|
||||
|
||||
type fakeCtl struct {
|
||||
units []unit
|
||||
groups map[string]string
|
||||
states map[string]unitState
|
||||
sets map[string][]property
|
||||
starts map[string][]property
|
||||
stops []string
|
||||
stateErr map[string]error
|
||||
startErr error
|
||||
setErr error
|
||||
events *[]string
|
||||
onStart func(string, []property)
|
||||
}
|
||||
|
||||
func newFake() *fakeCtl {
|
||||
return &fakeCtl{groups: map[string]string{}, states: map[string]unitState{}, sets: map[string][]property{}, starts: map[string][]property{}, stateErr: map[string]error{}}
|
||||
}
|
||||
|
||||
func (f *fakeCtl) Units() ([]unit, error) { return f.units, nil }
|
||||
func (f *fakeCtl) Group(name string) (string, error) { return f.groups[name], nil }
|
||||
func (f *fakeCtl) Set(name string, props []property) error {
|
||||
if f.events != nil {
|
||||
*f.events = append(*f.events, "set "+name)
|
||||
}
|
||||
f.sets[name] = props
|
||||
return f.setErr
|
||||
}
|
||||
func (f *fakeCtl) Start(name string, props []property) error {
|
||||
if f.startErr != nil {
|
||||
return f.startErr
|
||||
}
|
||||
f.starts[name] = props
|
||||
f.states[name] = unitState{Active: "activating"}
|
||||
if f.onStart != nil {
|
||||
f.onStart(name, props)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (f *fakeCtl) State(name string) (unitState, error) {
|
||||
if err := f.stateErr[name]; err != nil {
|
||||
return unitState{}, err
|
||||
}
|
||||
if state, ok := f.states[name]; ok {
|
||||
return state, nil
|
||||
}
|
||||
return unitState{}, dbus.Error{Name: noUnit}
|
||||
}
|
||||
func (f *fakeCtl) Stop(name string) error { f.stops = append(f.stops, name); return nil }
|
||||
|
||||
type fakeProcs struct {
|
||||
tasks map[uint32]task
|
||||
groups map[uint32]string
|
||||
}
|
||||
|
||||
type failWriter struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func (w failWriter) Write([]byte) (int, error) { return 0, w.err }
|
||||
|
||||
func (f fakeProcs) Snapshot(config) (map[uint32]task, error) { return f.tasks, nil }
|
||||
func (f fakeProcs) Group(pid uint32) (string, error) {
|
||||
if group, ok := f.groups[pid]; ok {
|
||||
return group, nil
|
||||
}
|
||||
return "", os.ErrNotExist
|
||||
}
|
||||
Loading…
Reference in a new issue