2022-06-13 13:18:03 +00:00
|
|
|
package live_query_mock
|
2020-03-23 01:33:04 +00:00
|
|
|
|
|
|
|
import (
|
2022-06-13 13:18:03 +00:00
|
|
|
"testing"
|
|
|
|
|
2021-06-26 04:46:51 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
2020-03-23 01:33:04 +00:00
|
|
|
"github.com/stretchr/testify/mock"
|
|
|
|
)
|
|
|
|
|
2022-06-13 13:18:03 +00:00
|
|
|
// MockLiveQuery allows mocking a live query store.
|
2020-03-23 01:33:04 +00:00
|
|
|
type MockLiveQuery struct {
|
|
|
|
mock.Mock
|
2021-06-06 22:07:29 +00:00
|
|
|
fleet.LiveQueryStore
|
2020-03-23 01:33:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-13 13:18:03 +00:00
|
|
|
var _ fleet.LiveQueryStore = (*MockLiveQuery)(nil)
|
|
|
|
|
|
|
|
// New allocates a mocked live query store.
|
|
|
|
func New(t *testing.T) *MockLiveQuery {
|
|
|
|
m := new(MockLiveQuery)
|
|
|
|
m.Test(t)
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
// RunQuery mocks the live query store RunQuery method.
|
2020-03-23 01:33:04 +00:00
|
|
|
func (m *MockLiveQuery) RunQuery(name, sql string, hostIDs []uint) error {
|
|
|
|
args := m.Called(name, sql, hostIDs)
|
|
|
|
return args.Error(0)
|
|
|
|
}
|
|
|
|
|
2022-06-13 13:18:03 +00:00
|
|
|
// StopQuery mocks the live query store StopQuery method.
|
2020-03-23 01:33:04 +00:00
|
|
|
func (m *MockLiveQuery) StopQuery(name string) error {
|
|
|
|
args := m.Called(name)
|
|
|
|
return args.Error(0)
|
|
|
|
}
|
|
|
|
|
2022-06-13 13:18:03 +00:00
|
|
|
// QueriesForHost mocks the live query store QueriesForHost method.
|
2020-03-23 01:33:04 +00:00
|
|
|
func (m *MockLiveQuery) QueriesForHost(hostID uint) (map[string]string, error) {
|
|
|
|
args := m.Called(hostID)
|
|
|
|
return args.Get(0).(map[string]string), args.Error(1)
|
|
|
|
}
|
|
|
|
|
2022-06-13 13:18:03 +00:00
|
|
|
// QueryCompletedByHost mocks the live query store QueryCompletedByHost method.
|
2020-03-23 01:33:04 +00:00
|
|
|
func (m *MockLiveQuery) QueryCompletedByHost(name string, hostID uint) error {
|
|
|
|
args := m.Called(name, hostID)
|
|
|
|
return args.Error(0)
|
|
|
|
}
|