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