Stars: Move stars from preferences apiserver to a new collections apiserver (#114006)
This commit is contained in:
+15
-38
@@ -1,4 +1,4 @@
|
||||
package preferences
|
||||
package collections
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -11,17 +11,21 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
|
||||
collections "github.com/grafana/grafana/apps/collections/pkg/apis/collections/v1alpha1"
|
||||
dashboardV1 "github.com/grafana/grafana/apps/dashboard/pkg/apis/dashboard/v1beta1"
|
||||
preferences "github.com/grafana/grafana/apps/preferences/pkg/apis/preferences/v1alpha1"
|
||||
grafanarest "github.com/grafana/grafana/pkg/apiserver/rest"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/queryhistory"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"github.com/grafana/grafana/pkg/tests/apis"
|
||||
"github.com/grafana/grafana/pkg/tests/testinfra"
|
||||
"github.com/grafana/grafana/pkg/tests/testsuite"
|
||||
"github.com/grafana/grafana/pkg/util/testutil"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
testsuite.Run(m)
|
||||
}
|
||||
|
||||
func TestIntegrationStars(t *testing.T) {
|
||||
testutil.SkipIntegrationTestInShortMode(t)
|
||||
|
||||
@@ -47,10 +51,10 @@ func TestIntegrationStars(t *testing.T) {
|
||||
"folders.folder.grafana.app": {
|
||||
DualWriterMode: mode,
|
||||
},
|
||||
"stars.preferences.grafana.app": {
|
||||
"stars.collections.grafana.app": {
|
||||
DualWriterMode: mode,
|
||||
},
|
||||
"preferences.preferences.grafana.app": {
|
||||
"collections.collections.grafana.app": {
|
||||
DualWriterMode: mode,
|
||||
},
|
||||
},
|
||||
@@ -60,28 +64,17 @@ func TestIntegrationStars(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
starsClient := helper.GetResourceClient(apis.ResourceClientArgs{
|
||||
User: helper.Org1.Admin,
|
||||
GVR: preferences.StarsResourceInfo.GroupVersionResource(),
|
||||
GVR: collections.StarsResourceInfo.GroupVersionResource(),
|
||||
})
|
||||
starsClientViewer := helper.GetResourceClient(apis.ResourceClientArgs{
|
||||
User: helper.Org1.Viewer,
|
||||
GVR: preferences.StarsResourceInfo.GroupVersionResource(),
|
||||
GVR: collections.StarsResourceInfo.GroupVersionResource(),
|
||||
})
|
||||
dashboardClient := helper.GetResourceClient(apis.ResourceClientArgs{
|
||||
User: helper.Org1.Admin,
|
||||
GVR: dashboardV1.DashboardResourceInfo.GroupVersionResource(),
|
||||
})
|
||||
|
||||
history := &queryhistory.QueryHistoryResponse{}
|
||||
legacyHistoryResponse := apis.DoRequest(helper, apis.RequestParams{
|
||||
User: starsClient.Args.User,
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/query-history",
|
||||
Body: []byte(`{"dataSourceUid":"eez1ebbdn3pq8b","queries":[{"scenarioId":"random_walk","seriesCount":1,"refId":"A","datasource":{"type":"grafana-testdata-datasource","uid":"eez1ebbdn3pq8b","apiVersion":"v0alpha1"}}]}`),
|
||||
}, &history)
|
||||
require.Equal(t, http.StatusOK, legacyHistoryResponse.Response.StatusCode, "add query history")
|
||||
queryHistoryStarUID := history.Result.UID
|
||||
require.NotEmpty(t, queryHistoryStarUID, "expect a query history UID")
|
||||
|
||||
// Create 5 dashboards
|
||||
for i := range 5 {
|
||||
_, err := dashboardClient.Resource.Create(context.Background(), &unstructured.Unstructured{
|
||||
@@ -126,7 +119,7 @@ func TestIntegrationStars(t *testing.T) {
|
||||
// List values and compare results
|
||||
rsp, err = starsClient.Resource.List(ctx, metav1.ListOptions{})
|
||||
require.NoError(t, err)
|
||||
stars := typed(t, rsp, &preferences.StarsList{})
|
||||
stars := typed(t, rsp, &collections.StarsList{})
|
||||
|
||||
require.Len(t, stars.Items, 1, "user stars should exist")
|
||||
require.Equal(t, "user-"+starsClient.Args.User.Identity.GetIdentifier(),
|
||||
@@ -148,7 +141,7 @@ func TestIntegrationStars(t *testing.T) {
|
||||
rspObj, err := starsClient.Resource.Get(ctx, "user-"+starsClient.Args.User.Identity.GetIdentifier(), metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
after := typed(t, rspObj, &preferences.Stars{})
|
||||
after := typed(t, rspObj, &collections.Stars{})
|
||||
resources = after.Spec.Resource
|
||||
require.Len(t, resources, 1)
|
||||
require.Equal(t, "dashboard.grafana.app", resources[0].Group)
|
||||
@@ -175,7 +168,7 @@ func TestIntegrationStars(t *testing.T) {
|
||||
}, metav1.UpdateOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
after = typed(t, rspObj, &preferences.Stars{})
|
||||
after = typed(t, rspObj, &collections.Stars{})
|
||||
resources = after.Spec.Resource
|
||||
require.Len(t, resources, 1)
|
||||
require.Equal(t, "dashboard.grafana.app", resources[0].Group)
|
||||
@@ -184,19 +177,10 @@ func TestIntegrationStars(t *testing.T) {
|
||||
[]string{"aaa", "bbb", "test-2"}, // NOTE 2 stays, 3 removed, added aaa+bbb (and sorted!)
|
||||
resources[0].Names)
|
||||
|
||||
// Query history stars
|
||||
legacyHistoryResponse = apis.DoRequest(helper, apis.RequestParams{
|
||||
User: starsClient.Args.User,
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/query-history/star/" + queryHistoryStarUID,
|
||||
}, &history)
|
||||
require.Equal(t, http.StatusOK, legacyHistoryResponse.Response.StatusCode, "add query history")
|
||||
require.True(t, history.Result.Starred, "expect the value to be starred")
|
||||
|
||||
rspObj, err = starsClient.Resource.Get(ctx, "user-"+starsClient.Args.User.Identity.GetIdentifier(), metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
after = typed(t, rspObj, &preferences.Stars{})
|
||||
after = typed(t, rspObj, &collections.Stars{})
|
||||
jj, err := json.MarshalIndent(after.Spec, "", " ")
|
||||
require.NoError(t, err)
|
||||
require.JSONEq(t, `{
|
||||
@@ -209,13 +193,6 @@ func TestIntegrationStars(t *testing.T) {
|
||||
"bbb",
|
||||
"test-2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"group": "history.grafana.app",
|
||||
"kind": "Query",
|
||||
"names": [
|
||||
"`+queryHistoryStarUID+`"
|
||||
]
|
||||
}
|
||||
]
|
||||
}`, string(jj))
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -97,6 +97,9 @@ func TestIntegrationOpenAPIs(t *testing.T) {
|
||||
}, {
|
||||
Group: "preferences.grafana.app",
|
||||
Version: "v1alpha1",
|
||||
}, {
|
||||
Group: "collections.grafana.app",
|
||||
Version: "v1alpha1",
|
||||
}, {
|
||||
Group: "notifications.alerting.grafana.app",
|
||||
Version: "v0alpha1",
|
||||
|
||||
Reference in New Issue
Block a user