Chore: Deprecate ID from Folder (#78281)

* Chore: Deprecate ID from Folder

* chore: add more linter comments

* chore: add missing lint comment
This commit is contained in:
Kat Yang
2023-11-20 15:44:51 -05:00
committed by GitHub
parent ae164df698
commit 2f2ce3edbb
34 changed files with 128 additions and 20 deletions

View File

@@ -26,6 +26,7 @@ func TestNewFolderNameScopeResolver(t *testing.T) {
t.Run("resolver should convert to uid scope", func(t *testing.T) {
orgId := rand.Int63()
title := "Very complex :title with: and /" + util.GenerateShortUID()
// nolint:staticcheck
db := &folder.Folder{Title: title, ID: rand.Int63(), UID: util.GenerateShortUID()}
folderStore := foldertest.NewFakeFolderStore(t)
folderStore.On("GetFolderByTitle", mock.Anything, mock.Anything, mock.Anything).Return(db, nil).Once()
@@ -43,6 +44,7 @@ func TestNewFolderNameScopeResolver(t *testing.T) {
orgId := rand.Int63()
title := "Very complex :title with: and /" + util.GenerateShortUID()
// nolint:staticcheck
db := &folder.Folder{Title: title, ID: rand.Int63(), UID: util.GenerateShortUID()}
folderStore := foldertest.NewFakeFolderStore(t)
@@ -114,15 +116,18 @@ func TestNewFolderIDScopeResolver(t *testing.T) {
orgId := rand.Int63()
uid := util.GenerateShortUID()
// nolint:staticcheck
db := &folder.Folder{ID: rand.Int63(), UID: uid}
folderStore.On("GetFolderByID", mock.Anything, mock.Anything, mock.Anything).Return(db, nil).Once()
// nolint:staticcheck
scope := "folders:id:" + strconv.FormatInt(db.ID, 10)
resolvedScopes, err := resolver.Resolve(context.Background(), orgId, scope)
require.NoError(t, err)
require.Len(t, resolvedScopes, 1)
require.Equal(t, fmt.Sprintf("folders:uid:%v", db.UID), resolvedScopes[0])
// nolint:staticcheck
folderStore.AssertCalled(t, "GetFolderByID", mock.Anything, orgId, db.ID)
})
t.Run("resolver should should include inherited scopes if any", func(t *testing.T) {
@@ -140,9 +145,11 @@ func TestNewFolderIDScopeResolver(t *testing.T) {
orgId := rand.Int63()
uid := util.GenerateShortUID()
// nolint:staticcheck
db := &folder.Folder{ID: rand.Int63(), UID: uid}
folderStore.On("GetFolderByID", mock.Anything, mock.Anything, mock.Anything).Return(db, nil).Once()
// nolint:staticcheck
scope := "folders:id:" + strconv.FormatInt(db.ID, 10)
resolvedScopes, err := resolver.Resolve(context.Background(), orgId, scope)
@@ -157,6 +164,7 @@ func TestNewFolderIDScopeResolver(t *testing.T) {
t.Errorf("Result mismatch (-want +got):\n%s", diff)
}
// nolint:staticcheck
folderStore.AssertCalled(t, "GetFolderByID", mock.Anything, orgId, db.ID)
})
t.Run("resolver should fail if input scope is not expected", func(t *testing.T) {
@@ -211,10 +219,12 @@ func TestNewDashboardIDScopeResolver(t *testing.T) {
_, resolver := NewDashboardIDScopeResolver(folderStore, dashSvc, foldertest.NewFakeService())
orgID := rand.Int63()
// nolint:staticcheck
folder := &folder.Folder{ID: 2, UID: "2"}
// nolint:staticcheck
dashboard := &Dashboard{ID: 1, FolderID: folder.ID, UID: "1"}
dashSvc.On("G")
// nolint:staticcheck
folderStore.On("GetFolderByID", mock.Anything, orgID, folder.ID).Return(folder, nil).Once()
dashSvc.On("GetDashboard", mock.Anything, mock.Anything).Return(dashboard, nil).Once()
scope := ac.Scope("dashboards", "id", strconv.FormatInt(dashboard.ID, 10))
@@ -240,11 +250,13 @@ func TestNewDashboardIDScopeResolver(t *testing.T) {
_, resolver := NewDashboardIDScopeResolver(folderStore, dashSvc, folderSvc)
orgID := rand.Int63()
// nolint:staticcheck
folder := &folder.Folder{ID: 2, UID: "2"}
// nolint:staticcheck
dashboard := &Dashboard{ID: 1, FolderID: folder.ID, UID: "1"}
dashSvc.On("GetDashboard", mock.Anything, mock.Anything).Return(dashboard, nil).Once()
// nolint:staticcheck
folderStore.On("GetFolderByID", mock.Anything, orgID, folder.ID).Return(folder, nil).Once()
scope := ac.Scope("dashboards", "id", strconv.FormatInt(dashboard.ID, 10))
@@ -296,11 +308,13 @@ func TestNewDashboardUIDScopeResolver(t *testing.T) {
_, resolver := NewDashboardUIDScopeResolver(folderStore, dashSvc, foldertest.NewFakeService())
orgID := rand.Int63()
// nolint:staticcheck
folder := &folder.Folder{ID: 2, UID: "2"}
// nolint:staticcheck
dashboard := &Dashboard{ID: 1, FolderID: folder.ID, UID: "1"}
dashSvc.On("GetDashboard", mock.Anything, mock.Anything).Return(dashboard, nil).Once()
// nolint:staticcheck
folderStore.On("GetFolderByID", mock.Anything, orgID, folder.ID).Return(folder, nil).Once()
scope := ac.Scope("dashboards", "uid", dashboard.UID)
resolvedScopes, err := resolver.Resolve(context.Background(), orgID, scope)
@@ -325,6 +339,7 @@ func TestNewDashboardUIDScopeResolver(t *testing.T) {
_, resolver := NewDashboardUIDScopeResolver(folderStore, dashSvc, folderSvc)
orgID := rand.Int63()
// nolint:staticcheck
folder := &folder.Folder{ID: 2, UID: "2"}
// nolint:staticcheck
dashboard := &Dashboard{ID: 1, FolderID: folder.ID, UID: "1"}

View File

@@ -759,6 +759,7 @@ func TestIntegrationFindDashboardsByTitle(t *testing.T) {
SignedInUser: user,
})
require.NoError(t, err)
// nolint:staticcheck
insertTestDashboard(t, dashboardStore, "dashboard under f0", orgID, f0.ID, f0.UID, false)
subfolder, err := folderServiceWithFlagOn.Create(context.Background(), &folder.CreateFolderCommand{
@@ -768,6 +769,7 @@ func TestIntegrationFindDashboardsByTitle(t *testing.T) {
SignedInUser: user,
})
require.NoError(t, err)
// nolint:staticcheck
insertTestDashboard(t, dashboardStore, "dashboard under subfolder", orgID, subfolder.ID, subfolder.UID, false)
type res struct {
@@ -874,6 +876,7 @@ func TestIntegrationFindDashboardsByFolder(t *testing.T) {
SignedInUser: user,
})
require.NoError(t, err)
// nolint:staticcheck
insertTestDashboard(t, dashboardStore, "dashboard under f0", orgID, f0.ID, f0.UID, false)
f1, err := folderServiceWithFlagOn.Create(context.Background(), &folder.CreateFolderCommand{
@@ -882,6 +885,7 @@ func TestIntegrationFindDashboardsByFolder(t *testing.T) {
SignedInUser: user,
})
require.NoError(t, err)
// nolint:staticcheck
insertTestDashboard(t, dashboardStore, "dashboard under f1", orgID, f1.ID, f1.UID, false)
subfolder, err := folderServiceWithFlagOn.Create(context.Background(), &folder.CreateFolderCommand{

View File

@@ -387,7 +387,7 @@ type CountDashboardsInFolderRequest struct {
func FromDashboard(dash *Dashboard) *folder.Folder {
return &folder.Folder{
ID: dash.ID,
ID: dash.ID, // nolint:staticcheck
UID: dash.UID,
OrgID: dash.OrgID,
Title: dash.Title,

View File

@@ -234,6 +234,7 @@ func TestDashboardService(t *testing.T) {
t.Run("Count dashboards in folder", func(t *testing.T) {
fakeStore.On("CountDashboardsInFolder", mock.Anything, mock.AnythingOfType("*dashboards.CountDashboardsInFolderRequest")).Return(int64(3), nil)
// nolint:staticcheck
folderSvc.ExpectedFolder = &folder.Folder{ID: 1}
// set up a ctx with signed in user
usr := &user.SignedInUser{UserID: 1}