diff --git a/cmd/commandeer.go b/cmd/commandeer.go index 61319e94..b1dafa7e 100644 --- a/cmd/commandeer.go +++ b/cmd/commandeer.go @@ -2,13 +2,17 @@ package cmd import ( "context" + "github.com/bep/simplecobra" + "github.com/esnet/gdg/cmd/backup" "github.com/esnet/gdg/cmd/support" + "github.com/esnet/gdg/cmd/tools" ) // Execute executes a command. -func Execute(defaultCfg string, args []string) error { +func Execute(defaultCfg string, args []string, options ...support.RootOption) error { support.DefaultConfig = defaultCfg - x, err := NewExec() + rootCmd := support.NewRootCmd(getNewRootCmd(), options...) + x, err := simplecobra.New(rootCmd) if err != nil { return err } @@ -21,3 +25,15 @@ func Execute(defaultCfg string, args []string) error { return nil } + +func getNewRootCmd() *support.RootCommand { + return &support.RootCommand{ + NameP: "gdg", + CommandEntries: []simplecobra.Commander{ + newVersionCmd(), + newContextCmd(), + tools.NewToolsCommand(), + backup.NewBackupCommand(), + }, + } +} diff --git a/cmd/commands.go b/cmd/commands.go deleted file mode 100644 index 535da029..00000000 --- a/cmd/commands.go +++ /dev/null @@ -1,24 +0,0 @@ -package cmd - -import ( - "github.com/bep/simplecobra" - "github.com/esnet/gdg/cmd/backup" - "github.com/esnet/gdg/cmd/support" - "github.com/esnet/gdg/cmd/tools" -) - -// NewExec wires up all of GDG CLI. -func NewExec() (*simplecobra.Exec, error) { - rootCmd := &support.RootCommand{ - NameP: "gdg", - CommandEntries: []simplecobra.Commander{ - newVersionCmd(), - newContextCmd(), - tools.NewToolsCommand(), - backup.NewBackupCommand(), - }, - } - - return simplecobra.New(rootCmd) - -} diff --git a/cmd/support/root.go b/cmd/support/root.go index b7b467c2..d9ea6d7c 100644 --- a/cmd/support/root.go +++ b/cmd/support/root.go @@ -9,19 +9,17 @@ import ( "github.com/jedib0t/go-pretty/v6/table" log "github.com/sirupsen/logrus" "os" - "sync" ) var ( DefaultConfig string - svcLock sync.Mutex ) type RootCommand struct { NameP string isInit bool - grafanaSvc service.GrafanaService + GrafanaSvc func() service.GrafanaService localFlagName string @@ -39,8 +37,17 @@ type RootCommand struct { CommandEntries []simplecobra.Commander } -func (c *RootCommand) GrafanaSvc() service.GrafanaService { - return c.grafanaSvc +type RootOption func(command *RootCommand) + +// NewRootCmd Allows to construct a root command passing any number of arguments to set RootCommand Options +func NewRootCmd(root *RootCommand, options ...RootOption) *RootCommand { + if root == nil { + root = &RootCommand{} + } + for _, o := range options { + o(root) + } + return root } func (c *RootCommand) Commands() []simplecobra.Commander { @@ -52,8 +59,6 @@ func (c *RootCommand) PreRun(this, runner *simplecobra.Commandeer) error { c.initThis = this c.initRunner = runner c.initConfiguration() - - c.grafanaSvc = service.NewApiService() return nil } @@ -96,11 +101,14 @@ func (c *RootCommand) Init(cd *simplecobra.Commandeer) error { return errors.New("failWithCobraCommand") } cmd := cd.CobraCommand + persistentFlags := cmd.PersistentFlags() persistentFlags.StringP("config", "c", "", "Configuration Override") - c.TableObj = table.NewWriter() - c.TableObj.SetOutputMirror(os.Stdout) - c.TableObj.SetStyle(table.StyleLight) + if c.TableObj == nil { + c.TableObj = table.NewWriter() + c.TableObj.SetOutputMirror(os.Stdout) + c.TableObj.SetStyle(table.StyleLight) + } return nil } diff --git a/cmd/version.go b/cmd/version.go index d3f9d15f..bdfc8804 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -7,17 +7,19 @@ import ( "github.com/esnet/gdg/cmd/support" "github.com/esnet/gdg/internal/version" "github.com/spf13/cobra" + "os" ) func newVersionCmd() simplecobra.Commander { return &support.SimpleCommand{ NameP: "version", RunFunc: func(ctx context.Context, cd *simplecobra.Commandeer, r *support.RootCommand, args []string) error { - fmt.Println("Build Date:", version.BuildDate) - fmt.Println("Git Commit:", version.GitCommit) - fmt.Println("Version:", version.Version) - fmt.Println("Go Version:", version.GoVersion) - fmt.Println("OS / Arch:", version.OsArch) + stdout := os.Stdout + fmt.Fprintf(stdout, "Build Date: %s\n", version.BuildDate) + fmt.Fprintf(stdout, "Git Commit: %s\n", version.GitCommit) + fmt.Fprintf(stdout, "Version: %s\n", version.Version) + fmt.Fprintf(stdout, "Go Version: %s\n", version.GoVersion) + fmt.Fprintf(stdout, "OS / Arch: %s\n", version.OsArch) return nil }, WithCFunc: func(cmd *cobra.Command, r *support.RootCommand) { diff --git a/cmd/version_test.go b/cmd/version_test.go new file mode 100644 index 00000000..a3bca6db --- /dev/null +++ b/cmd/version_test.go @@ -0,0 +1,62 @@ +package cmd + +import ( + "fmt" + "github.com/esnet/gdg/cmd/support" + "github.com/esnet/gdg/internal/service" + "github.com/esnet/gdg/internal/service/mocks" + "github.com/esnet/gdg/internal/version" + "github.com/stretchr/testify/assert" + "io" + "os" + "strings" + "testing" +) + +func interceptStdout() (*os.File, *os.File, func()) { + backupStd := os.Stdout + backupErr := os.Stderr + r, w, _ := os.Pipe() + //Restore streams + cleanup := func() { + os.Stdout = backupStd + os.Stderr = backupErr + } + os.Stdout = w + os.Stderr = w + + return r, w, cleanup + +} + +func TestVersionCommand(t *testing.T) { + testSvc := new(mocks.GrafanaService) + getMockSvc := func() service.GrafanaService { + return testSvc + } + + optionMockSvc := func() support.RootOption { + return func(response *support.RootCommand) { + response.GrafanaSvc = getMockSvc + } + } + path, _ := os.Getwd() + fmt.Println(path) + r, w, cleanup := interceptStdout() + data, err := os.ReadFile("../config/testing.yml") + assert.Nil(t, err) + + err = Execute(string(data), []string{"version"}, optionMockSvc()) + assert.Nil(t, err) + defer cleanup() + w.Close() + out, _ := io.ReadAll(r) + outStr := string(out) + assert.True(t, strings.Contains(outStr, "Build Date:")) + assert.True(t, strings.Contains(outStr, "Git Commit:")) + assert.True(t, strings.Contains(outStr, "Version:")) + assert.True(t, strings.Contains(outStr, version.Version)) + assert.True(t, strings.Contains(outStr, "Date:")) + assert.True(t, strings.Contains(outStr, "Go Version:")) + assert.True(t, strings.Contains(outStr, "OS / Arch:")) +} diff --git a/go.mod b/go.mod index 84bd5015..a876883b 100644 --- a/go.mod +++ b/go.mod @@ -113,6 +113,7 @@ require ( github.com/spf13/cast v1.5.1 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect + github.com/stretchr/objx v0.5.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect github.com/tidwall/match v1.1.1 // indirect go.opencensus.io v0.24.0 // indirect diff --git a/go.sum b/go.sum index f4570123..8e6cf464 100644 --- a/go.sum +++ b/go.sum @@ -442,6 +442,7 @@ github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1Fof github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= diff --git a/internal/service/dashboards.go b/internal/service/dashboards.go index c3e73e37..0550198e 100644 --- a/internal/service/dashboards.go +++ b/internal/service/dashboards.go @@ -27,7 +27,6 @@ type DashboardsApi interface { DownloadDashboards(filter filters.Filter) []string UploadDashboards(filter filters.Filter) DeleteAllDashboards(filter filters.Filter) []string - getDashboardByUid(uid string) (*models.DashboardFullWithMeta, error) } // getDashboardByUid retrieve a dashboard given a particular uid. diff --git a/internal/service/mocks/AlertNotificationsApi.go b/internal/service/mocks/AlertNotificationsApi.go new file mode 100644 index 00000000..b275ee1c --- /dev/null +++ b/internal/service/mocks/AlertNotificationsApi.go @@ -0,0 +1,91 @@ +// Code generated by mockery v2.34.0. DO NOT EDIT. + +package mocks + +import ( + models "github.com/esnet/grafana-swagger-api-golang/goclient/models" + mock "github.com/stretchr/testify/mock" +) + +// AlertNotificationsApi is an autogenerated mock type for the AlertNotificationsApi type +type AlertNotificationsApi struct { + mock.Mock +} + +// DeleteAllAlertNotifications provides a mock function with given fields: +func (_m *AlertNotificationsApi) DeleteAllAlertNotifications() []string { + ret := _m.Called() + + var r0 []string + if rf, ok := ret.Get(0).(func() []string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DownloadAlertNotifications provides a mock function with given fields: +func (_m *AlertNotificationsApi) DownloadAlertNotifications() []string { + ret := _m.Called() + + var r0 []string + if rf, ok := ret.Get(0).(func() []string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// ListAlertNotifications provides a mock function with given fields: +func (_m *AlertNotificationsApi) ListAlertNotifications() []*models.AlertNotification { + ret := _m.Called() + + var r0 []*models.AlertNotification + if rf, ok := ret.Get(0).(func() []*models.AlertNotification); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.AlertNotification) + } + } + + return r0 +} + +// UploadAlertNotifications provides a mock function with given fields: +func (_m *AlertNotificationsApi) UploadAlertNotifications() []string { + ret := _m.Called() + + var r0 []string + if rf, ok := ret.Get(0).(func() []string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// NewAlertNotificationsApi creates a new instance of AlertNotificationsApi. 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 NewAlertNotificationsApi(t interface { + mock.TestingT + Cleanup(func()) +}) *AlertNotificationsApi { + mock := &AlertNotificationsApi{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/service/mocks/AuthenticationApi.go b/internal/service/mocks/AuthenticationApi.go new file mode 100644 index 00000000..eb33f295 --- /dev/null +++ b/internal/service/mocks/AuthenticationApi.go @@ -0,0 +1,218 @@ +// Code generated by mockery v2.34.0. DO NOT EDIT. + +package mocks + +import ( + api "github.com/esnet/gdg/internal/api" + mock "github.com/stretchr/testify/mock" + + models "github.com/esnet/grafana-swagger-api-golang/goclient/models" +) + +// AuthenticationApi is an autogenerated mock type for the AuthenticationApi type +type AuthenticationApi struct { + mock.Mock +} + +// CreateAPIKey provides a mock function with given fields: name, role, expiration +func (_m *AuthenticationApi) CreateAPIKey(name string, role string, expiration int64) (*models.NewAPIKeyResult, error) { + ret := _m.Called(name, role, expiration) + + var r0 *models.NewAPIKeyResult + var r1 error + if rf, ok := ret.Get(0).(func(string, string, int64) (*models.NewAPIKeyResult, error)); ok { + return rf(name, role, expiration) + } + if rf, ok := ret.Get(0).(func(string, string, int64) *models.NewAPIKeyResult); ok { + r0 = rf(name, role, expiration) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*models.NewAPIKeyResult) + } + } + + if rf, ok := ret.Get(1).(func(string, string, int64) error); ok { + r1 = rf(name, role, expiration) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CreateServiceAccount provides a mock function with given fields: name, role, expiration +func (_m *AuthenticationApi) CreateServiceAccount(name string, role string, expiration int64) (*models.ServiceAccountDTO, error) { + ret := _m.Called(name, role, expiration) + + var r0 *models.ServiceAccountDTO + var r1 error + if rf, ok := ret.Get(0).(func(string, string, int64) (*models.ServiceAccountDTO, error)); ok { + return rf(name, role, expiration) + } + if rf, ok := ret.Get(0).(func(string, string, int64) *models.ServiceAccountDTO); ok { + r0 = rf(name, role, expiration) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*models.ServiceAccountDTO) + } + } + + if rf, ok := ret.Get(1).(func(string, string, int64) error); ok { + r1 = rf(name, role, expiration) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CreateServiceAccountToken provides a mock function with given fields: name, role, expiration +func (_m *AuthenticationApi) CreateServiceAccountToken(name int64, role string, expiration int64) (*models.NewAPIKeyResult, error) { + ret := _m.Called(name, role, expiration) + + var r0 *models.NewAPIKeyResult + var r1 error + if rf, ok := ret.Get(0).(func(int64, string, int64) (*models.NewAPIKeyResult, error)); ok { + return rf(name, role, expiration) + } + if rf, ok := ret.Get(0).(func(int64, string, int64) *models.NewAPIKeyResult); ok { + r0 = rf(name, role, expiration) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*models.NewAPIKeyResult) + } + } + + if rf, ok := ret.Get(1).(func(int64, string, int64) error); ok { + r1 = rf(name, role, expiration) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeleteAllServiceAccounts provides a mock function with given fields: +func (_m *AuthenticationApi) DeleteAllServiceAccounts() []string { + ret := _m.Called() + + var r0 []string + if rf, ok := ret.Get(0).(func() []string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DeleteAllTokens provides a mock function with given fields: +func (_m *AuthenticationApi) DeleteAllTokens() []string { + ret := _m.Called() + + var r0 []string + if rf, ok := ret.Get(0).(func() []string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DeleteServiceAccountTokens provides a mock function with given fields: serviceId +func (_m *AuthenticationApi) DeleteServiceAccountTokens(serviceId int64) []string { + ret := _m.Called(serviceId) + + var r0 []string + if rf, ok := ret.Get(0).(func(int64) []string); ok { + r0 = rf(serviceId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// ListAPIKeys provides a mock function with given fields: +func (_m *AuthenticationApi) ListAPIKeys() []*models.APIKeyDTO { + ret := _m.Called() + + var r0 []*models.APIKeyDTO + if rf, ok := ret.Get(0).(func() []*models.APIKeyDTO); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.APIKeyDTO) + } + } + + return r0 +} + +// ListServiceAccounts provides a mock function with given fields: +func (_m *AuthenticationApi) ListServiceAccounts() []*api.ServiceAccountDTOWithTokens { + ret := _m.Called() + + var r0 []*api.ServiceAccountDTOWithTokens + if rf, ok := ret.Get(0).(func() []*api.ServiceAccountDTOWithTokens); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*api.ServiceAccountDTOWithTokens) + } + } + + return r0 +} + +// ListServiceAccountsTokens provides a mock function with given fields: id +func (_m *AuthenticationApi) ListServiceAccountsTokens(id int64) ([]*models.TokenDTO, error) { + ret := _m.Called(id) + + var r0 []*models.TokenDTO + var r1 error + if rf, ok := ret.Get(0).(func(int64) ([]*models.TokenDTO, error)); ok { + return rf(id) + } + if rf, ok := ret.Get(0).(func(int64) []*models.TokenDTO); ok { + r0 = rf(id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.TokenDTO) + } + } + + if rf, ok := ret.Get(1).(func(int64) error); ok { + r1 = rf(id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Login provides a mock function with given fields: +func (_m *AuthenticationApi) Login() { + _m.Called() +} + +// NewAuthenticationApi creates a new instance of AuthenticationApi. 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 NewAuthenticationApi(t interface { + mock.TestingT + Cleanup(func()) +}) *AuthenticationApi { + mock := &AuthenticationApi{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/service/mocks/ConnectionPermissions.go b/internal/service/mocks/ConnectionPermissions.go new file mode 100644 index 00000000..2cae8024 --- /dev/null +++ b/internal/service/mocks/ConnectionPermissions.go @@ -0,0 +1,93 @@ +// Code generated by mockery v2.34.0. DO NOT EDIT. + +package mocks + +import ( + filters "github.com/esnet/gdg/internal/service/filters" + mock "github.com/stretchr/testify/mock" + + models "github.com/esnet/grafana-swagger-api-golang/goclient/models" +) + +// ConnectionPermissions is an autogenerated mock type for the ConnectionPermissions type +type ConnectionPermissions struct { + mock.Mock +} + +// DeleteAllConnectionPermissions provides a mock function with given fields: filter +func (_m *ConnectionPermissions) DeleteAllConnectionPermissions(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DownloadConnectionPermissions provides a mock function with given fields: filter +func (_m *ConnectionPermissions) DownloadConnectionPermissions(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// ListConnectionPermissions provides a mock function with given fields: filter +func (_m *ConnectionPermissions) ListConnectionPermissions(filter filters.Filter) map[*models.DataSourceListItemDTO]*models.DataSourcePermissionsDTO { + ret := _m.Called(filter) + + var r0 map[*models.DataSourceListItemDTO]*models.DataSourcePermissionsDTO + if rf, ok := ret.Get(0).(func(filters.Filter) map[*models.DataSourceListItemDTO]*models.DataSourcePermissionsDTO); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[*models.DataSourceListItemDTO]*models.DataSourcePermissionsDTO) + } + } + + return r0 +} + +// UploadConnectionPermissions provides a mock function with given fields: filter +func (_m *ConnectionPermissions) UploadConnectionPermissions(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// NewConnectionPermissions creates a new instance of ConnectionPermissions. 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 NewConnectionPermissions(t interface { + mock.TestingT + Cleanup(func()) +}) *ConnectionPermissions { + mock := &ConnectionPermissions{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/service/mocks/ConnectionsApi.go b/internal/service/mocks/ConnectionsApi.go new file mode 100644 index 00000000..e1df4016 --- /dev/null +++ b/internal/service/mocks/ConnectionsApi.go @@ -0,0 +1,157 @@ +// Code generated by mockery v2.34.0. DO NOT EDIT. + +package mocks + +import ( + filters "github.com/esnet/gdg/internal/service/filters" + mock "github.com/stretchr/testify/mock" + + models "github.com/esnet/grafana-swagger-api-golang/goclient/models" +) + +// ConnectionsApi is an autogenerated mock type for the ConnectionsApi type +type ConnectionsApi struct { + mock.Mock +} + +// DeleteAllConnectionPermissions provides a mock function with given fields: filter +func (_m *ConnectionsApi) DeleteAllConnectionPermissions(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DeleteAllConnections provides a mock function with given fields: filter +func (_m *ConnectionsApi) DeleteAllConnections(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DownloadConnectionPermissions provides a mock function with given fields: filter +func (_m *ConnectionsApi) DownloadConnectionPermissions(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DownloadConnections provides a mock function with given fields: filter +func (_m *ConnectionsApi) DownloadConnections(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// ListConnectionPermissions provides a mock function with given fields: filter +func (_m *ConnectionsApi) ListConnectionPermissions(filter filters.Filter) map[*models.DataSourceListItemDTO]*models.DataSourcePermissionsDTO { + ret := _m.Called(filter) + + var r0 map[*models.DataSourceListItemDTO]*models.DataSourcePermissionsDTO + if rf, ok := ret.Get(0).(func(filters.Filter) map[*models.DataSourceListItemDTO]*models.DataSourcePermissionsDTO); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[*models.DataSourceListItemDTO]*models.DataSourcePermissionsDTO) + } + } + + return r0 +} + +// ListConnections provides a mock function with given fields: filter +func (_m *ConnectionsApi) ListConnections(filter filters.Filter) []models.DataSourceListItemDTO { + ret := _m.Called(filter) + + var r0 []models.DataSourceListItemDTO + if rf, ok := ret.Get(0).(func(filters.Filter) []models.DataSourceListItemDTO); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]models.DataSourceListItemDTO) + } + } + + return r0 +} + +// UploadConnectionPermissions provides a mock function with given fields: filter +func (_m *ConnectionsApi) UploadConnectionPermissions(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// UploadConnections provides a mock function with given fields: filter +func (_m *ConnectionsApi) UploadConnections(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// NewConnectionsApi creates a new instance of ConnectionsApi. 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 NewConnectionsApi(t interface { + mock.TestingT + Cleanup(func()) +}) *ConnectionsApi { + mock := &ConnectionsApi{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/service/mocks/DashboardsApi.go b/internal/service/mocks/DashboardsApi.go new file mode 100644 index 00000000..5251e2c1 --- /dev/null +++ b/internal/service/mocks/DashboardsApi.go @@ -0,0 +1,82 @@ +// Code generated by mockery v2.34.0. DO NOT EDIT. + +package mocks + +import ( + filters "github.com/esnet/gdg/internal/service/filters" + mock "github.com/stretchr/testify/mock" + + models "github.com/esnet/grafana-swagger-api-golang/goclient/models" +) + +// DashboardsApi is an autogenerated mock type for the DashboardsApi type +type DashboardsApi struct { + mock.Mock +} + +// DeleteAllDashboards provides a mock function with given fields: filter +func (_m *DashboardsApi) DeleteAllDashboards(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DownloadDashboards provides a mock function with given fields: filter +func (_m *DashboardsApi) DownloadDashboards(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// ListDashboards provides a mock function with given fields: filter +func (_m *DashboardsApi) ListDashboards(filter filters.Filter) []*models.Hit { + ret := _m.Called(filter) + + var r0 []*models.Hit + if rf, ok := ret.Get(0).(func(filters.Filter) []*models.Hit); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.Hit) + } + } + + return r0 +} + +// UploadDashboards provides a mock function with given fields: filter +func (_m *DashboardsApi) UploadDashboards(filter filters.Filter) { + _m.Called(filter) +} + +// NewDashboardsApi creates a new instance of DashboardsApi. 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 NewDashboardsApi(t interface { + mock.TestingT + Cleanup(func()) +}) *DashboardsApi { + mock := &DashboardsApi{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/service/mocks/Filter.go b/internal/service/mocks/Filter.go new file mode 100644 index 00000000..dc6d7437 --- /dev/null +++ b/internal/service/mocks/Filter.go @@ -0,0 +1,102 @@ +// Code generated by mockery v2.34.0. DO NOT EDIT. + +package mocks + +import ( + filters "github.com/esnet/gdg/internal/service/filters" + mock "github.com/stretchr/testify/mock" + + regexp "regexp" +) + +// Filter is an autogenerated mock type for the Filter type +type Filter struct { + mock.Mock +} + +// AddFilter provides a mock function with given fields: key, value +func (_m *Filter) AddFilter(key filters.FilterType, value string) { + _m.Called(key, value) +} + +// AddRegex provides a mock function with given fields: _a0, _a1 +func (_m *Filter) AddRegex(_a0 filters.FilterType, _a1 *regexp.Regexp) { + _m.Called(_a0, _a1) +} + +// AddValidation provides a mock function with given fields: _a0, _a1 +func (_m *Filter) AddValidation(_a0 filters.FilterType, _a1 func(interface{}) bool) { + _m.Called(_a0, _a1) +} + +// GetEntity provides a mock function with given fields: _a0 +func (_m *Filter) GetEntity(_a0 filters.FilterType) []string { + ret := _m.Called(_a0) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.FilterType) []string); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// GetFilter provides a mock function with given fields: key +func (_m *Filter) GetFilter(key filters.FilterType) string { + ret := _m.Called(key) + + var r0 string + if rf, ok := ret.Get(0).(func(filters.FilterType) string); ok { + r0 = rf(key) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// InvokeValidation provides a mock function with given fields: _a0, _a1 +func (_m *Filter) InvokeValidation(_a0 filters.FilterType, _a1 interface{}) bool { + ret := _m.Called(_a0, _a1) + + var r0 bool + if rf, ok := ret.Get(0).(func(filters.FilterType, interface{}) bool); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// ValidateAll provides a mock function with given fields: _a0 +func (_m *Filter) ValidateAll(_a0 interface{}) bool { + ret := _m.Called(_a0) + + var r0 bool + if rf, ok := ret.Get(0).(func(interface{}) bool); ok { + r0 = rf(_a0) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// NewFilter creates a new instance of Filter. 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 NewFilter(t interface { + mock.TestingT + Cleanup(func()) +}) *Filter { + mock := &Filter{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/service/mocks/FoldersApi.go b/internal/service/mocks/FoldersApi.go new file mode 100644 index 00000000..d2707d8d --- /dev/null +++ b/internal/service/mocks/FoldersApi.go @@ -0,0 +1,141 @@ +// Code generated by mockery v2.34.0. DO NOT EDIT. + +package mocks + +import ( + filters "github.com/esnet/gdg/internal/service/filters" + mock "github.com/stretchr/testify/mock" + + models "github.com/esnet/grafana-swagger-api-golang/goclient/models" +) + +// FoldersApi is an autogenerated mock type for the FoldersApi type +type FoldersApi struct { + mock.Mock +} + +// DeleteAllFolders provides a mock function with given fields: filter +func (_m *FoldersApi) DeleteAllFolders(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DownloadFolderPermissions provides a mock function with given fields: filter +func (_m *FoldersApi) DownloadFolderPermissions(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DownloadFolders provides a mock function with given fields: filter +func (_m *FoldersApi) DownloadFolders(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// ListFolder provides a mock function with given fields: filter +func (_m *FoldersApi) ListFolder(filter filters.Filter) []*models.Hit { + ret := _m.Called(filter) + + var r0 []*models.Hit + if rf, ok := ret.Get(0).(func(filters.Filter) []*models.Hit); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.Hit) + } + } + + return r0 +} + +// ListFolderPermissions provides a mock function with given fields: filter +func (_m *FoldersApi) ListFolderPermissions(filter filters.Filter) map[*models.Hit][]*models.DashboardACLInfoDTO { + ret := _m.Called(filter) + + var r0 map[*models.Hit][]*models.DashboardACLInfoDTO + if rf, ok := ret.Get(0).(func(filters.Filter) map[*models.Hit][]*models.DashboardACLInfoDTO); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[*models.Hit][]*models.DashboardACLInfoDTO) + } + } + + return r0 +} + +// UploadFolderPermissions provides a mock function with given fields: filter +func (_m *FoldersApi) UploadFolderPermissions(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// UploadFolders provides a mock function with given fields: filter +func (_m *FoldersApi) UploadFolders(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// NewFoldersApi creates a new instance of FoldersApi. 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 NewFoldersApi(t interface { + mock.TestingT + Cleanup(func()) +}) *FoldersApi { + mock := &FoldersApi{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/service/mocks/GrafanaService.go b/internal/service/mocks/GrafanaService.go new file mode 100644 index 00000000..1c9c22fc --- /dev/null +++ b/internal/service/mocks/GrafanaService.go @@ -0,0 +1,1031 @@ +// Code generated by mockery v2.34.0. DO NOT EDIT. + +package mocks + +import ( + api "github.com/esnet/gdg/internal/api" + filters "github.com/esnet/gdg/internal/service/filters" + mock "github.com/stretchr/testify/mock" + + models "github.com/esnet/grafana-swagger-api-golang/goclient/models" +) + +// GrafanaService is an autogenerated mock type for the GrafanaService type +type GrafanaService struct { + mock.Mock +} + +// AddUserToOrg provides a mock function with given fields: role, userId, orgId +func (_m *GrafanaService) AddUserToOrg(role string, userId int64, orgId int64) error { + ret := _m.Called(role, userId, orgId) + + var r0 error + if rf, ok := ret.Get(0).(func(string, int64, int64) error); ok { + r0 = rf(role, userId, orgId) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// CreateAPIKey provides a mock function with given fields: name, role, expiration +func (_m *GrafanaService) CreateAPIKey(name string, role string, expiration int64) (*models.NewAPIKeyResult, error) { + ret := _m.Called(name, role, expiration) + + var r0 *models.NewAPIKeyResult + var r1 error + if rf, ok := ret.Get(0).(func(string, string, int64) (*models.NewAPIKeyResult, error)); ok { + return rf(name, role, expiration) + } + if rf, ok := ret.Get(0).(func(string, string, int64) *models.NewAPIKeyResult); ok { + r0 = rf(name, role, expiration) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*models.NewAPIKeyResult) + } + } + + if rf, ok := ret.Get(1).(func(string, string, int64) error); ok { + r1 = rf(name, role, expiration) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CreateServiceAccount provides a mock function with given fields: name, role, expiration +func (_m *GrafanaService) CreateServiceAccount(name string, role string, expiration int64) (*models.ServiceAccountDTO, error) { + ret := _m.Called(name, role, expiration) + + var r0 *models.ServiceAccountDTO + var r1 error + if rf, ok := ret.Get(0).(func(string, string, int64) (*models.ServiceAccountDTO, error)); ok { + return rf(name, role, expiration) + } + if rf, ok := ret.Get(0).(func(string, string, int64) *models.ServiceAccountDTO); ok { + r0 = rf(name, role, expiration) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*models.ServiceAccountDTO) + } + } + + if rf, ok := ret.Get(1).(func(string, string, int64) error); ok { + r1 = rf(name, role, expiration) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CreateServiceAccountToken provides a mock function with given fields: name, role, expiration +func (_m *GrafanaService) CreateServiceAccountToken(name int64, role string, expiration int64) (*models.NewAPIKeyResult, error) { + ret := _m.Called(name, role, expiration) + + var r0 *models.NewAPIKeyResult + var r1 error + if rf, ok := ret.Get(0).(func(int64, string, int64) (*models.NewAPIKeyResult, error)); ok { + return rf(name, role, expiration) + } + if rf, ok := ret.Get(0).(func(int64, string, int64) *models.NewAPIKeyResult); ok { + r0 = rf(name, role, expiration) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*models.NewAPIKeyResult) + } + } + + if rf, ok := ret.Get(1).(func(int64, string, int64) error); ok { + r1 = rf(name, role, expiration) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeleteAllAlertNotifications provides a mock function with given fields: +func (_m *GrafanaService) DeleteAllAlertNotifications() []string { + ret := _m.Called() + + var r0 []string + if rf, ok := ret.Get(0).(func() []string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DeleteAllConnectionPermissions provides a mock function with given fields: filter +func (_m *GrafanaService) DeleteAllConnectionPermissions(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DeleteAllConnections provides a mock function with given fields: filter +func (_m *GrafanaService) DeleteAllConnections(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DeleteAllDashboards provides a mock function with given fields: filter +func (_m *GrafanaService) DeleteAllDashboards(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DeleteAllFolders provides a mock function with given fields: filter +func (_m *GrafanaService) DeleteAllFolders(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DeleteAllLibraryElements provides a mock function with given fields: filter +func (_m *GrafanaService) DeleteAllLibraryElements(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DeleteAllServiceAccounts provides a mock function with given fields: +func (_m *GrafanaService) DeleteAllServiceAccounts() []string { + ret := _m.Called() + + var r0 []string + if rf, ok := ret.Get(0).(func() []string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DeleteAllTokens provides a mock function with given fields: +func (_m *GrafanaService) DeleteAllTokens() []string { + ret := _m.Called() + + var r0 []string + if rf, ok := ret.Get(0).(func() []string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DeleteAllUsers provides a mock function with given fields: filter +func (_m *GrafanaService) DeleteAllUsers(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DeleteServiceAccountTokens provides a mock function with given fields: serviceId +func (_m *GrafanaService) DeleteServiceAccountTokens(serviceId int64) []string { + ret := _m.Called(serviceId) + + var r0 []string + if rf, ok := ret.Get(0).(func(int64) []string); ok { + r0 = rf(serviceId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DeleteTeam provides a mock function with given fields: filter +func (_m *GrafanaService) DeleteTeam(filter filters.Filter) ([]*models.TeamDTO, error) { + ret := _m.Called(filter) + + var r0 []*models.TeamDTO + var r1 error + if rf, ok := ret.Get(0).(func(filters.Filter) ([]*models.TeamDTO, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(filters.Filter) []*models.TeamDTO); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.TeamDTO) + } + } + + if rf, ok := ret.Get(1).(func(filters.Filter) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeleteUserFromOrg provides a mock function with given fields: userId, orgId +func (_m *GrafanaService) DeleteUserFromOrg(userId int64, orgId int64) error { + ret := _m.Called(userId, orgId) + + var r0 error + if rf, ok := ret.Get(0).(func(int64, int64) error); ok { + r0 = rf(userId, orgId) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// DownloadAlertNotifications provides a mock function with given fields: +func (_m *GrafanaService) DownloadAlertNotifications() []string { + ret := _m.Called() + + var r0 []string + if rf, ok := ret.Get(0).(func() []string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DownloadConnectionPermissions provides a mock function with given fields: filter +func (_m *GrafanaService) DownloadConnectionPermissions(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DownloadConnections provides a mock function with given fields: filter +func (_m *GrafanaService) DownloadConnections(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DownloadDashboards provides a mock function with given fields: filter +func (_m *GrafanaService) DownloadDashboards(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DownloadFolderPermissions provides a mock function with given fields: filter +func (_m *GrafanaService) DownloadFolderPermissions(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DownloadFolders provides a mock function with given fields: filter +func (_m *GrafanaService) DownloadFolders(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DownloadLibraryElements provides a mock function with given fields: filter +func (_m *GrafanaService) DownloadLibraryElements(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DownloadOrganizations provides a mock function with given fields: +func (_m *GrafanaService) DownloadOrganizations() []string { + ret := _m.Called() + + var r0 []string + if rf, ok := ret.Get(0).(func() []string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DownloadTeams provides a mock function with given fields: filter +func (_m *GrafanaService) DownloadTeams(filter filters.Filter) map[*models.TeamDTO][]*models.TeamMemberDTO { + ret := _m.Called(filter) + + var r0 map[*models.TeamDTO][]*models.TeamMemberDTO + if rf, ok := ret.Get(0).(func(filters.Filter) map[*models.TeamDTO][]*models.TeamMemberDTO); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[*models.TeamDTO][]*models.TeamMemberDTO) + } + } + + return r0 +} + +// DownloadUsers provides a mock function with given fields: filter +func (_m *GrafanaService) DownloadUsers(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// GetServerInfo provides a mock function with given fields: +func (_m *GrafanaService) GetServerInfo() map[string]interface{} { + ret := _m.Called() + + var r0 map[string]interface{} + if rf, ok := ret.Get(0).(func() map[string]interface{}); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[string]interface{}) + } + } + + return r0 +} + +// GetTokenOrganization provides a mock function with given fields: +func (_m *GrafanaService) GetTokenOrganization() *models.OrgDetailsDTO { + ret := _m.Called() + + var r0 *models.OrgDetailsDTO + if rf, ok := ret.Get(0).(func() *models.OrgDetailsDTO); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*models.OrgDetailsDTO) + } + } + + return r0 +} + +// GetUserInfo provides a mock function with given fields: +func (_m *GrafanaService) GetUserInfo() (*models.UserProfileDTO, error) { + ret := _m.Called() + + var r0 *models.UserProfileDTO + var r1 error + if rf, ok := ret.Get(0).(func() (*models.UserProfileDTO, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *models.UserProfileDTO); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*models.UserProfileDTO) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// GetUserOrganization provides a mock function with given fields: +func (_m *GrafanaService) GetUserOrganization() *models.OrgDetailsDTO { + ret := _m.Called() + + var r0 *models.OrgDetailsDTO + if rf, ok := ret.Get(0).(func() *models.OrgDetailsDTO); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*models.OrgDetailsDTO) + } + } + + return r0 +} + +// InitOrganizations provides a mock function with given fields: +func (_m *GrafanaService) InitOrganizations() { + _m.Called() +} + +// ListAPIKeys provides a mock function with given fields: +func (_m *GrafanaService) ListAPIKeys() []*models.APIKeyDTO { + ret := _m.Called() + + var r0 []*models.APIKeyDTO + if rf, ok := ret.Get(0).(func() []*models.APIKeyDTO); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.APIKeyDTO) + } + } + + return r0 +} + +// ListAlertNotifications provides a mock function with given fields: +func (_m *GrafanaService) ListAlertNotifications() []*models.AlertNotification { + ret := _m.Called() + + var r0 []*models.AlertNotification + if rf, ok := ret.Get(0).(func() []*models.AlertNotification); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.AlertNotification) + } + } + + return r0 +} + +// ListConnectionPermissions provides a mock function with given fields: filter +func (_m *GrafanaService) ListConnectionPermissions(filter filters.Filter) map[*models.DataSourceListItemDTO]*models.DataSourcePermissionsDTO { + ret := _m.Called(filter) + + var r0 map[*models.DataSourceListItemDTO]*models.DataSourcePermissionsDTO + if rf, ok := ret.Get(0).(func(filters.Filter) map[*models.DataSourceListItemDTO]*models.DataSourcePermissionsDTO); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[*models.DataSourceListItemDTO]*models.DataSourcePermissionsDTO) + } + } + + return r0 +} + +// ListConnections provides a mock function with given fields: filter +func (_m *GrafanaService) ListConnections(filter filters.Filter) []models.DataSourceListItemDTO { + ret := _m.Called(filter) + + var r0 []models.DataSourceListItemDTO + if rf, ok := ret.Get(0).(func(filters.Filter) []models.DataSourceListItemDTO); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]models.DataSourceListItemDTO) + } + } + + return r0 +} + +// ListDashboards provides a mock function with given fields: filter +func (_m *GrafanaService) ListDashboards(filter filters.Filter) []*models.Hit { + ret := _m.Called(filter) + + var r0 []*models.Hit + if rf, ok := ret.Get(0).(func(filters.Filter) []*models.Hit); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.Hit) + } + } + + return r0 +} + +// ListFolder provides a mock function with given fields: filter +func (_m *GrafanaService) ListFolder(filter filters.Filter) []*models.Hit { + ret := _m.Called(filter) + + var r0 []*models.Hit + if rf, ok := ret.Get(0).(func(filters.Filter) []*models.Hit); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.Hit) + } + } + + return r0 +} + +// ListFolderPermissions provides a mock function with given fields: filter +func (_m *GrafanaService) ListFolderPermissions(filter filters.Filter) map[*models.Hit][]*models.DashboardACLInfoDTO { + ret := _m.Called(filter) + + var r0 map[*models.Hit][]*models.DashboardACLInfoDTO + if rf, ok := ret.Get(0).(func(filters.Filter) map[*models.Hit][]*models.DashboardACLInfoDTO); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[*models.Hit][]*models.DashboardACLInfoDTO) + } + } + + return r0 +} + +// ListLibraryElements provides a mock function with given fields: filter +func (_m *GrafanaService) ListLibraryElements(filter filters.Filter) []*models.LibraryElementDTO { + ret := _m.Called(filter) + + var r0 []*models.LibraryElementDTO + if rf, ok := ret.Get(0).(func(filters.Filter) []*models.LibraryElementDTO); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.LibraryElementDTO) + } + } + + return r0 +} + +// ListLibraryElementsConnections provides a mock function with given fields: filter, connectionID +func (_m *GrafanaService) ListLibraryElementsConnections(filter filters.Filter, connectionID string) []*models.DashboardFullWithMeta { + ret := _m.Called(filter, connectionID) + + var r0 []*models.DashboardFullWithMeta + if rf, ok := ret.Get(0).(func(filters.Filter, string) []*models.DashboardFullWithMeta); ok { + r0 = rf(filter, connectionID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.DashboardFullWithMeta) + } + } + + return r0 +} + +// ListOrgUsers provides a mock function with given fields: orgId +func (_m *GrafanaService) ListOrgUsers(orgId int64) []*models.OrgUserDTO { + ret := _m.Called(orgId) + + var r0 []*models.OrgUserDTO + if rf, ok := ret.Get(0).(func(int64) []*models.OrgUserDTO); ok { + r0 = rf(orgId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.OrgUserDTO) + } + } + + return r0 +} + +// ListOrganizations provides a mock function with given fields: +func (_m *GrafanaService) ListOrganizations() []*models.OrgDTO { + ret := _m.Called() + + var r0 []*models.OrgDTO + if rf, ok := ret.Get(0).(func() []*models.OrgDTO); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.OrgDTO) + } + } + + return r0 +} + +// ListServiceAccounts provides a mock function with given fields: +func (_m *GrafanaService) ListServiceAccounts() []*api.ServiceAccountDTOWithTokens { + ret := _m.Called() + + var r0 []*api.ServiceAccountDTOWithTokens + if rf, ok := ret.Get(0).(func() []*api.ServiceAccountDTOWithTokens); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*api.ServiceAccountDTOWithTokens) + } + } + + return r0 +} + +// ListServiceAccountsTokens provides a mock function with given fields: id +func (_m *GrafanaService) ListServiceAccountsTokens(id int64) ([]*models.TokenDTO, error) { + ret := _m.Called(id) + + var r0 []*models.TokenDTO + var r1 error + if rf, ok := ret.Get(0).(func(int64) ([]*models.TokenDTO, error)); ok { + return rf(id) + } + if rf, ok := ret.Get(0).(func(int64) []*models.TokenDTO); ok { + r0 = rf(id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.TokenDTO) + } + } + + if rf, ok := ret.Get(1).(func(int64) error); ok { + r1 = rf(id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ListTeams provides a mock function with given fields: filter +func (_m *GrafanaService) ListTeams(filter filters.Filter) map[*models.TeamDTO][]*models.TeamMemberDTO { + ret := _m.Called(filter) + + var r0 map[*models.TeamDTO][]*models.TeamMemberDTO + if rf, ok := ret.Get(0).(func(filters.Filter) map[*models.TeamDTO][]*models.TeamMemberDTO); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[*models.TeamDTO][]*models.TeamMemberDTO) + } + } + + return r0 +} + +// ListUsers provides a mock function with given fields: filter +func (_m *GrafanaService) ListUsers(filter filters.Filter) []*models.UserSearchHitDTO { + ret := _m.Called(filter) + + var r0 []*models.UserSearchHitDTO + if rf, ok := ret.Get(0).(func(filters.Filter) []*models.UserSearchHitDTO); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.UserSearchHitDTO) + } + } + + return r0 +} + +// Login provides a mock function with given fields: +func (_m *GrafanaService) Login() { + _m.Called() +} + +// PromoteUser provides a mock function with given fields: userLogin +func (_m *GrafanaService) PromoteUser(userLogin string) (string, error) { + ret := _m.Called(userLogin) + + var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(string) (string, error)); ok { + return rf(userLogin) + } + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(userLogin) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(userLogin) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SetOrganization provides a mock function with given fields: id +func (_m *GrafanaService) SetOrganization(id int64) error { + ret := _m.Called(id) + + var r0 error + if rf, ok := ret.Get(0).(func(int64) error); ok { + r0 = rf(id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// SetUserOrganizations provides a mock function with given fields: id +func (_m *GrafanaService) SetUserOrganizations(id int64) error { + ret := _m.Called(id) + + var r0 error + if rf, ok := ret.Get(0).(func(int64) error); ok { + r0 = rf(id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// UpdateUserInOrg provides a mock function with given fields: role, userId, orgId +func (_m *GrafanaService) UpdateUserInOrg(role string, userId int64, orgId int64) error { + ret := _m.Called(role, userId, orgId) + + var r0 error + if rf, ok := ret.Get(0).(func(string, int64, int64) error); ok { + r0 = rf(role, userId, orgId) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// UploadAlertNotifications provides a mock function with given fields: +func (_m *GrafanaService) UploadAlertNotifications() []string { + ret := _m.Called() + + var r0 []string + if rf, ok := ret.Get(0).(func() []string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// UploadConnectionPermissions provides a mock function with given fields: filter +func (_m *GrafanaService) UploadConnectionPermissions(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// UploadConnections provides a mock function with given fields: filter +func (_m *GrafanaService) UploadConnections(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// UploadDashboards provides a mock function with given fields: filter +func (_m *GrafanaService) UploadDashboards(filter filters.Filter) { + _m.Called(filter) +} + +// UploadFolderPermissions provides a mock function with given fields: filter +func (_m *GrafanaService) UploadFolderPermissions(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// UploadFolders provides a mock function with given fields: filter +func (_m *GrafanaService) UploadFolders(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// UploadLibraryElements provides a mock function with given fields: filter +func (_m *GrafanaService) UploadLibraryElements(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// UploadOrganizations provides a mock function with given fields: +func (_m *GrafanaService) UploadOrganizations() []string { + ret := _m.Called() + + var r0 []string + if rf, ok := ret.Get(0).(func() []string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// UploadTeams provides a mock function with given fields: filter +func (_m *GrafanaService) UploadTeams(filter filters.Filter) map[*models.TeamDTO][]*models.TeamMemberDTO { + ret := _m.Called(filter) + + var r0 map[*models.TeamDTO][]*models.TeamMemberDTO + if rf, ok := ret.Get(0).(func(filters.Filter) map[*models.TeamDTO][]*models.TeamMemberDTO); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[*models.TeamDTO][]*models.TeamMemberDTO) + } + } + + return r0 +} + +// UploadUsers provides a mock function with given fields: filter +func (_m *GrafanaService) UploadUsers(filter filters.Filter) []models.UserProfileDTO { + ret := _m.Called(filter) + + var r0 []models.UserProfileDTO + if rf, ok := ret.Get(0).(func(filters.Filter) []models.UserProfileDTO); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]models.UserProfileDTO) + } + } + + return r0 +} + +// NewGrafanaService creates a new instance of GrafanaService. 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 NewGrafanaService(t interface { + mock.TestingT + Cleanup(func()) +}) *GrafanaService { + mock := &GrafanaService{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/service/mocks/LibraryElementsApi.go b/internal/service/mocks/LibraryElementsApi.go new file mode 100644 index 00000000..278f6b83 --- /dev/null +++ b/internal/service/mocks/LibraryElementsApi.go @@ -0,0 +1,109 @@ +// Code generated by mockery v2.34.0. DO NOT EDIT. + +package mocks + +import ( + filters "github.com/esnet/gdg/internal/service/filters" + mock "github.com/stretchr/testify/mock" + + models "github.com/esnet/grafana-swagger-api-golang/goclient/models" +) + +// LibraryElementsApi is an autogenerated mock type for the LibraryElementsApi type +type LibraryElementsApi struct { + mock.Mock +} + +// DeleteAllLibraryElements provides a mock function with given fields: filter +func (_m *LibraryElementsApi) DeleteAllLibraryElements(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DownloadLibraryElements provides a mock function with given fields: filter +func (_m *LibraryElementsApi) DownloadLibraryElements(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// ListLibraryElements provides a mock function with given fields: filter +func (_m *LibraryElementsApi) ListLibraryElements(filter filters.Filter) []*models.LibraryElementDTO { + ret := _m.Called(filter) + + var r0 []*models.LibraryElementDTO + if rf, ok := ret.Get(0).(func(filters.Filter) []*models.LibraryElementDTO); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.LibraryElementDTO) + } + } + + return r0 +} + +// ListLibraryElementsConnections provides a mock function with given fields: filter, connectionID +func (_m *LibraryElementsApi) ListLibraryElementsConnections(filter filters.Filter, connectionID string) []*models.DashboardFullWithMeta { + ret := _m.Called(filter, connectionID) + + var r0 []*models.DashboardFullWithMeta + if rf, ok := ret.Get(0).(func(filters.Filter, string) []*models.DashboardFullWithMeta); ok { + r0 = rf(filter, connectionID) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.DashboardFullWithMeta) + } + } + + return r0 +} + +// UploadLibraryElements provides a mock function with given fields: filter +func (_m *LibraryElementsApi) UploadLibraryElements(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// NewLibraryElementsApi creates a new instance of LibraryElementsApi. 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 NewLibraryElementsApi(t interface { + mock.TestingT + Cleanup(func()) +}) *LibraryElementsApi { + mock := &LibraryElementsApi{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/service/mocks/OrganizationsApi.go b/internal/service/mocks/OrganizationsApi.go new file mode 100644 index 00000000..c0b00ff7 --- /dev/null +++ b/internal/service/mocks/OrganizationsApi.go @@ -0,0 +1,198 @@ +// Code generated by mockery v2.34.0. DO NOT EDIT. + +package mocks + +import ( + models "github.com/esnet/grafana-swagger-api-golang/goclient/models" + mock "github.com/stretchr/testify/mock" +) + +// OrganizationsApi is an autogenerated mock type for the OrganizationsApi type +type OrganizationsApi struct { + mock.Mock +} + +// AddUserToOrg provides a mock function with given fields: role, userId, orgId +func (_m *OrganizationsApi) AddUserToOrg(role string, userId int64, orgId int64) error { + ret := _m.Called(role, userId, orgId) + + var r0 error + if rf, ok := ret.Get(0).(func(string, int64, int64) error); ok { + r0 = rf(role, userId, orgId) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// DeleteUserFromOrg provides a mock function with given fields: userId, orgId +func (_m *OrganizationsApi) DeleteUserFromOrg(userId int64, orgId int64) error { + ret := _m.Called(userId, orgId) + + var r0 error + if rf, ok := ret.Get(0).(func(int64, int64) error); ok { + r0 = rf(userId, orgId) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// DownloadOrganizations provides a mock function with given fields: +func (_m *OrganizationsApi) DownloadOrganizations() []string { + ret := _m.Called() + + var r0 []string + if rf, ok := ret.Get(0).(func() []string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// GetTokenOrganization provides a mock function with given fields: +func (_m *OrganizationsApi) GetTokenOrganization() *models.OrgDetailsDTO { + ret := _m.Called() + + var r0 *models.OrgDetailsDTO + if rf, ok := ret.Get(0).(func() *models.OrgDetailsDTO); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*models.OrgDetailsDTO) + } + } + + return r0 +} + +// GetUserOrganization provides a mock function with given fields: +func (_m *OrganizationsApi) GetUserOrganization() *models.OrgDetailsDTO { + ret := _m.Called() + + var r0 *models.OrgDetailsDTO + if rf, ok := ret.Get(0).(func() *models.OrgDetailsDTO); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*models.OrgDetailsDTO) + } + } + + return r0 +} + +// InitOrganizations provides a mock function with given fields: +func (_m *OrganizationsApi) InitOrganizations() { + _m.Called() +} + +// ListOrgUsers provides a mock function with given fields: orgId +func (_m *OrganizationsApi) ListOrgUsers(orgId int64) []*models.OrgUserDTO { + ret := _m.Called(orgId) + + var r0 []*models.OrgUserDTO + if rf, ok := ret.Get(0).(func(int64) []*models.OrgUserDTO); ok { + r0 = rf(orgId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.OrgUserDTO) + } + } + + return r0 +} + +// ListOrganizations provides a mock function with given fields: +func (_m *OrganizationsApi) ListOrganizations() []*models.OrgDTO { + ret := _m.Called() + + var r0 []*models.OrgDTO + if rf, ok := ret.Get(0).(func() []*models.OrgDTO); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.OrgDTO) + } + } + + return r0 +} + +// SetOrganization provides a mock function with given fields: id +func (_m *OrganizationsApi) SetOrganization(id int64) error { + ret := _m.Called(id) + + var r0 error + if rf, ok := ret.Get(0).(func(int64) error); ok { + r0 = rf(id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// SetUserOrganizations provides a mock function with given fields: id +func (_m *OrganizationsApi) SetUserOrganizations(id int64) error { + ret := _m.Called(id) + + var r0 error + if rf, ok := ret.Get(0).(func(int64) error); ok { + r0 = rf(id) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// UpdateUserInOrg provides a mock function with given fields: role, userId, orgId +func (_m *OrganizationsApi) UpdateUserInOrg(role string, userId int64, orgId int64) error { + ret := _m.Called(role, userId, orgId) + + var r0 error + if rf, ok := ret.Get(0).(func(string, int64, int64) error); ok { + r0 = rf(role, userId, orgId) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// UploadOrganizations provides a mock function with given fields: +func (_m *OrganizationsApi) UploadOrganizations() []string { + ret := _m.Called() + + var r0 []string + if rf, ok := ret.Get(0).(func() []string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// NewOrganizationsApi creates a new instance of OrganizationsApi. 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 NewOrganizationsApi(t interface { + mock.TestingT + Cleanup(func()) +}) *OrganizationsApi { + mock := &OrganizationsApi{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/service/mocks/ServiceAccountApi.go b/internal/service/mocks/ServiceAccountApi.go new file mode 100644 index 00000000..f6c6b631 --- /dev/null +++ b/internal/service/mocks/ServiceAccountApi.go @@ -0,0 +1,155 @@ +// Code generated by mockery v2.34.0. DO NOT EDIT. + +package mocks + +import ( + api "github.com/esnet/gdg/internal/api" + mock "github.com/stretchr/testify/mock" + + models "github.com/esnet/grafana-swagger-api-golang/goclient/models" +) + +// ServiceAccountApi is an autogenerated mock type for the ServiceAccountApi type +type ServiceAccountApi struct { + mock.Mock +} + +// CreateServiceAccount provides a mock function with given fields: name, role, expiration +func (_m *ServiceAccountApi) CreateServiceAccount(name string, role string, expiration int64) (*models.ServiceAccountDTO, error) { + ret := _m.Called(name, role, expiration) + + var r0 *models.ServiceAccountDTO + var r1 error + if rf, ok := ret.Get(0).(func(string, string, int64) (*models.ServiceAccountDTO, error)); ok { + return rf(name, role, expiration) + } + if rf, ok := ret.Get(0).(func(string, string, int64) *models.ServiceAccountDTO); ok { + r0 = rf(name, role, expiration) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*models.ServiceAccountDTO) + } + } + + if rf, ok := ret.Get(1).(func(string, string, int64) error); ok { + r1 = rf(name, role, expiration) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// CreateServiceAccountToken provides a mock function with given fields: name, role, expiration +func (_m *ServiceAccountApi) CreateServiceAccountToken(name int64, role string, expiration int64) (*models.NewAPIKeyResult, error) { + ret := _m.Called(name, role, expiration) + + var r0 *models.NewAPIKeyResult + var r1 error + if rf, ok := ret.Get(0).(func(int64, string, int64) (*models.NewAPIKeyResult, error)); ok { + return rf(name, role, expiration) + } + if rf, ok := ret.Get(0).(func(int64, string, int64) *models.NewAPIKeyResult); ok { + r0 = rf(name, role, expiration) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*models.NewAPIKeyResult) + } + } + + if rf, ok := ret.Get(1).(func(int64, string, int64) error); ok { + r1 = rf(name, role, expiration) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeleteAllServiceAccounts provides a mock function with given fields: +func (_m *ServiceAccountApi) DeleteAllServiceAccounts() []string { + ret := _m.Called() + + var r0 []string + if rf, ok := ret.Get(0).(func() []string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DeleteServiceAccountTokens provides a mock function with given fields: serviceId +func (_m *ServiceAccountApi) DeleteServiceAccountTokens(serviceId int64) []string { + ret := _m.Called(serviceId) + + var r0 []string + if rf, ok := ret.Get(0).(func(int64) []string); ok { + r0 = rf(serviceId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// ListServiceAccounts provides a mock function with given fields: +func (_m *ServiceAccountApi) ListServiceAccounts() []*api.ServiceAccountDTOWithTokens { + ret := _m.Called() + + var r0 []*api.ServiceAccountDTOWithTokens + if rf, ok := ret.Get(0).(func() []*api.ServiceAccountDTOWithTokens); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*api.ServiceAccountDTOWithTokens) + } + } + + return r0 +} + +// ListServiceAccountsTokens provides a mock function with given fields: id +func (_m *ServiceAccountApi) ListServiceAccountsTokens(id int64) ([]*models.TokenDTO, error) { + ret := _m.Called(id) + + var r0 []*models.TokenDTO + var r1 error + if rf, ok := ret.Get(0).(func(int64) ([]*models.TokenDTO, error)); ok { + return rf(id) + } + if rf, ok := ret.Get(0).(func(int64) []*models.TokenDTO); ok { + r0 = rf(id) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.TokenDTO) + } + } + + if rf, ok := ret.Get(1).(func(int64) error); ok { + r1 = rf(id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// NewServiceAccountApi creates a new instance of ServiceAccountApi. 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 NewServiceAccountApi(t interface { + mock.TestingT + Cleanup(func()) +}) *ServiceAccountApi { + mock := &ServiceAccountApi{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/service/mocks/Storage.go b/internal/service/mocks/Storage.go new file mode 100644 index 00000000..40f0a5ab --- /dev/null +++ b/internal/service/mocks/Storage.go @@ -0,0 +1,104 @@ +// Code generated by mockery v2.34.0. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// Storage is an autogenerated mock type for the Storage type +type Storage struct { + mock.Mock +} + +// FindAllFiles provides a mock function with given fields: folder, fullPath +func (_m *Storage) FindAllFiles(folder string, fullPath bool) ([]string, error) { + ret := _m.Called(folder, fullPath) + + var r0 []string + var r1 error + if rf, ok := ret.Get(0).(func(string, bool) ([]string, error)); ok { + return rf(folder, fullPath) + } + if rf, ok := ret.Get(0).(func(string, bool) []string); ok { + r0 = rf(folder, fullPath) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + if rf, ok := ret.Get(1).(func(string, bool) error); ok { + r1 = rf(folder, fullPath) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Name provides a mock function with given fields: +func (_m *Storage) Name() string { + ret := _m.Called() + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// ReadFile provides a mock function with given fields: filename +func (_m *Storage) ReadFile(filename string) ([]byte, error) { + ret := _m.Called(filename) + + var r0 []byte + var r1 error + if rf, ok := ret.Get(0).(func(string) ([]byte, error)); ok { + return rf(filename) + } + if rf, ok := ret.Get(0).(func(string) []byte); ok { + r0 = rf(filename) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(filename) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// WriteFile provides a mock function with given fields: filename, data +func (_m *Storage) WriteFile(filename string, data []byte) error { + ret := _m.Called(filename, data) + + var r0 error + if rf, ok := ret.Get(0).(func(string, []byte) error); ok { + r0 = rf(filename, data) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// NewStorage creates a new instance of Storage. 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 NewStorage(t interface { + mock.TestingT + Cleanup(func()) +}) *Storage { + mock := &Storage{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/service/mocks/TeamsApi.go b/internal/service/mocks/TeamsApi.go new file mode 100644 index 00000000..59cc906b --- /dev/null +++ b/internal/service/mocks/TeamsApi.go @@ -0,0 +1,103 @@ +// Code generated by mockery v2.34.0. DO NOT EDIT. + +package mocks + +import ( + filters "github.com/esnet/gdg/internal/service/filters" + mock "github.com/stretchr/testify/mock" + + models "github.com/esnet/grafana-swagger-api-golang/goclient/models" +) + +// TeamsApi is an autogenerated mock type for the TeamsApi type +type TeamsApi struct { + mock.Mock +} + +// DeleteTeam provides a mock function with given fields: filter +func (_m *TeamsApi) DeleteTeam(filter filters.Filter) ([]*models.TeamDTO, error) { + ret := _m.Called(filter) + + var r0 []*models.TeamDTO + var r1 error + if rf, ok := ret.Get(0).(func(filters.Filter) ([]*models.TeamDTO, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(filters.Filter) []*models.TeamDTO); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.TeamDTO) + } + } + + if rf, ok := ret.Get(1).(func(filters.Filter) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DownloadTeams provides a mock function with given fields: filter +func (_m *TeamsApi) DownloadTeams(filter filters.Filter) map[*models.TeamDTO][]*models.TeamMemberDTO { + ret := _m.Called(filter) + + var r0 map[*models.TeamDTO][]*models.TeamMemberDTO + if rf, ok := ret.Get(0).(func(filters.Filter) map[*models.TeamDTO][]*models.TeamMemberDTO); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[*models.TeamDTO][]*models.TeamMemberDTO) + } + } + + return r0 +} + +// ListTeams provides a mock function with given fields: filter +func (_m *TeamsApi) ListTeams(filter filters.Filter) map[*models.TeamDTO][]*models.TeamMemberDTO { + ret := _m.Called(filter) + + var r0 map[*models.TeamDTO][]*models.TeamMemberDTO + if rf, ok := ret.Get(0).(func(filters.Filter) map[*models.TeamDTO][]*models.TeamMemberDTO); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[*models.TeamDTO][]*models.TeamMemberDTO) + } + } + + return r0 +} + +// UploadTeams provides a mock function with given fields: filter +func (_m *TeamsApi) UploadTeams(filter filters.Filter) map[*models.TeamDTO][]*models.TeamMemberDTO { + ret := _m.Called(filter) + + var r0 map[*models.TeamDTO][]*models.TeamMemberDTO + if rf, ok := ret.Get(0).(func(filters.Filter) map[*models.TeamDTO][]*models.TeamMemberDTO); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(map[*models.TeamDTO][]*models.TeamMemberDTO) + } + } + + return r0 +} + +// NewTeamsApi creates a new instance of TeamsApi. 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 NewTeamsApi(t interface { + mock.TestingT + Cleanup(func()) +}) *TeamsApi { + mock := &TeamsApi{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/service/mocks/TokenApi.go b/internal/service/mocks/TokenApi.go new file mode 100644 index 00000000..22d58574 --- /dev/null +++ b/internal/service/mocks/TokenApi.go @@ -0,0 +1,85 @@ +// Code generated by mockery v2.34.0. DO NOT EDIT. + +package mocks + +import ( + models "github.com/esnet/grafana-swagger-api-golang/goclient/models" + mock "github.com/stretchr/testify/mock" +) + +// TokenApi is an autogenerated mock type for the TokenApi type +type TokenApi struct { + mock.Mock +} + +// CreateAPIKey provides a mock function with given fields: name, role, expiration +func (_m *TokenApi) CreateAPIKey(name string, role string, expiration int64) (*models.NewAPIKeyResult, error) { + ret := _m.Called(name, role, expiration) + + var r0 *models.NewAPIKeyResult + var r1 error + if rf, ok := ret.Get(0).(func(string, string, int64) (*models.NewAPIKeyResult, error)); ok { + return rf(name, role, expiration) + } + if rf, ok := ret.Get(0).(func(string, string, int64) *models.NewAPIKeyResult); ok { + r0 = rf(name, role, expiration) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*models.NewAPIKeyResult) + } + } + + if rf, ok := ret.Get(1).(func(string, string, int64) error); ok { + r1 = rf(name, role, expiration) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeleteAllTokens provides a mock function with given fields: +func (_m *TokenApi) DeleteAllTokens() []string { + ret := _m.Called() + + var r0 []string + if rf, ok := ret.Get(0).(func() []string); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// ListAPIKeys provides a mock function with given fields: +func (_m *TokenApi) ListAPIKeys() []*models.APIKeyDTO { + ret := _m.Called() + + var r0 []*models.APIKeyDTO + if rf, ok := ret.Get(0).(func() []*models.APIKeyDTO); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.APIKeyDTO) + } + } + + return r0 +} + +// NewTokenApi creates a new instance of TokenApi. 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 NewTokenApi(t interface { + mock.TestingT + Cleanup(func()) +}) *TokenApi { + mock := &TokenApi{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/service/mocks/UsersApi.go b/internal/service/mocks/UsersApi.go new file mode 100644 index 00000000..7f3d0103 --- /dev/null +++ b/internal/service/mocks/UsersApi.go @@ -0,0 +1,143 @@ +// Code generated by mockery v2.34.0. DO NOT EDIT. + +package mocks + +import ( + filters "github.com/esnet/gdg/internal/service/filters" + mock "github.com/stretchr/testify/mock" + + models "github.com/esnet/grafana-swagger-api-golang/goclient/models" +) + +// UsersApi is an autogenerated mock type for the UsersApi type +type UsersApi struct { + mock.Mock +} + +// DeleteAllUsers provides a mock function with given fields: filter +func (_m *UsersApi) DeleteAllUsers(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// DownloadUsers provides a mock function with given fields: filter +func (_m *UsersApi) DownloadUsers(filter filters.Filter) []string { + ret := _m.Called(filter) + + var r0 []string + if rf, ok := ret.Get(0).(func(filters.Filter) []string); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + return r0 +} + +// GetUserInfo provides a mock function with given fields: +func (_m *UsersApi) GetUserInfo() (*models.UserProfileDTO, error) { + ret := _m.Called() + + var r0 *models.UserProfileDTO + var r1 error + if rf, ok := ret.Get(0).(func() (*models.UserProfileDTO, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *models.UserProfileDTO); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*models.UserProfileDTO) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ListUsers provides a mock function with given fields: filter +func (_m *UsersApi) ListUsers(filter filters.Filter) []*models.UserSearchHitDTO { + ret := _m.Called(filter) + + var r0 []*models.UserSearchHitDTO + if rf, ok := ret.Get(0).(func(filters.Filter) []*models.UserSearchHitDTO); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*models.UserSearchHitDTO) + } + } + + return r0 +} + +// PromoteUser provides a mock function with given fields: userLogin +func (_m *UsersApi) PromoteUser(userLogin string) (string, error) { + ret := _m.Called(userLogin) + + var r0 string + var r1 error + if rf, ok := ret.Get(0).(func(string) (string, error)); ok { + return rf(userLogin) + } + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(userLogin) + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(userLogin) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// UploadUsers provides a mock function with given fields: filter +func (_m *UsersApi) UploadUsers(filter filters.Filter) []models.UserProfileDTO { + ret := _m.Called(filter) + + var r0 []models.UserProfileDTO + if rf, ok := ret.Get(0).(func(filters.Filter) []models.UserProfileDTO); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]models.UserProfileDTO) + } + } + + return r0 +} + +// NewUsersApi creates a new instance of UsersApi. 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 NewUsersApi(t interface { + mock.TestingT + Cleanup(func()) +}) *UsersApi { + mock := &UsersApi{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/main.go b/main.go index 3aaa07cd..25e47029 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,9 @@ package main import ( _ "embed" "github.com/esnet/gdg/cmd" + "github.com/esnet/gdg/cmd/support" applogger "github.com/esnet/gdg/internal/log" + api "github.com/esnet/gdg/internal/service" log "github.com/sirupsen/logrus" "os" ) @@ -11,9 +13,22 @@ import ( //go:embed config/importer-example.yml var defaultConfig string +var ( + f = func() api.GrafanaService { + return api.NewApiService() + } +) + func main() { applogger.InitializeAppLogger() - err := cmd.Execute(defaultConfig, os.Args[1:]) + + option := func() support.RootOption { + return func(response *support.RootCommand) { + response.GrafanaSvc = f + } + } + + err := cmd.Execute(defaultConfig, os.Args[1:], option()) if err != nil { log.Fatalf("Error: %s", err) }