|
|
|
|
@ -7,6 +7,10 @@ import ( |
|
|
|
|
"net/http/httptest" |
|
|
|
|
"testing" |
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert" |
|
|
|
|
"github.com/stretchr/testify/require" |
|
|
|
|
"google.golang.org/grpc" |
|
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/apimachinery/identity" |
|
|
|
|
"github.com/grafana/grafana/pkg/apis/dashboard/v0alpha1" |
|
|
|
|
"github.com/grafana/grafana/pkg/apiserver/rest" |
|
|
|
|
@ -17,15 +21,11 @@ import ( |
|
|
|
|
"github.com/grafana/grafana/pkg/services/user" |
|
|
|
|
"github.com/grafana/grafana/pkg/setting" |
|
|
|
|
"github.com/grafana/grafana/pkg/storage/unified/resource" |
|
|
|
|
"github.com/stretchr/testify/assert" |
|
|
|
|
"github.com/stretchr/testify/require" |
|
|
|
|
"google.golang.org/grpc" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func TestSearchFallback(t *testing.T) { |
|
|
|
|
t.Run("should hit legacy search handler on mode 0", func(t *testing.T) { |
|
|
|
|
mockClient := &MockClient{} |
|
|
|
|
mockUnifiedCtxclient := func(context.Context) resource.ResourceClient { return mockClient } |
|
|
|
|
mockLegacyClient := &MockClient{} |
|
|
|
|
|
|
|
|
|
cfg := &setting.Cfg{ |
|
|
|
|
@ -33,8 +33,8 @@ func TestSearchFallback(t *testing.T) { |
|
|
|
|
"dashboards.dashboard.grafana.app": {DualWriterMode: rest.Mode0}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
searchHandler := NewSearchHandler(tracing.NewNoopTracerService(), cfg, mockLegacyClient, nil) |
|
|
|
|
searchHandler.client = resource.NewSearchClient(cfg, setting.UnifiedStorageConfigKeyDashboard, mockUnifiedCtxclient, mockLegacyClient) |
|
|
|
|
searchHandler := NewSearchHandler(tracing.NewNoopTracerService(), cfg, mockLegacyClient, mockClient, nil) |
|
|
|
|
searchHandler.client = resource.NewSearchClient(cfg, setting.UnifiedStorageConfigKeyDashboard, mockClient, mockLegacyClient) |
|
|
|
|
|
|
|
|
|
rr := httptest.NewRecorder() |
|
|
|
|
req := httptest.NewRequest("GET", "/search", nil) |
|
|
|
|
@ -53,7 +53,6 @@ func TestSearchFallback(t *testing.T) { |
|
|
|
|
|
|
|
|
|
t.Run("should hit legacy search handler on mode 1", func(t *testing.T) { |
|
|
|
|
mockClient := &MockClient{} |
|
|
|
|
mockUnifiedCtxclient := func(context.Context) resource.ResourceClient { return mockClient } |
|
|
|
|
mockLegacyClient := &MockClient{} |
|
|
|
|
|
|
|
|
|
cfg := &setting.Cfg{ |
|
|
|
|
@ -61,8 +60,8 @@ func TestSearchFallback(t *testing.T) { |
|
|
|
|
"dashboards.dashboard.grafana.app": {DualWriterMode: rest.Mode1}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
searchHandler := NewSearchHandler(tracing.NewNoopTracerService(), cfg, mockLegacyClient, nil) |
|
|
|
|
searchHandler.client = resource.NewSearchClient(cfg, setting.UnifiedStorageConfigKeyDashboard, mockUnifiedCtxclient, mockLegacyClient) |
|
|
|
|
searchHandler := NewSearchHandler(tracing.NewNoopTracerService(), cfg, mockLegacyClient, mockClient, nil) |
|
|
|
|
searchHandler.client = resource.NewSearchClient(cfg, setting.UnifiedStorageConfigKeyDashboard, mockClient, mockLegacyClient) |
|
|
|
|
|
|
|
|
|
rr := httptest.NewRecorder() |
|
|
|
|
req := httptest.NewRequest("GET", "/search", nil) |
|
|
|
|
@ -81,7 +80,6 @@ func TestSearchFallback(t *testing.T) { |
|
|
|
|
|
|
|
|
|
t.Run("should hit legacy search handler on mode 2", func(t *testing.T) { |
|
|
|
|
mockClient := &MockClient{} |
|
|
|
|
mockUnifiedCtxclient := func(context.Context) resource.ResourceClient { return mockClient } |
|
|
|
|
mockLegacyClient := &MockClient{} |
|
|
|
|
|
|
|
|
|
cfg := &setting.Cfg{ |
|
|
|
|
@ -89,8 +87,8 @@ func TestSearchFallback(t *testing.T) { |
|
|
|
|
"dashboards.dashboard.grafana.app": {DualWriterMode: rest.Mode2}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
searchHandler := NewSearchHandler(tracing.NewNoopTracerService(), cfg, mockLegacyClient, nil) |
|
|
|
|
searchHandler.client = resource.NewSearchClient(cfg, setting.UnifiedStorageConfigKeyDashboard, mockUnifiedCtxclient, mockLegacyClient) |
|
|
|
|
searchHandler := NewSearchHandler(tracing.NewNoopTracerService(), cfg, mockLegacyClient, mockClient, nil) |
|
|
|
|
searchHandler.client = resource.NewSearchClient(cfg, setting.UnifiedStorageConfigKeyDashboard, mockClient, mockLegacyClient) |
|
|
|
|
|
|
|
|
|
rr := httptest.NewRecorder() |
|
|
|
|
req := httptest.NewRequest("GET", "/search", nil) |
|
|
|
|
@ -109,7 +107,6 @@ func TestSearchFallback(t *testing.T) { |
|
|
|
|
|
|
|
|
|
t.Run("should hit unified storage search handler on mode 3", func(t *testing.T) { |
|
|
|
|
mockClient := &MockClient{} |
|
|
|
|
mockUnifiedCtxclient := func(context.Context) resource.ResourceClient { return mockClient } |
|
|
|
|
mockLegacyClient := &MockClient{} |
|
|
|
|
|
|
|
|
|
cfg := &setting.Cfg{ |
|
|
|
|
@ -117,8 +114,8 @@ func TestSearchFallback(t *testing.T) { |
|
|
|
|
"dashboards.dashboard.grafana.app": {DualWriterMode: rest.Mode3}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
searchHandler := NewSearchHandler(tracing.NewNoopTracerService(), cfg, mockLegacyClient, nil) |
|
|
|
|
searchHandler.client = resource.NewSearchClient(cfg, setting.UnifiedStorageConfigKeyDashboard, mockUnifiedCtxclient, mockLegacyClient) |
|
|
|
|
searchHandler := NewSearchHandler(tracing.NewNoopTracerService(), cfg, mockLegacyClient, mockClient, nil) |
|
|
|
|
searchHandler.client = resource.NewSearchClient(cfg, setting.UnifiedStorageConfigKeyDashboard, mockClient, mockLegacyClient) |
|
|
|
|
|
|
|
|
|
rr := httptest.NewRecorder() |
|
|
|
|
req := httptest.NewRequest("GET", "/search", nil) |
|
|
|
|
@ -137,7 +134,6 @@ func TestSearchFallback(t *testing.T) { |
|
|
|
|
|
|
|
|
|
t.Run("should hit unified storage search handler on mode 4", func(t *testing.T) { |
|
|
|
|
mockClient := &MockClient{} |
|
|
|
|
mockUnifiedCtxclient := func(context.Context) resource.ResourceClient { return mockClient } |
|
|
|
|
mockLegacyClient := &MockClient{} |
|
|
|
|
|
|
|
|
|
cfg := &setting.Cfg{ |
|
|
|
|
@ -145,8 +141,8 @@ func TestSearchFallback(t *testing.T) { |
|
|
|
|
"dashboards.dashboard.grafana.app": {DualWriterMode: rest.Mode4}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
searchHandler := NewSearchHandler(tracing.NewNoopTracerService(), cfg, mockLegacyClient, nil) |
|
|
|
|
searchHandler.client = resource.NewSearchClient(cfg, setting.UnifiedStorageConfigKeyDashboard, mockUnifiedCtxclient, mockLegacyClient) |
|
|
|
|
searchHandler := NewSearchHandler(tracing.NewNoopTracerService(), cfg, mockLegacyClient, mockClient, nil) |
|
|
|
|
searchHandler.client = resource.NewSearchClient(cfg, setting.UnifiedStorageConfigKeyDashboard, mockClient, mockLegacyClient) |
|
|
|
|
|
|
|
|
|
rr := httptest.NewRecorder() |
|
|
|
|
req := httptest.NewRequest("GET", "/search", nil) |
|
|
|
|
@ -165,7 +161,6 @@ func TestSearchFallback(t *testing.T) { |
|
|
|
|
|
|
|
|
|
t.Run("should hit unified storage search handler on mode 5", func(t *testing.T) { |
|
|
|
|
mockClient := &MockClient{} |
|
|
|
|
mockUnifiedCtxclient := func(context.Context) resource.ResourceClient { return mockClient } |
|
|
|
|
mockLegacyClient := &MockClient{} |
|
|
|
|
|
|
|
|
|
cfg := &setting.Cfg{ |
|
|
|
|
@ -173,8 +168,8 @@ func TestSearchFallback(t *testing.T) { |
|
|
|
|
"dashboards.dashboard.grafana.app": {DualWriterMode: rest.Mode5}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
searchHandler := NewSearchHandler(tracing.NewNoopTracerService(), cfg, mockLegacyClient, nil) |
|
|
|
|
searchHandler.client = resource.NewSearchClient(cfg, setting.UnifiedStorageConfigKeyDashboard, mockUnifiedCtxclient, mockLegacyClient) |
|
|
|
|
searchHandler := NewSearchHandler(tracing.NewNoopTracerService(), cfg, mockLegacyClient, mockClient, nil) |
|
|
|
|
searchHandler.client = resource.NewSearchClient(cfg, setting.UnifiedStorageConfigKeyDashboard, mockClient, mockLegacyClient) |
|
|
|
|
|
|
|
|
|
rr := httptest.NewRecorder() |
|
|
|
|
req := httptest.NewRequest("GET", "/search", nil) |
|
|
|
|
@ -201,7 +196,7 @@ func TestSearchHandler(t *testing.T) { |
|
|
|
|
// Initialize the search handler with the mock client
|
|
|
|
|
searchHandler := SearchHandler{ |
|
|
|
|
log: log.New("test", "test"), |
|
|
|
|
client: func(context.Context) resource.ResourceIndexClient { return mockClient }, |
|
|
|
|
client: mockClient, |
|
|
|
|
tracer: tracing.NewNoopTracerService(), |
|
|
|
|
features: features, |
|
|
|
|
} |
|
|
|
|
@ -230,7 +225,7 @@ func TestSearchHandler(t *testing.T) { |
|
|
|
|
// Initialize the search handler with the mock client
|
|
|
|
|
searchHandler := SearchHandler{ |
|
|
|
|
log: log.New("test", "test"), |
|
|
|
|
client: func(context.Context) resource.ResourceIndexClient { return mockClient }, |
|
|
|
|
client: mockClient, |
|
|
|
|
tracer: tracing.NewNoopTracerService(), |
|
|
|
|
features: features, |
|
|
|
|
} |
|
|
|
|
@ -259,7 +254,7 @@ func TestSearchHandler(t *testing.T) { |
|
|
|
|
// Initialize the search handler with the mock client
|
|
|
|
|
searchHandler := SearchHandler{ |
|
|
|
|
log: log.New("test", "test"), |
|
|
|
|
client: func(context.Context) resource.ResourceIndexClient { return mockClient }, |
|
|
|
|
client: mockClient, |
|
|
|
|
tracer: tracing.NewNoopTracerService(), |
|
|
|
|
features: features, |
|
|
|
|
} |
|
|
|
|
@ -311,7 +306,7 @@ func TestSearchHandler(t *testing.T) { |
|
|
|
|
// Initialize the search handler with the mock client
|
|
|
|
|
searchHandler := SearchHandler{ |
|
|
|
|
log: log.New("test", "test"), |
|
|
|
|
client: func(context.Context) resource.ResourceIndexClient { return mockClient }, |
|
|
|
|
client: mockClient, |
|
|
|
|
tracer: tracing.NewNoopTracerService(), |
|
|
|
|
features: features, |
|
|
|
|
} |
|
|
|
|
@ -350,7 +345,7 @@ func TestSearchHandlerSharedDashboards(t *testing.T) { |
|
|
|
|
features := featuremgmt.WithFeatures() |
|
|
|
|
searchHandler := SearchHandler{ |
|
|
|
|
log: log.New("test", "test"), |
|
|
|
|
client: func(context.Context) resource.ResourceIndexClient { return mockClient }, |
|
|
|
|
client: mockClient, |
|
|
|
|
tracer: tracing.NewNoopTracerService(), |
|
|
|
|
features: features, |
|
|
|
|
} |
|
|
|
|
@ -432,7 +427,7 @@ func TestSearchHandlerSharedDashboards(t *testing.T) { |
|
|
|
|
features := featuremgmt.WithFeatures(featuremgmt.FlagUnifiedStorageSearchPermissionFiltering) |
|
|
|
|
searchHandler := SearchHandler{ |
|
|
|
|
log: log.New("test", "test"), |
|
|
|
|
client: func(context.Context) resource.ResourceIndexClient { return mockClient }, |
|
|
|
|
client: mockClient, |
|
|
|
|
tracer: tracing.NewNoopTracerService(), |
|
|
|
|
features: features, |
|
|
|
|
} |
|
|
|
|
|