Stars: support running stars in mode 5 (#111754)
This commit is contained in:
@@ -1,56 +1,53 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana-app-sdk/logging"
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/services/apiserver"
|
||||
"github.com/grafana/grafana/pkg/services/apiserver/endpoints/request"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/star"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
type API struct {
|
||||
starService star.Service
|
||||
dashboardService dashboards.DashboardService
|
||||
logger log.Logger
|
||||
starService star.Service
|
||||
client K8sClients
|
||||
}
|
||||
|
||||
func ProvideApi(
|
||||
cfg *setting.Cfg, // for namespacer
|
||||
features featuremgmt.FeatureToggles,
|
||||
starService star.Service,
|
||||
dashboardService dashboards.DashboardService,
|
||||
configProvider apiserver.DirectRestConfigProvider,
|
||||
) *API {
|
||||
starLogger := log.New("stars.api")
|
||||
api := &API{
|
||||
starService: starService,
|
||||
dashboardService: dashboardService,
|
||||
logger: starLogger,
|
||||
if features.IsEnabledGlobally(featuremgmt.FlagKubernetesStars) {
|
||||
starService = nil // don't use it
|
||||
}
|
||||
return api
|
||||
}
|
||||
|
||||
func (api *API) getDashboardHelper(ctx context.Context, orgID int64, id int64, uid string) (*dashboards.Dashboard, response.Response) {
|
||||
var query dashboards.GetDashboardQuery
|
||||
|
||||
if len(uid) > 0 {
|
||||
query = dashboards.GetDashboardQuery{UID: uid, ID: id, OrgID: orgID}
|
||||
} else {
|
||||
query = dashboards.GetDashboardQuery{ID: id, OrgID: orgID}
|
||||
return &API{
|
||||
starService: starService,
|
||||
client: &k8sClients{
|
||||
namespacer: request.GetNamespaceMapper(cfg),
|
||||
configProvider: configProvider,
|
||||
},
|
||||
}
|
||||
|
||||
result, err := api.dashboardService.GetDashboard(ctx, &query)
|
||||
if err != nil {
|
||||
return nil, response.Error(http.StatusNotFound, "Dashboard not found", err)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (api *API) GetStars(c *contextmodel.ReqContext) response.Response {
|
||||
if api.starService == nil {
|
||||
stars, err := api.client.GetStars(c)
|
||||
if err != nil {
|
||||
logging.FromContext(c.Req.Context()).With("logger", "star.api").Warn("error", "err", err)
|
||||
}
|
||||
return response.JSON(http.StatusOK, stars)
|
||||
}
|
||||
|
||||
query := star.GetUserStarsQuery{
|
||||
UserID: c.UserID,
|
||||
}
|
||||
@@ -86,17 +83,25 @@ func (api *API) StarDashboardByUID(c *contextmodel.ReqContext) response.Response
|
||||
return response.Error(http.StatusBadRequest, "Invalid dashboard UID", nil)
|
||||
}
|
||||
|
||||
if api.starService == nil {
|
||||
err := api.client.AddStar(c, uid)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Failed to star dashboard", err)
|
||||
}
|
||||
return response.Success("Dashboard starred!")
|
||||
}
|
||||
|
||||
userID, err := identity.UserIdentifier(c.GetID())
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "Only users and service accounts can star dashboards", nil)
|
||||
}
|
||||
|
||||
dash, rsp := api.getDashboardHelper(c.Req.Context(), c.GetOrgID(), 0, uid)
|
||||
dashboardID, rsp := api.client.GetDashboardID(c, uid)
|
||||
if rsp != nil {
|
||||
return rsp
|
||||
}
|
||||
|
||||
cmd := star.StarDashboardCommand{UserID: userID, DashboardID: dash.ID, DashboardUID: uid, OrgID: c.GetOrgID(), Updated: time.Now()}
|
||||
cmd := star.StarDashboardCommand{UserID: userID, DashboardID: dashboardID, DashboardUID: uid, OrgID: c.GetOrgID(), Updated: time.Now()}
|
||||
|
||||
if err := api.starService.Add(c.Req.Context(), &cmd); err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Failed to star dashboard", err)
|
||||
@@ -123,6 +128,14 @@ func (api *API) UnstarDashboardByUID(c *contextmodel.ReqContext) response.Respon
|
||||
return response.Error(http.StatusBadRequest, "Invalid dashboard UID", nil)
|
||||
}
|
||||
|
||||
if api.starService == nil {
|
||||
err := api.client.RemoveStar(c, uid)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Failed to unstar dashboard", err)
|
||||
}
|
||||
return response.Success("Dashboard unstarred")
|
||||
}
|
||||
|
||||
userID, err := identity.UserIdentifier(c.GetID())
|
||||
if err != nil {
|
||||
return response.Error(http.StatusBadRequest, "Only users and service accounts can star dashboards", nil)
|
||||
|
||||
@@ -8,16 +8,18 @@ import (
|
||||
"github.com/stretchr/testify/mock"
|
||||
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/star/startest"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
func TestStarDashboardUID(t *testing.T) {
|
||||
svc := dashboards.NewFakeDashboardService(t)
|
||||
svc.On("GetDashboard", mock.Anything, mock.Anything).Return(&dashboards.Dashboard{UID: "test", OrgID: 1}, nil)
|
||||
api := ProvideApi(startest.NewStarServiceFake(), svc)
|
||||
client := NewMockK8sClients(t)
|
||||
client.On("GetDashboardID", mock.Anything, mock.Anything).Return(int64(123), nil)
|
||||
api := &API{
|
||||
starService: startest.NewStarServiceFake(),
|
||||
client: client,
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/client-go/dynamic"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
|
||||
authlib "github.com/grafana/authlib/types"
|
||||
dashboardsV1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v1beta1"
|
||||
preferencesV1 "github.com/grafana/grafana/apps/preferences/pkg/apis/preferences/v1alpha1"
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
"github.com/grafana/grafana/pkg/apimachinery/utils"
|
||||
"github.com/grafana/grafana/pkg/services/apiserver"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
)
|
||||
|
||||
//go:generate mockery --name K8sClients --structname MockK8sClients --inpackage --filename client_mock.go --with-expecter
|
||||
type K8sClients interface {
|
||||
GetDashboardID(c *contextmodel.ReqContext, uid string) (int64, response.Response)
|
||||
GetStars(c *contextmodel.ReqContext) ([]string, error)
|
||||
AddStar(c *contextmodel.ReqContext, uid string) error
|
||||
RemoveStar(c *contextmodel.ReqContext, uid string) error
|
||||
}
|
||||
|
||||
type k8sClients struct {
|
||||
namespacer authlib.NamespaceFormatter
|
||||
configProvider apiserver.DirectRestConfigProvider
|
||||
}
|
||||
|
||||
var (
|
||||
_ K8sClients = (*k8sClients)(nil)
|
||||
)
|
||||
|
||||
// GetDashboardID implements the K8sClients interface.
|
||||
func (k *k8sClients) GetDashboardID(c *contextmodel.ReqContext, uid string) (int64, response.Response) {
|
||||
dyn, err := dynamic.NewForConfig(k.configProvider.GetDirectRestConfig(c))
|
||||
if err != nil {
|
||||
return 0, response.Error(http.StatusInternalServerError, "client config", err)
|
||||
}
|
||||
client := dyn.Resource(dashboardsV1.GroupVersion.WithResource(dashboardsV1.DASHBOARD_RESOURCE)).Namespace(k.namespacer(c.OrgID))
|
||||
obj, err := client.Get(c.Req.Context(), uid, v1.GetOptions{})
|
||||
if err != nil {
|
||||
return 0, response.Error(http.StatusNotFound, "Dashboard not found", err)
|
||||
}
|
||||
dash, err := utils.MetaAccessor(obj)
|
||||
if err != nil {
|
||||
return 0, response.Error(http.StatusInternalServerError, "invalid object", err)
|
||||
}
|
||||
return dash.GetDeprecatedInternalID(), nil // nolint:staticcheck
|
||||
}
|
||||
|
||||
// GetStars implements K8sClients.
|
||||
func (k *k8sClients) GetStars(c *contextmodel.ReqContext) ([]string, error) {
|
||||
dyn, err := dynamic.NewForConfig(k.configProvider.GetDirectRestConfig(c))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client := dyn.Resource(preferencesV1.StarsResourceInfo.GroupVersionResource()).Namespace(k.namespacer(c.OrgID))
|
||||
|
||||
ctx := c.Req.Context()
|
||||
user, err := identity.GetRequester(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
obj, _ := client.Get(ctx, "user-"+user.GetIdentifier(), v1.GetOptions{})
|
||||
if obj != nil {
|
||||
resources, ok, _ := unstructured.NestedSlice(obj.Object, "spec", "resource")
|
||||
if ok && resources != nil {
|
||||
for _, r := range resources {
|
||||
tmp, ok := r.(map[string]any)
|
||||
if ok {
|
||||
g, _, _ := unstructured.NestedString(tmp, "group")
|
||||
k, _, _ := unstructured.NestedString(tmp, "kind")
|
||||
if k == "Dashboard" && g == dashboardsV1.APIGroup {
|
||||
names, _, _ := unstructured.NestedStringSlice(tmp, "names")
|
||||
return names, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return []string{}, nil
|
||||
}
|
||||
|
||||
// AddStar implements K8sClients.
|
||||
func (k *k8sClients) AddStar(c *contextmodel.ReqContext, uid string) error {
|
||||
dyn, err := kubernetes.NewForConfig(k.configProvider.GetDirectRestConfig(c))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx := c.Req.Context()
|
||||
user, err := identity.GetRequester(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ns := k.namespacer(c.OrgID)
|
||||
|
||||
client := dyn.RESTClient()
|
||||
rsp := client.Put().AbsPath(
|
||||
"apis", preferencesV1.APIGroup, preferencesV1.APIVersion, "namespaces", ns,
|
||||
"stars", "user-"+user.GetIdentifier(),
|
||||
"update", dashboardsV1.APIGroup, dashboardsV1.DashboardKind().Kind(), uid,
|
||||
).Do(ctx)
|
||||
|
||||
return rsp.Error()
|
||||
}
|
||||
|
||||
// RemoveStar implements K8sClients.
|
||||
func (k *k8sClients) RemoveStar(c *contextmodel.ReqContext, uid string) error {
|
||||
dyn, err := kubernetes.NewForConfig(k.configProvider.GetDirectRestConfig(c))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx := c.Req.Context()
|
||||
user, err := identity.GetRequester(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ns := k.namespacer(c.OrgID)
|
||||
|
||||
client := dyn.RESTClient()
|
||||
rsp := client.Delete().AbsPath(
|
||||
"apis", preferencesV1.APIGroup, preferencesV1.APIVersion, "namespaces", ns,
|
||||
"stars", "user-"+user.GetIdentifier(),
|
||||
"update", dashboardsV1.APIGroup, dashboardsV1.DashboardKind().Kind(), uid,
|
||||
).Do(ctx)
|
||||
|
||||
return rsp.Error()
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
// Code generated by mockery v2.53.4. DO NOT EDIT.
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
|
||||
response "github.com/grafana/grafana/pkg/api/response"
|
||||
)
|
||||
|
||||
// MockK8sClients is an autogenerated mock type for the K8sClients type
|
||||
type MockK8sClients struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
type MockK8sClients_Expecter struct {
|
||||
mock *mock.Mock
|
||||
}
|
||||
|
||||
func (_m *MockK8sClients) EXPECT() *MockK8sClients_Expecter {
|
||||
return &MockK8sClients_Expecter{mock: &_m.Mock}
|
||||
}
|
||||
|
||||
// AddStar provides a mock function with given fields: c, uid
|
||||
func (_m *MockK8sClients) AddStar(c *contextmodel.ReqContext, uid string) error {
|
||||
ret := _m.Called(c, uid)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for AddStar")
|
||||
}
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(*contextmodel.ReqContext, string) error); ok {
|
||||
r0 = rf(c, uid)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// MockK8sClients_AddStar_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddStar'
|
||||
type MockK8sClients_AddStar_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// AddStar is a helper method to define mock.On call
|
||||
// - c *contextmodel.ReqContext
|
||||
// - uid string
|
||||
func (_e *MockK8sClients_Expecter) AddStar(c interface{}, uid interface{}) *MockK8sClients_AddStar_Call {
|
||||
return &MockK8sClients_AddStar_Call{Call: _e.mock.On("AddStar", c, uid)}
|
||||
}
|
||||
|
||||
func (_c *MockK8sClients_AddStar_Call) Run(run func(c *contextmodel.ReqContext, uid string)) *MockK8sClients_AddStar_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
run(args[0].(*contextmodel.ReqContext), args[1].(string))
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockK8sClients_AddStar_Call) Return(_a0 error) *MockK8sClients_AddStar_Call {
|
||||
_c.Call.Return(_a0)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockK8sClients_AddStar_Call) RunAndReturn(run func(*contextmodel.ReqContext, string) error) *MockK8sClients_AddStar_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// GetDashboardID provides a mock function with given fields: c, uid
|
||||
func (_m *MockK8sClients) GetDashboardID(c *contextmodel.ReqContext, uid string) (int64, response.Response) {
|
||||
ret := _m.Called(c, uid)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for GetDashboardID")
|
||||
}
|
||||
|
||||
var r0 int64
|
||||
var r1 response.Response
|
||||
if rf, ok := ret.Get(0).(func(*contextmodel.ReqContext, string) (int64, response.Response)); ok {
|
||||
return rf(c, uid)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(*contextmodel.ReqContext, string) int64); ok {
|
||||
r0 = rf(c, uid)
|
||||
} else {
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(*contextmodel.ReqContext, string) response.Response); ok {
|
||||
r1 = rf(c, uid)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(response.Response)
|
||||
}
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// MockK8sClients_GetDashboardID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDashboardID'
|
||||
type MockK8sClients_GetDashboardID_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// GetDashboardID is a helper method to define mock.On call
|
||||
// - c *contextmodel.ReqContext
|
||||
// - uid string
|
||||
func (_e *MockK8sClients_Expecter) GetDashboardID(c interface{}, uid interface{}) *MockK8sClients_GetDashboardID_Call {
|
||||
return &MockK8sClients_GetDashboardID_Call{Call: _e.mock.On("GetDashboardID", c, uid)}
|
||||
}
|
||||
|
||||
func (_c *MockK8sClients_GetDashboardID_Call) Run(run func(c *contextmodel.ReqContext, uid string)) *MockK8sClients_GetDashboardID_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
run(args[0].(*contextmodel.ReqContext), args[1].(string))
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockK8sClients_GetDashboardID_Call) Return(_a0 int64, _a1 response.Response) *MockK8sClients_GetDashboardID_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockK8sClients_GetDashboardID_Call) RunAndReturn(run func(*contextmodel.ReqContext, string) (int64, response.Response)) *MockK8sClients_GetDashboardID_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// GetStars provides a mock function with given fields: c
|
||||
func (_m *MockK8sClients) GetStars(c *contextmodel.ReqContext) ([]string, error) {
|
||||
ret := _m.Called(c)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for GetStars")
|
||||
}
|
||||
|
||||
var r0 []string
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(*contextmodel.ReqContext) ([]string, error)); ok {
|
||||
return rf(c)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(*contextmodel.ReqContext) []string); ok {
|
||||
r0 = rf(c)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]string)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(*contextmodel.ReqContext) error); ok {
|
||||
r1 = rf(c)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// MockK8sClients_GetStars_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetStars'
|
||||
type MockK8sClients_GetStars_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// GetStars is a helper method to define mock.On call
|
||||
// - c *contextmodel.ReqContext
|
||||
func (_e *MockK8sClients_Expecter) GetStars(c interface{}) *MockK8sClients_GetStars_Call {
|
||||
return &MockK8sClients_GetStars_Call{Call: _e.mock.On("GetStars", c)}
|
||||
}
|
||||
|
||||
func (_c *MockK8sClients_GetStars_Call) Run(run func(c *contextmodel.ReqContext)) *MockK8sClients_GetStars_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
run(args[0].(*contextmodel.ReqContext))
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockK8sClients_GetStars_Call) Return(_a0 []string, _a1 error) *MockK8sClients_GetStars_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockK8sClients_GetStars_Call) RunAndReturn(run func(*contextmodel.ReqContext) ([]string, error)) *MockK8sClients_GetStars_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// RemoveStar provides a mock function with given fields: c, uid
|
||||
func (_m *MockK8sClients) RemoveStar(c *contextmodel.ReqContext, uid string) error {
|
||||
ret := _m.Called(c, uid)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for RemoveStar")
|
||||
}
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(*contextmodel.ReqContext, string) error); ok {
|
||||
r0 = rf(c, uid)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// MockK8sClients_RemoveStar_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RemoveStar'
|
||||
type MockK8sClients_RemoveStar_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// RemoveStar is a helper method to define mock.On call
|
||||
// - c *contextmodel.ReqContext
|
||||
// - uid string
|
||||
func (_e *MockK8sClients_Expecter) RemoveStar(c interface{}, uid interface{}) *MockK8sClients_RemoveStar_Call {
|
||||
return &MockK8sClients_RemoveStar_Call{Call: _e.mock.On("RemoveStar", c, uid)}
|
||||
}
|
||||
|
||||
func (_c *MockK8sClients_RemoveStar_Call) Run(run func(c *contextmodel.ReqContext, uid string)) *MockK8sClients_RemoveStar_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
run(args[0].(*contextmodel.ReqContext), args[1].(string))
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockK8sClients_RemoveStar_Call) Return(_a0 error) *MockK8sClients_RemoveStar_Call {
|
||||
_c.Call.Return(_a0)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockK8sClients_RemoveStar_Call) RunAndReturn(run func(*contextmodel.ReqContext, string) error) *MockK8sClients_RemoveStar_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// NewMockK8sClients creates a new instance of MockK8sClients. 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 NewMockK8sClients(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}) *MockK8sClients {
|
||||
mock := &MockK8sClients{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) })
|
||||
|
||||
return mock
|
||||
}
|
||||
Reference in New Issue
Block a user