Plugins: Move store init to dskit service (#111823)

This commit is contained in:
Todd Treece
2025-10-02 19:53:31 -04:00
committed by GitHub
parent 5798181fb0
commit 2d232aa10d
16 changed files with 394 additions and 222 deletions
@@ -26,7 +26,7 @@ func TestService_IsDisabled(t *testing.T) {
&setting.Cfg{
PreinstallPluginsAsync: []setting.InstallPlugin{{ID: "myplugin"}},
},
pluginstore.New(registry.NewInMemory(), &fakes.FakeLoader{}),
pluginstore.New(registry.NewInMemory(), &fakes.FakeLoader{}, &fakes.FakeSourceRegistry{}),
&fakes.FakePluginInstaller{},
prometheus.NewRegistry(),
&fakes.FakePluginRepo{},
@@ -160,12 +160,14 @@ func TestService_Run(t *testing.T) {
}
installed := 0
installedFromURL := 0
store, err := pluginstore.NewPluginStoreForTest(preg, &fakes.FakeLoader{}, &fakes.FakeSourceRegistry{})
require.NoError(t, err)
s, err := ProvideService(
&setting.Cfg{
PreinstallPluginsAsync: tt.pluginsToInstall,
PreinstallPluginsSync: tt.pluginsToInstallSync,
},
pluginstore.New(preg, &fakes.FakeLoader{}),
store,
&fakes.FakePluginInstaller{
AddFunc: func(ctx context.Context, pluginID string, version string, opts plugins.AddOpts) error {
for _, plugin := range tt.pluginsToFail {
@@ -203,13 +205,26 @@ func TestService_Run(t *testing.T) {
&pluginchecker.FakePluginPreinstall{},
),
)
require.NoError(t, err)
t.Cleanup(func() {
s.StopAsync()
err := s.AwaitTerminated(context.Background())
if tt.shouldThrowError {
require.ErrorContains(t, err, "Failed to install plugin")
return
}
require.NoError(t, err)
})
err = s.StartAsync(context.Background())
require.NoError(t, err)
err = s.AwaitRunning(context.Background())
if tt.shouldThrowError {
require.ErrorContains(t, err, "Failed to install plugin")
return
}
require.NoError(t, err)
err = s.Run(context.Background())
require.NoError(t, err)
if tt.shouldInstall {
expectedInstalled := 0
@@ -232,6 +247,7 @@ func TestService_Run(t *testing.T) {
expectedInstalled++
}
}
<-s.installComplete
require.Equal(t, expectedInstalled, installed)
require.Equal(t, expectedInstalledFromURL, installedFromURL)
}