2015-04-02 00:34:32 +08:00
|
|
|
package system
|
|
|
|
|
|
2015-12-05 06:09:07 +08:00
|
|
|
import (
|
2017-04-19 02:42:58 +08:00
|
|
|
"os"
|
|
|
|
|
|
2015-12-05 06:09:07 +08:00
|
|
|
"github.com/stretchr/testify/mock"
|
2015-04-07 00:32:10 +08:00
|
|
|
|
2021-11-19 00:33:47 +08:00
|
|
|
"github.com/shirou/gopsutil/v3/cpu"
|
|
|
|
|
"github.com/shirou/gopsutil/v3/disk"
|
|
|
|
|
"github.com/shirou/gopsutil/v3/host"
|
2015-04-07 07:03:09 +08:00
|
|
|
|
2021-11-19 00:33:47 +08:00
|
|
|
"github.com/shirou/gopsutil/v3/load"
|
|
|
|
|
"github.com/shirou/gopsutil/v3/mem"
|
|
|
|
|
"github.com/shirou/gopsutil/v3/net"
|
2015-12-05 06:09:07 +08:00
|
|
|
)
|
2015-04-02 00:34:32 +08:00
|
|
|
|
|
|
|
|
type MockPS struct {
|
|
|
|
|
mock.Mock
|
2017-04-19 02:42:58 +08:00
|
|
|
PSDiskDeps
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type MockPSDisk struct {
|
2018-07-12 07:43:49 +08:00
|
|
|
*SystemPS
|
2017-04-19 02:42:58 +08:00
|
|
|
*mock.Mock
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-12 07:43:49 +08:00
|
|
|
type MockDiskUsage struct {
|
2017-04-19 02:42:58 +08:00
|
|
|
*mock.Mock
|
2015-04-02 00:34:32 +08:00
|
|
|
}
|
|
|
|
|
|
2016-05-19 22:05:08 +08:00
|
|
|
func (m *MockPS) LoadAvg() (*load.AvgStat, error) {
|
2015-04-02 00:34:32 +08:00
|
|
|
ret := m.Called()
|
|
|
|
|
|
2016-05-19 22:05:08 +08:00
|
|
|
r0 := ret.Get(0).(*load.AvgStat)
|
2015-04-02 00:34:32 +08:00
|
|
|
r1 := ret.Error(1)
|
|
|
|
|
|
|
|
|
|
return r0, r1
|
|
|
|
|
}
|
2015-12-05 06:09:07 +08:00
|
|
|
|
2021-03-23 01:21:36 +08:00
|
|
|
func (m *MockPS) CPUTimes(_, _ bool) ([]cpu.TimesStat, error) {
|
2015-04-07 00:32:10 +08:00
|
|
|
ret := m.Called()
|
|
|
|
|
|
2016-05-19 22:05:08 +08:00
|
|
|
r0 := ret.Get(0).([]cpu.TimesStat)
|
2015-04-07 00:32:10 +08:00
|
|
|
r1 := ret.Error(1)
|
|
|
|
|
|
|
|
|
|
return r0, r1
|
|
|
|
|
}
|
2015-12-05 06:09:07 +08:00
|
|
|
|
2016-12-06 01:42:36 +08:00
|
|
|
func (m *MockPS) DiskUsage(mountPointFilter []string, fstypeExclude []string) ([]*disk.UsageStat, []*disk.PartitionStat, error) {
|
2016-02-23 01:29:10 +08:00
|
|
|
ret := m.Called(mountPointFilter, fstypeExclude)
|
2015-04-07 01:34:55 +08:00
|
|
|
|
2016-05-19 22:05:08 +08:00
|
|
|
r0 := ret.Get(0).([]*disk.UsageStat)
|
2016-12-06 01:42:36 +08:00
|
|
|
r1 := ret.Get(1).([]*disk.PartitionStat)
|
|
|
|
|
r2 := ret.Error(2)
|
2015-04-07 01:34:55 +08:00
|
|
|
|
2016-12-06 01:42:36 +08:00
|
|
|
return r0, r1, r2
|
2015-04-07 01:34:55 +08:00
|
|
|
}
|
2015-12-05 06:09:07 +08:00
|
|
|
|
2016-05-19 22:05:08 +08:00
|
|
|
func (m *MockPS) NetIO() ([]net.IOCountersStat, error) {
|
2015-04-07 01:44:32 +08:00
|
|
|
ret := m.Called()
|
|
|
|
|
|
2016-05-19 22:05:08 +08:00
|
|
|
r0 := ret.Get(0).([]net.IOCountersStat)
|
2015-04-07 01:44:32 +08:00
|
|
|
r1 := ret.Error(1)
|
|
|
|
|
|
|
|
|
|
return r0, r1
|
|
|
|
|
}
|
2015-12-05 06:09:07 +08:00
|
|
|
|
2016-05-19 22:05:08 +08:00
|
|
|
func (m *MockPS) NetProto() ([]net.ProtoCountersStat, error) {
|
2015-12-05 06:09:07 +08:00
|
|
|
ret := m.Called()
|
|
|
|
|
|
2016-05-19 22:05:08 +08:00
|
|
|
r0 := ret.Get(0).([]net.ProtoCountersStat)
|
2015-12-05 06:09:07 +08:00
|
|
|
r1 := ret.Error(1)
|
|
|
|
|
|
|
|
|
|
return r0, r1
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-23 01:21:36 +08:00
|
|
|
func (m *MockPS) DiskIO(_ []string) (map[string]disk.IOCountersStat, error) {
|
2015-04-07 01:59:05 +08:00
|
|
|
ret := m.Called()
|
|
|
|
|
|
2016-05-19 22:05:08 +08:00
|
|
|
r0 := ret.Get(0).(map[string]disk.IOCountersStat)
|
2015-04-07 01:59:05 +08:00
|
|
|
r1 := ret.Error(1)
|
|
|
|
|
|
|
|
|
|
return r0, r1
|
|
|
|
|
}
|
2015-12-05 06:09:07 +08:00
|
|
|
|
2015-04-07 05:53:43 +08:00
|
|
|
func (m *MockPS) VMStat() (*mem.VirtualMemoryStat, error) {
|
|
|
|
|
ret := m.Called()
|
|
|
|
|
|
|
|
|
|
r0 := ret.Get(0).(*mem.VirtualMemoryStat)
|
|
|
|
|
r1 := ret.Error(1)
|
|
|
|
|
|
|
|
|
|
return r0, r1
|
|
|
|
|
}
|
2015-12-05 06:09:07 +08:00
|
|
|
|
2015-04-07 05:53:43 +08:00
|
|
|
func (m *MockPS) SwapStat() (*mem.SwapMemoryStat, error) {
|
|
|
|
|
ret := m.Called()
|
|
|
|
|
|
|
|
|
|
r0 := ret.Get(0).(*mem.SwapMemoryStat)
|
|
|
|
|
r1 := ret.Error(1)
|
|
|
|
|
|
|
|
|
|
return r0, r1
|
|
|
|
|
}
|
2015-12-05 06:09:07 +08:00
|
|
|
|
2018-09-11 02:52:15 +08:00
|
|
|
func (m *MockPS) Temperature() ([]host.TemperatureStat, error) {
|
|
|
|
|
ret := m.Called()
|
|
|
|
|
|
|
|
|
|
r0 := ret.Get(0).([]host.TemperatureStat)
|
|
|
|
|
r1 := ret.Error(1)
|
|
|
|
|
|
|
|
|
|
return r0, r1
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-19 22:05:08 +08:00
|
|
|
func (m *MockPS) NetConnections() ([]net.ConnectionStat, error) {
|
2015-10-08 21:55:34 +08:00
|
|
|
ret := m.Called()
|
|
|
|
|
|
2016-05-19 22:05:08 +08:00
|
|
|
r0 := ret.Get(0).([]net.ConnectionStat)
|
2015-10-08 21:55:34 +08:00
|
|
|
r1 := ret.Error(1)
|
|
|
|
|
|
|
|
|
|
return r0, r1
|
|
|
|
|
}
|
2017-04-19 02:42:58 +08:00
|
|
|
|
2018-07-12 07:43:49 +08:00
|
|
|
func (m *MockDiskUsage) Partitions(all bool) ([]disk.PartitionStat, error) {
|
2017-04-19 02:42:58 +08:00
|
|
|
ret := m.Called(all)
|
|
|
|
|
|
|
|
|
|
r0 := ret.Get(0).([]disk.PartitionStat)
|
|
|
|
|
r1 := ret.Error(1)
|
|
|
|
|
|
|
|
|
|
return r0, r1
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-12 07:43:49 +08:00
|
|
|
func (m *MockDiskUsage) OSGetenv(key string) string {
|
2017-04-19 02:42:58 +08:00
|
|
|
ret := m.Called(key)
|
|
|
|
|
return ret.Get(0).(string)
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-12 07:43:49 +08:00
|
|
|
func (m *MockDiskUsage) OSStat(name string) (os.FileInfo, error) {
|
2017-04-19 02:42:58 +08:00
|
|
|
ret := m.Called(name)
|
|
|
|
|
|
|
|
|
|
r0 := ret.Get(0).(os.FileInfo)
|
|
|
|
|
r1 := ret.Error(1)
|
|
|
|
|
|
|
|
|
|
return r0, r1
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-12 07:43:49 +08:00
|
|
|
func (m *MockDiskUsage) PSDiskUsage(path string) (*disk.UsageStat, error) {
|
2017-04-19 02:42:58 +08:00
|
|
|
ret := m.Called(path)
|
|
|
|
|
|
|
|
|
|
r0 := ret.Get(0).(*disk.UsageStat)
|
|
|
|
|
r1 := ret.Error(1)
|
|
|
|
|
|
|
|
|
|
return r0, r1
|
|
|
|
|
}
|