mirror of
https://github.com/grafana/grafana.git
synced 2025-01-16 19:52:33 -06:00
eb31f71f60
* Enable feature toggle pluginsDynamicAngularDetectionPatterns by default * Change backgroundJobInterval to 24h * re-generate feature toggles * Use different intervals for cloud vs on-prem * temporarily switch interval log to info level * debug level again * Simplify provideDynamic for tests * re-generated feature toggles files * PR review feedback * PR review feedback: removed dependency from plugin management config
57 lines
2.6 KiB
Go
57 lines
2.6 KiB
Go
package angularinspector
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/grafana/grafana/pkg/infra/kvstore"
|
|
"github.com/grafana/grafana/pkg/plugins/manager/loader/angular/angulardetector"
|
|
"github.com/grafana/grafana/pkg/plugins/manager/loader/angular/angularinspector"
|
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/angulardetectorsprovider"
|
|
"github.com/grafana/grafana/pkg/services/pluginsintegration/angularpatternsstore"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
)
|
|
|
|
func TestProvideService(t *testing.T) {
|
|
t.Run("uses hardcoded inspector if feature flag is not present", func(t *testing.T) {
|
|
features := featuremgmt.WithFeatures()
|
|
dynamic, err := angulardetectorsprovider.ProvideDynamic(
|
|
setting.NewCfg(),
|
|
angularpatternsstore.ProvideService(kvstore.NewFakeKVStore()),
|
|
features,
|
|
)
|
|
require.NoError(t, err)
|
|
inspector, err := ProvideService(features, dynamic)
|
|
require.NoError(t, err)
|
|
require.IsType(t, inspector.Inspector, &angularinspector.PatternsListInspector{})
|
|
patternsListInspector := inspector.Inspector.(*angularinspector.PatternsListInspector)
|
|
detectors := patternsListInspector.DetectorsProvider.ProvideDetectors(context.Background())
|
|
require.NotEmpty(t, detectors, "provided detectors should not be empty")
|
|
})
|
|
|
|
t.Run("uses dynamic inspector with hardcoded fallback if feature flag is present", func(t *testing.T) {
|
|
features := featuremgmt.WithFeatures(
|
|
featuremgmt.FlagPluginsDynamicAngularDetectionPatterns,
|
|
)
|
|
dynamic, err := angulardetectorsprovider.ProvideDynamic(
|
|
setting.NewCfg(),
|
|
angularpatternsstore.ProvideService(kvstore.NewFakeKVStore()),
|
|
features,
|
|
)
|
|
require.NoError(t, err)
|
|
inspector, err := ProvideService(features, dynamic)
|
|
require.NoError(t, err)
|
|
require.IsType(t, inspector.Inspector, &angularinspector.PatternsListInspector{})
|
|
require.IsType(t, inspector.Inspector.(*angularinspector.PatternsListInspector).DetectorsProvider, angulardetector.SequenceDetectorsProvider{})
|
|
seq := inspector.Inspector.(*angularinspector.PatternsListInspector).DetectorsProvider.(angulardetector.SequenceDetectorsProvider)
|
|
require.Len(t, seq, 2, "should return the correct number of providers")
|
|
require.IsType(t, seq[0], &angulardetectorsprovider.Dynamic{}, "first AngularDetector provided should be gcom")
|
|
require.IsType(t, seq[1], &angulardetector.StaticDetectorsProvider{}, "second AngularDetector provided should be static")
|
|
staticDetectors := seq[1].ProvideDetectors(context.Background())
|
|
require.NotEmpty(t, staticDetectors, "provided static detectors should not be empty")
|
|
})
|
|
}
|