Chore: Remove context.TODO() (#43409)

* Remove context.TODO() from services

* Fix live test

* Remove context.TODO
This commit is contained in:
idafurjes
2021-12-22 11:02:42 +01:00
committed by GitHub
parent 2409d8dc1f
commit b8852ef6a3
45 changed files with 133 additions and 126 deletions
@@ -14,7 +14,7 @@ import (
)
type configReader interface {
readConfig(path string) ([]*pluginsAsConfig, error)
readConfig(ctx context.Context, path string) ([]*pluginsAsConfig, error)
}
type configReaderImpl struct {
@@ -26,7 +26,7 @@ func newConfigReader(logger log.Logger, pluginStore plugins.Store) configReader
return &configReaderImpl{log: logger, pluginStore: pluginStore}
}
func (cr *configReaderImpl) readConfig(path string) ([]*pluginsAsConfig, error) {
func (cr *configReaderImpl) readConfig(ctx context.Context, path string) ([]*pluginsAsConfig, error) {
var apps []*pluginsAsConfig
cr.log.Debug("Looking for plugin provisioning files", "path", path)
@@ -57,7 +57,7 @@ func (cr *configReaderImpl) readConfig(path string) ([]*pluginsAsConfig, error)
checkOrgIDAndOrgName(apps)
err = cr.validatePluginsConfig(apps)
err = cr.validatePluginsConfig(ctx, apps)
if err != nil {
return nil, err
}
@@ -107,14 +107,14 @@ func validateRequiredField(apps []*pluginsAsConfig) error {
return nil
}
func (cr *configReaderImpl) validatePluginsConfig(apps []*pluginsAsConfig) error {
func (cr *configReaderImpl) validatePluginsConfig(ctx context.Context, apps []*pluginsAsConfig) error {
for i := range apps {
if apps[i].Apps == nil {
continue
}
for _, app := range apps[i].Apps {
if _, exists := cr.pluginStore.Plugin(context.TODO(), app.PluginID); !exists {
if _, exists := cr.pluginStore.Plugin(ctx, app.PluginID); !exists {
return fmt.Errorf("plugin not installed: %q", app.PluginID)
}
}
@@ -21,27 +21,27 @@ const (
func TestConfigReader(t *testing.T) {
t.Run("Broken yaml should return error", func(t *testing.T) {
reader := newConfigReader(log.New("test logger"), nil)
_, err := reader.readConfig(brokenYaml)
_, err := reader.readConfig(context.Background(), brokenYaml)
require.Error(t, err)
})
t.Run("Skip invalid directory", func(t *testing.T) {
cfgProvider := newConfigReader(log.New("test logger"), nil)
cfg, err := cfgProvider.readConfig(emptyFolder)
cfg, err := cfgProvider.readConfig(context.Background(), emptyFolder)
require.NoError(t, err)
require.Len(t, cfg, 0)
})
t.Run("Unknown app plugin should return error", func(t *testing.T) {
cfgProvider := newConfigReader(log.New("test logger"), fakePluginStore{})
_, err := cfgProvider.readConfig(unknownApp)
_, err := cfgProvider.readConfig(context.Background(), unknownApp)
require.Error(t, err)
require.Equal(t, "plugin not installed: \"nonexisting\"", err.Error())
})
t.Run("Read incorrect properties", func(t *testing.T) {
cfgProvider := newConfigReader(log.New("test logger"), nil)
_, err := cfgProvider.readConfig(incorrectSettings)
_, err := cfgProvider.readConfig(context.Background(), incorrectSettings)
require.Error(t, err)
require.Equal(t, "app item 1 in configuration doesn't contain required field type", err.Error())
})
@@ -61,7 +61,7 @@ func TestConfigReader(t *testing.T) {
})
cfgProvider := newConfigReader(log.New("test logger"), pm)
cfg, err := cfgProvider.readConfig(correctProperties)
cfg, err := cfgProvider.readConfig(context.Background(), correctProperties)
require.NoError(t, err)
require.Len(t, cfg, 1)
@@ -69,7 +69,7 @@ func (ap *PluginProvisioner) apply(ctx context.Context, cfg *pluginsAsConfig) er
}
func (ap *PluginProvisioner) applyChanges(ctx context.Context, configPath string) error {
configs, err := ap.cfgProvider.readConfig(configPath)
configs, err := ap.cfgProvider.readConfig(ctx, configPath)
if err != nil {
return err
}
@@ -91,6 +91,6 @@ type testConfigReader struct {
err error
}
func (tcr *testConfigReader) readConfig(path string) ([]*pluginsAsConfig, error) {
func (tcr *testConfigReader) readConfig(ctx context.Context, path string) ([]*pluginsAsConfig, error) {
return tcr.result, tcr.err
}