mirror of https://github.com/grafana/grafana
Unistore Chore: Add OTEL testing harness (#94835)
* add testing harness * fix mockery and linters * fix data race in tests * fix data race in tests * reduce cardinality of datapull/94863/head
parent
8b9bb2acf6
commit
cf08f6762d
@ -0,0 +1,132 @@ |
||||
// Code generated by mockery v2.43.1. DO NOT EDIT.
|
||||
|
||||
package mocks |
||||
|
||||
import mock "github.com/stretchr/testify/mock" |
||||
|
||||
// Row is an autogenerated mock type for the Row type
|
||||
type Row struct { |
||||
mock.Mock |
||||
} |
||||
|
||||
type Row_Expecter struct { |
||||
mock *mock.Mock |
||||
} |
||||
|
||||
func (_m *Row) EXPECT() *Row_Expecter { |
||||
return &Row_Expecter{mock: &_m.Mock} |
||||
} |
||||
|
||||
// Err provides a mock function with given fields:
|
||||
func (_m *Row) Err() error { |
||||
ret := _m.Called() |
||||
|
||||
if len(ret) == 0 { |
||||
panic("no return value specified for Err") |
||||
} |
||||
|
||||
var r0 error |
||||
if rf, ok := ret.Get(0).(func() error); ok { |
||||
r0 = rf() |
||||
} else { |
||||
r0 = ret.Error(0) |
||||
} |
||||
|
||||
return r0 |
||||
} |
||||
|
||||
// Row_Err_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Err'
|
||||
type Row_Err_Call struct { |
||||
*mock.Call |
||||
} |
||||
|
||||
// Err is a helper method to define mock.On call
|
||||
func (_e *Row_Expecter) Err() *Row_Err_Call { |
||||
return &Row_Err_Call{Call: _e.mock.On("Err")} |
||||
} |
||||
|
||||
func (_c *Row_Err_Call) Run(run func()) *Row_Err_Call { |
||||
_c.Call.Run(func(args mock.Arguments) { |
||||
run() |
||||
}) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *Row_Err_Call) Return(_a0 error) *Row_Err_Call { |
||||
_c.Call.Return(_a0) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *Row_Err_Call) RunAndReturn(run func() error) *Row_Err_Call { |
||||
_c.Call.Return(run) |
||||
return _c |
||||
} |
||||
|
||||
// Scan provides a mock function with given fields: dest
|
||||
func (_m *Row) Scan(dest ...interface{}) error { |
||||
var _ca []interface{} |
||||
_ca = append(_ca, dest...) |
||||
ret := _m.Called(_ca...) |
||||
|
||||
if len(ret) == 0 { |
||||
panic("no return value specified for Scan") |
||||
} |
||||
|
||||
var r0 error |
||||
if rf, ok := ret.Get(0).(func(...interface{}) error); ok { |
||||
r0 = rf(dest...) |
||||
} else { |
||||
r0 = ret.Error(0) |
||||
} |
||||
|
||||
return r0 |
||||
} |
||||
|
||||
// Row_Scan_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Scan'
|
||||
type Row_Scan_Call struct { |
||||
*mock.Call |
||||
} |
||||
|
||||
// Scan is a helper method to define mock.On call
|
||||
// - dest ...interface{}
|
||||
func (_e *Row_Expecter) Scan(dest ...interface{}) *Row_Scan_Call { |
||||
return &Row_Scan_Call{Call: _e.mock.On("Scan", |
||||
append([]interface{}{}, dest...)...)} |
||||
} |
||||
|
||||
func (_c *Row_Scan_Call) Run(run func(dest ...interface{})) *Row_Scan_Call { |
||||
_c.Call.Run(func(args mock.Arguments) { |
||||
variadicArgs := make([]interface{}, len(args)-0) |
||||
for i, a := range args[0:] { |
||||
if a != nil { |
||||
variadicArgs[i] = a.(interface{}) |
||||
} |
||||
} |
||||
run(variadicArgs...) |
||||
}) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *Row_Scan_Call) Return(_a0 error) *Row_Scan_Call { |
||||
_c.Call.Return(_a0) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *Row_Scan_Call) RunAndReturn(run func(...interface{}) error) *Row_Scan_Call { |
||||
_c.Call.Return(run) |
||||
return _c |
||||
} |
||||
|
||||
// NewRow creates a new instance of Row. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
// The first argument is typically a *testing.T value.
|
||||
func NewRow(t interface { |
||||
mock.TestingT |
||||
Cleanup(func()) |
||||
}) *Row { |
||||
mock := &Row{} |
||||
mock.Mock.Test(t) |
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) }) |
||||
|
||||
return mock |
||||
} |
||||
@ -0,0 +1,267 @@ |
||||
// Code generated by mockery v2.43.1. DO NOT EDIT.
|
||||
|
||||
package mocks |
||||
|
||||
import mock "github.com/stretchr/testify/mock" |
||||
|
||||
// Rows is an autogenerated mock type for the Rows type
|
||||
type Rows struct { |
||||
mock.Mock |
||||
} |
||||
|
||||
type Rows_Expecter struct { |
||||
mock *mock.Mock |
||||
} |
||||
|
||||
func (_m *Rows) EXPECT() *Rows_Expecter { |
||||
return &Rows_Expecter{mock: &_m.Mock} |
||||
} |
||||
|
||||
// Close provides a mock function with given fields:
|
||||
func (_m *Rows) Close() error { |
||||
ret := _m.Called() |
||||
|
||||
if len(ret) == 0 { |
||||
panic("no return value specified for Close") |
||||
} |
||||
|
||||
var r0 error |
||||
if rf, ok := ret.Get(0).(func() error); ok { |
||||
r0 = rf() |
||||
} else { |
||||
r0 = ret.Error(0) |
||||
} |
||||
|
||||
return r0 |
||||
} |
||||
|
||||
// Rows_Close_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Close'
|
||||
type Rows_Close_Call struct { |
||||
*mock.Call |
||||
} |
||||
|
||||
// Close is a helper method to define mock.On call
|
||||
func (_e *Rows_Expecter) Close() *Rows_Close_Call { |
||||
return &Rows_Close_Call{Call: _e.mock.On("Close")} |
||||
} |
||||
|
||||
func (_c *Rows_Close_Call) Run(run func()) *Rows_Close_Call { |
||||
_c.Call.Run(func(args mock.Arguments) { |
||||
run() |
||||
}) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *Rows_Close_Call) Return(_a0 error) *Rows_Close_Call { |
||||
_c.Call.Return(_a0) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *Rows_Close_Call) RunAndReturn(run func() error) *Rows_Close_Call { |
||||
_c.Call.Return(run) |
||||
return _c |
||||
} |
||||
|
||||
// Err provides a mock function with given fields:
|
||||
func (_m *Rows) Err() error { |
||||
ret := _m.Called() |
||||
|
||||
if len(ret) == 0 { |
||||
panic("no return value specified for Err") |
||||
} |
||||
|
||||
var r0 error |
||||
if rf, ok := ret.Get(0).(func() error); ok { |
||||
r0 = rf() |
||||
} else { |
||||
r0 = ret.Error(0) |
||||
} |
||||
|
||||
return r0 |
||||
} |
||||
|
||||
// Rows_Err_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Err'
|
||||
type Rows_Err_Call struct { |
||||
*mock.Call |
||||
} |
||||
|
||||
// Err is a helper method to define mock.On call
|
||||
func (_e *Rows_Expecter) Err() *Rows_Err_Call { |
||||
return &Rows_Err_Call{Call: _e.mock.On("Err")} |
||||
} |
||||
|
||||
func (_c *Rows_Err_Call) Run(run func()) *Rows_Err_Call { |
||||
_c.Call.Run(func(args mock.Arguments) { |
||||
run() |
||||
}) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *Rows_Err_Call) Return(_a0 error) *Rows_Err_Call { |
||||
_c.Call.Return(_a0) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *Rows_Err_Call) RunAndReturn(run func() error) *Rows_Err_Call { |
||||
_c.Call.Return(run) |
||||
return _c |
||||
} |
||||
|
||||
// Next provides a mock function with given fields:
|
||||
func (_m *Rows) Next() bool { |
||||
ret := _m.Called() |
||||
|
||||
if len(ret) == 0 { |
||||
panic("no return value specified for Next") |
||||
} |
||||
|
||||
var r0 bool |
||||
if rf, ok := ret.Get(0).(func() bool); ok { |
||||
r0 = rf() |
||||
} else { |
||||
r0 = ret.Get(0).(bool) |
||||
} |
||||
|
||||
return r0 |
||||
} |
||||
|
||||
// Rows_Next_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Next'
|
||||
type Rows_Next_Call struct { |
||||
*mock.Call |
||||
} |
||||
|
||||
// Next is a helper method to define mock.On call
|
||||
func (_e *Rows_Expecter) Next() *Rows_Next_Call { |
||||
return &Rows_Next_Call{Call: _e.mock.On("Next")} |
||||
} |
||||
|
||||
func (_c *Rows_Next_Call) Run(run func()) *Rows_Next_Call { |
||||
_c.Call.Run(func(args mock.Arguments) { |
||||
run() |
||||
}) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *Rows_Next_Call) Return(_a0 bool) *Rows_Next_Call { |
||||
_c.Call.Return(_a0) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *Rows_Next_Call) RunAndReturn(run func() bool) *Rows_Next_Call { |
||||
_c.Call.Return(run) |
||||
return _c |
||||
} |
||||
|
||||
// NextResultSet provides a mock function with given fields:
|
||||
func (_m *Rows) NextResultSet() bool { |
||||
ret := _m.Called() |
||||
|
||||
if len(ret) == 0 { |
||||
panic("no return value specified for NextResultSet") |
||||
} |
||||
|
||||
var r0 bool |
||||
if rf, ok := ret.Get(0).(func() bool); ok { |
||||
r0 = rf() |
||||
} else { |
||||
r0 = ret.Get(0).(bool) |
||||
} |
||||
|
||||
return r0 |
||||
} |
||||
|
||||
// Rows_NextResultSet_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'NextResultSet'
|
||||
type Rows_NextResultSet_Call struct { |
||||
*mock.Call |
||||
} |
||||
|
||||
// NextResultSet is a helper method to define mock.On call
|
||||
func (_e *Rows_Expecter) NextResultSet() *Rows_NextResultSet_Call { |
||||
return &Rows_NextResultSet_Call{Call: _e.mock.On("NextResultSet")} |
||||
} |
||||
|
||||
func (_c *Rows_NextResultSet_Call) Run(run func()) *Rows_NextResultSet_Call { |
||||
_c.Call.Run(func(args mock.Arguments) { |
||||
run() |
||||
}) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *Rows_NextResultSet_Call) Return(_a0 bool) *Rows_NextResultSet_Call { |
||||
_c.Call.Return(_a0) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *Rows_NextResultSet_Call) RunAndReturn(run func() bool) *Rows_NextResultSet_Call { |
||||
_c.Call.Return(run) |
||||
return _c |
||||
} |
||||
|
||||
// Scan provides a mock function with given fields: dest
|
||||
func (_m *Rows) Scan(dest ...interface{}) error { |
||||
var _ca []interface{} |
||||
_ca = append(_ca, dest...) |
||||
ret := _m.Called(_ca...) |
||||
|
||||
if len(ret) == 0 { |
||||
panic("no return value specified for Scan") |
||||
} |
||||
|
||||
var r0 error |
||||
if rf, ok := ret.Get(0).(func(...interface{}) error); ok { |
||||
r0 = rf(dest...) |
||||
} else { |
||||
r0 = ret.Error(0) |
||||
} |
||||
|
||||
return r0 |
||||
} |
||||
|
||||
// Rows_Scan_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Scan'
|
||||
type Rows_Scan_Call struct { |
||||
*mock.Call |
||||
} |
||||
|
||||
// Scan is a helper method to define mock.On call
|
||||
// - dest ...interface{}
|
||||
func (_e *Rows_Expecter) Scan(dest ...interface{}) *Rows_Scan_Call { |
||||
return &Rows_Scan_Call{Call: _e.mock.On("Scan", |
||||
append([]interface{}{}, dest...)...)} |
||||
} |
||||
|
||||
func (_c *Rows_Scan_Call) Run(run func(dest ...interface{})) *Rows_Scan_Call { |
||||
_c.Call.Run(func(args mock.Arguments) { |
||||
variadicArgs := make([]interface{}, len(args)-0) |
||||
for i, a := range args[0:] { |
||||
if a != nil { |
||||
variadicArgs[i] = a.(interface{}) |
||||
} |
||||
} |
||||
run(variadicArgs...) |
||||
}) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *Rows_Scan_Call) Return(_a0 error) *Rows_Scan_Call { |
||||
_c.Call.Return(_a0) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *Rows_Scan_Call) RunAndReturn(run func(...interface{}) error) *Rows_Scan_Call { |
||||
_c.Call.Return(run) |
||||
return _c |
||||
} |
||||
|
||||
// NewRows creates a new instance of Rows. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
// The first argument is typically a *testing.T value.
|
||||
func NewRows(t interface { |
||||
mock.TestingT |
||||
Cleanup(func()) |
||||
}) *Rows { |
||||
mock := &Rows{} |
||||
mock.Mock.Test(t) |
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) }) |
||||
|
||||
return mock |
||||
} |
||||
@ -0,0 +1,142 @@ |
||||
// Code generated by mockery v2.43.1. DO NOT EDIT.
|
||||
|
||||
package mocks |
||||
|
||||
import mock "github.com/stretchr/testify/mock" |
||||
|
||||
// Result is an autogenerated mock type for the result type
|
||||
type Result struct { |
||||
mock.Mock |
||||
} |
||||
|
||||
type Result_Expecter struct { |
||||
mock *mock.Mock |
||||
} |
||||
|
||||
func (_m *Result) EXPECT() *Result_Expecter { |
||||
return &Result_Expecter{mock: &_m.Mock} |
||||
} |
||||
|
||||
// LastInsertId provides a mock function with given fields:
|
||||
func (_m *Result) LastInsertId() (int64, error) { |
||||
ret := _m.Called() |
||||
|
||||
if len(ret) == 0 { |
||||
panic("no return value specified for LastInsertId") |
||||
} |
||||
|
||||
var r0 int64 |
||||
var r1 error |
||||
if rf, ok := ret.Get(0).(func() (int64, error)); ok { |
||||
return rf() |
||||
} |
||||
if rf, ok := ret.Get(0).(func() int64); ok { |
||||
r0 = rf() |
||||
} else { |
||||
r0 = ret.Get(0).(int64) |
||||
} |
||||
|
||||
if rf, ok := ret.Get(1).(func() error); ok { |
||||
r1 = rf() |
||||
} else { |
||||
r1 = ret.Error(1) |
||||
} |
||||
|
||||
return r0, r1 |
||||
} |
||||
|
||||
// Result_LastInsertId_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LastInsertId'
|
||||
type Result_LastInsertId_Call struct { |
||||
*mock.Call |
||||
} |
||||
|
||||
// LastInsertId is a helper method to define mock.On call
|
||||
func (_e *Result_Expecter) LastInsertId() *Result_LastInsertId_Call { |
||||
return &Result_LastInsertId_Call{Call: _e.mock.On("LastInsertId")} |
||||
} |
||||
|
||||
func (_c *Result_LastInsertId_Call) Run(run func()) *Result_LastInsertId_Call { |
||||
_c.Call.Run(func(args mock.Arguments) { |
||||
run() |
||||
}) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *Result_LastInsertId_Call) Return(_a0 int64, _a1 error) *Result_LastInsertId_Call { |
||||
_c.Call.Return(_a0, _a1) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *Result_LastInsertId_Call) RunAndReturn(run func() (int64, error)) *Result_LastInsertId_Call { |
||||
_c.Call.Return(run) |
||||
return _c |
||||
} |
||||
|
||||
// RowsAffected provides a mock function with given fields:
|
||||
func (_m *Result) RowsAffected() (int64, error) { |
||||
ret := _m.Called() |
||||
|
||||
if len(ret) == 0 { |
||||
panic("no return value specified for RowsAffected") |
||||
} |
||||
|
||||
var r0 int64 |
||||
var r1 error |
||||
if rf, ok := ret.Get(0).(func() (int64, error)); ok { |
||||
return rf() |
||||
} |
||||
if rf, ok := ret.Get(0).(func() int64); ok { |
||||
r0 = rf() |
||||
} else { |
||||
r0 = ret.Get(0).(int64) |
||||
} |
||||
|
||||
if rf, ok := ret.Get(1).(func() error); ok { |
||||
r1 = rf() |
||||
} else { |
||||
r1 = ret.Error(1) |
||||
} |
||||
|
||||
return r0, r1 |
||||
} |
||||
|
||||
// Result_RowsAffected_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RowsAffected'
|
||||
type Result_RowsAffected_Call struct { |
||||
*mock.Call |
||||
} |
||||
|
||||
// RowsAffected is a helper method to define mock.On call
|
||||
func (_e *Result_Expecter) RowsAffected() *Result_RowsAffected_Call { |
||||
return &Result_RowsAffected_Call{Call: _e.mock.On("RowsAffected")} |
||||
} |
||||
|
||||
func (_c *Result_RowsAffected_Call) Run(run func()) *Result_RowsAffected_Call { |
||||
_c.Call.Run(func(args mock.Arguments) { |
||||
run() |
||||
}) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *Result_RowsAffected_Call) Return(_a0 int64, _a1 error) *Result_RowsAffected_Call { |
||||
_c.Call.Return(_a0, _a1) |
||||
return _c |
||||
} |
||||
|
||||
func (_c *Result_RowsAffected_Call) RunAndReturn(run func() (int64, error)) *Result_RowsAffected_Call { |
||||
_c.Call.Return(run) |
||||
return _c |
||||
} |
||||
|
||||
// NewResult creates a new instance of Result. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
// The first argument is typically a *testing.T value.
|
||||
func NewResult(t interface { |
||||
mock.TestingT |
||||
Cleanup(func()) |
||||
}) *Result { |
||||
mock := &Result{} |
||||
mock.Mock.Test(t) |
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) }) |
||||
|
||||
return mock |
||||
} |
||||
@ -0,0 +1,56 @@ |
||||
package mocks |
||||
|
||||
import ( |
||||
"reflect" |
||||
"testing" |
||||
|
||||
mock "github.com/stretchr/testify/mock" |
||||
) |
||||
|
||||
func NewRowWithValues(t *testing.T, values ...any) *Row { |
||||
row := NewRow(t) |
||||
row.EXPECT().Err().Return(nil).Once() // should check error
|
||||
ExpectRowValues(t, row, values...) |
||||
return row |
||||
} |
||||
|
||||
func ExpectRowValues(t *testing.T, row *Row, values ...any) *Row_Scan_Call { |
||||
return row.EXPECT().Scan(mock.Anything).RunAndReturn(func(dsts ...any) error { |
||||
scan(t, dsts, values) |
||||
return nil |
||||
}) |
||||
} |
||||
|
||||
func scan(t *testing.T, dsts, srcs []any) { |
||||
t.Helper() |
||||
if len(dsts) > len(srcs) { |
||||
t.Fatalf("%d destination values, but only %d source values", len(dsts), |
||||
len(srcs)) |
||||
return |
||||
} |
||||
|
||||
for i := range dsts { |
||||
src := reflect.ValueOf(srcs[i]) |
||||
if !src.IsValid() { |
||||
t.Fatalf("%d-eth value to be returned by the mocked db is"+ |
||||
" invalid: %#v", i, srcs[i]) |
||||
return |
||||
} |
||||
|
||||
dst := reflect.ValueOf(dsts[i]) |
||||
if !dst.IsValid() || dst.Kind() != reflect.Pointer { |
||||
t.Fatalf("%d-eth argument passed to Scan is invalid or not"+ |
||||
" a pointer: %#v", i, dsts[i]) |
||||
return |
||||
} |
||||
|
||||
dst = dst.Elem() // get element to which the pointer points to
|
||||
if !dst.CanSet() || !src.Type().AssignableTo(dst.Type()) { |
||||
t.Fatalf("%d-eth destination cannot be set, orcannot be assigned "+ |
||||
"the value; type of destination: %T; value that would be "+ |
||||
"assigned: %#v", i, dsts[i], srcs[i]) |
||||
return |
||||
} |
||||
dst.Set(src) |
||||
} |
||||
} |
||||
Loading…
Reference in new issue