mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Removed context.Context from DetectorsProvider
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package angulardetector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
@@ -44,7 +43,7 @@ func TestRegexDetector(t *testing.T) {
|
||||
|
||||
func TestStaticDetectorsProvider(t *testing.T) {
|
||||
p := StaticDetectorsProvider{Detectors: testDetectors}
|
||||
detectors := p.ProvideDetectors(context.Background())
|
||||
detectors := p.ProvideDetectors()
|
||||
require.NotEmpty(t, detectors)
|
||||
require.Equal(t, testDetectors, detectors)
|
||||
}
|
||||
@@ -54,7 +53,7 @@ type fakeDetectorsProvider struct {
|
||||
returns []AngularDetector
|
||||
}
|
||||
|
||||
func (p *fakeDetectorsProvider) ProvideDetectors(_ context.Context) []AngularDetector {
|
||||
func (p *fakeDetectorsProvider) ProvideDetectors() []AngularDetector {
|
||||
p.calls += 1
|
||||
return p.returns
|
||||
}
|
||||
@@ -113,7 +112,7 @@ func TestSequenceDetectorsProvider(t *testing.T) {
|
||||
for _, p := range tc.fakeProviders {
|
||||
seq = append(seq, DetectorsProvider(p))
|
||||
}
|
||||
detectors := seq.ProvideDetectors(context.Background())
|
||||
detectors := seq.ProvideDetectors()
|
||||
tc.exp(t, tc.fakeProviders, detectors)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package angulardetector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
// DetectorsProvider can provide multiple AngularDetectors used for Angular detection.
|
||||
type DetectorsProvider interface {
|
||||
// ProvideDetectors returns a slice of AngularDetector.
|
||||
ProvideDetectors(ctx context.Context) []AngularDetector
|
||||
ProvideDetectors() []AngularDetector
|
||||
}
|
||||
|
||||
// StaticDetectorsProvider is a DetectorsProvider that always returns a pre-defined slice of AngularDetector.
|
||||
@@ -16,7 +15,7 @@ type StaticDetectorsProvider struct {
|
||||
Detectors []AngularDetector
|
||||
}
|
||||
|
||||
func (p *StaticDetectorsProvider) ProvideDetectors(_ context.Context) []AngularDetector {
|
||||
func (p *StaticDetectorsProvider) ProvideDetectors() []AngularDetector {
|
||||
return p.Detectors
|
||||
}
|
||||
|
||||
@@ -24,9 +23,9 @@ func (p *StaticDetectorsProvider) ProvideDetectors(_ context.Context) []AngularD
|
||||
// provided result that isn't empty.
|
||||
type SequenceDetectorsProvider []DetectorsProvider
|
||||
|
||||
func (p SequenceDetectorsProvider) ProvideDetectors(ctx context.Context) []AngularDetector {
|
||||
func (p SequenceDetectorsProvider) ProvideDetectors() []AngularDetector {
|
||||
for _, provider := range p {
|
||||
if detectors := provider.ProvideDetectors(ctx); len(detectors) > 0 {
|
||||
if detectors := provider.ProvideDetectors(); len(detectors) > 0 {
|
||||
return detectors
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func (i *PatternsListInspector) Inspect(ctx context.Context, p *plugins.Plugin)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("module.js readall: %w", err)
|
||||
}
|
||||
for _, d := range i.DetectorsProvider.ProvideDetectors(ctx) {
|
||||
for _, d := range i.DetectorsProvider.ProvideDetectors() {
|
||||
if d.DetectAngular(b) {
|
||||
isAngular = true
|
||||
break
|
||||
|
||||
@@ -262,8 +262,7 @@ func (d *Dynamic) Run(ctx context.Context) error {
|
||||
}
|
||||
|
||||
// ProvideDetectors returns the cached detectors. It returns an empty slice if there's no value.
|
||||
// TODO: remove context here?
|
||||
func (d *Dynamic) ProvideDetectors(_ context.Context) []angulardetector.AngularDetector {
|
||||
func (d *Dynamic) ProvideDetectors() []angulardetector.AngularDetector {
|
||||
// Block until channel is closed, which is done after the restore from db is done.
|
||||
<-d.initialRestoreDone
|
||||
|
||||
|
||||
@@ -60,14 +60,14 @@ func TestDynamicAngularDetectorsProvider(t *testing.T) {
|
||||
t.Run("ProvideDetectors", func(t *testing.T) {
|
||||
t.Run("returns empty result by default", func(t *testing.T) {
|
||||
svc := provideDynamic(t, srv.URL, defaultCacheTTL, dynamicWithInitialRestoreDone)
|
||||
r := svc.ProvideDetectors(context.Background())
|
||||
r := svc.ProvideDetectors()
|
||||
require.Empty(t, r)
|
||||
})
|
||||
|
||||
t.Run("returns cached detectors", func(t *testing.T) {
|
||||
svc := provideDynamic(t, srv.URL, defaultCacheTTL, dynamicWithInitialRestoreDone)
|
||||
svc.setDetectors(mockGCOMDetectors)
|
||||
checkMockDetectors(t, svc.ProvideDetectors(context.Background()))
|
||||
checkMockDetectors(t, svc.ProvideDetectors())
|
||||
})
|
||||
|
||||
t.Run("awaits initial restore done", func(t *testing.T) {
|
||||
@@ -81,7 +81,7 @@ func TestDynamicAngularDetectorsProvider(t *testing.T) {
|
||||
// ensure the value is read and this goroutine exits
|
||||
done <- struct{}{}
|
||||
}()
|
||||
r := svc.ProvideDetectors(context.Background())
|
||||
r := svc.ProvideDetectors()
|
||||
checkMockDetectors(t, r)
|
||||
<-done
|
||||
})
|
||||
@@ -214,7 +214,7 @@ func TestDynamicAngularDetectorsProvider(t *testing.T) {
|
||||
bg := newBackgroundServiceScenario(svc, func() {})
|
||||
t.Cleanup(bg.close)
|
||||
bg.run(context.Background(), t)
|
||||
d := svc.ProvideDetectors(context.Background())
|
||||
d := svc.ProvideDetectors()
|
||||
checkMockDetectors(t, d)
|
||||
require.False(t, gcom.httpCalls.called(), "gcom api should not be called")
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package angularinspector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -24,7 +23,7 @@ func TestProvideService(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.IsType(t, inspector.Inspector, &angularinspector.PatternsListInspector{})
|
||||
patternsListInspector := inspector.Inspector.(*angularinspector.PatternsListInspector)
|
||||
detectors := patternsListInspector.DetectorsProvider.ProvideDetectors(context.Background())
|
||||
detectors := patternsListInspector.DetectorsProvider.ProvideDetectors()
|
||||
require.NotEmpty(t, detectors, "provided detectors should not be empty")
|
||||
})
|
||||
|
||||
@@ -42,7 +41,7 @@ func TestProvideService(t *testing.T) {
|
||||
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())
|
||||
staticDetectors := seq[1].ProvideDetectors()
|
||||
require.NotEmpty(t, staticDetectors, "provided static detectors should not be empty")
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user