-
Notifications
You must be signed in to change notification settings - Fork 2k
/
testing.go
50 lines (40 loc) · 1.49 KB
/
testing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package devicemanager
import (
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/plugins/base"
"github.com/hashicorp/nomad/plugins/device"
)
type ReserveFn func(d *structs.AllocatedDeviceResource) (*device.ContainerReservation, error)
type AllStatsFn func() []*device.DeviceGroupStats
type DeviceStatsFn func(d *structs.AllocatedDeviceResource) (*device.DeviceGroupStats, error)
func NoopReserve(*structs.AllocatedDeviceResource) (*device.ContainerReservation, error) {
return nil, nil
}
func NoopAllStats() []*device.DeviceGroupStats {
return nil
}
func NoopDeviceStats(*structs.AllocatedDeviceResource) (*device.DeviceGroupStats, error) {
return nil, nil
}
func NoopMockManager() *MockManager {
return &MockManager{
ReserveF: NoopReserve,
AllStatsF: NoopAllStats,
DeviceStatsF: NoopDeviceStats,
}
}
type MockManager struct {
ReserveF ReserveFn
AllStatsF AllStatsFn
DeviceStatsF DeviceStatsFn
}
func (m *MockManager) Run() {}
func (m *MockManager) Shutdown() {}
func (m *MockManager) PluginType() string { return base.PluginTypeDevice }
func (m *MockManager) AllStats() []*device.DeviceGroupStats { return m.AllStatsF() }
func (m *MockManager) Reserve(d *structs.AllocatedDeviceResource) (*device.ContainerReservation, error) {
return m.ReserveF(d)
}
func (m *MockManager) DeviceStats(d *structs.AllocatedDeviceResource) (*device.DeviceGroupStats, error) {
return m.DeviceStatsF(d)
}