mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Remove folderid service test (#80433)
* Remove FolderID from service tests * Add models * Add folderID pack to publicdashboard tests * Remove folderID from dashboard tests * Remove folderID from folders * Remove folderID from ngalert tests * Remove nolint comment * Add back some tests after rebase
This commit is contained in:
@@ -44,8 +44,7 @@ func TestIntegrationDashboardFolderStore(t *testing.T) {
|
||||
t.Run("GetFolderByTitle should find the folder", func(t *testing.T) {
|
||||
result, err := folderStore.GetFolderByTitle(context.Background(), orgId, title)
|
||||
require.NoError(t, err)
|
||||
// nolint:staticcheck
|
||||
require.Equal(t, folder1.ID, result.ID)
|
||||
require.Equal(t, folder1.UID, result.UID)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -58,8 +57,7 @@ func TestIntegrationDashboardFolderStore(t *testing.T) {
|
||||
|
||||
t.Run("should return folder by UID", func(t *testing.T) {
|
||||
d, err := folderStore.GetFolderByUID(context.Background(), orgId, folder.UID)
|
||||
// nolint:staticcheck
|
||||
require.Equal(t, folder.ID, d.ID)
|
||||
require.Equal(t, folder.UID, d.UID)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
t.Run("should not find dashboard", func(t *testing.T) {
|
||||
@@ -83,8 +81,7 @@ func TestIntegrationDashboardFolderStore(t *testing.T) {
|
||||
|
||||
t.Run("should return folder by ID", func(t *testing.T) {
|
||||
d, err := folderStore.GetFolderByID(context.Background(), orgId, folder.ID)
|
||||
// nolint:staticcheck
|
||||
require.Equal(t, folder.ID, d.ID)
|
||||
require.Equal(t, folder.UID, d.UID)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
t.Run("should not find dashboard", func(t *testing.T) {
|
||||
|
||||
@@ -106,38 +106,22 @@ func TestIntegrationFolderService(t *testing.T) {
|
||||
origNewGuardian := guardian.New
|
||||
guardian.MockDashboardGuardian(&guardian.FakeDashboardGuardian{})
|
||||
|
||||
folderId := rand.Int63()
|
||||
folderUID := util.GenerateShortUID()
|
||||
|
||||
f := folder.NewFolder("Folder", "")
|
||||
// nolint:staticcheck
|
||||
f.ID = folderId
|
||||
f.UID = folderUID
|
||||
|
||||
folderStore.On("GetFolderByID", mock.Anything, orgID, folderId).Return(f, nil)
|
||||
folderStore.On("GetFolderByUID", mock.Anything, orgID, folderUID).Return(f, nil)
|
||||
|
||||
t.Run("When get folder by id should return access denied error", func(t *testing.T) {
|
||||
_, err := service.Get(context.Background(), &folder.GetFolderQuery{
|
||||
ID: &folderId, // nolint:staticcheck
|
||||
UID: &folderUID,
|
||||
OrgID: orgID,
|
||||
SignedInUser: usr,
|
||||
})
|
||||
require.Equal(t, err, dashboards.ErrFolderAccessDenied)
|
||||
})
|
||||
|
||||
var zeroInt int64 = 0
|
||||
t.Run("When get folder by id, with id = 0 should return default folder", func(t *testing.T) {
|
||||
foldr, err := service.Get(context.Background(), &folder.GetFolderQuery{
|
||||
ID: &zeroInt, // nolint:staticcheck
|
||||
OrgID: orgID,
|
||||
SignedInUser: usr,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
// nolint:staticcheck
|
||||
require.Equal(t, foldr, &folder.Folder{ID: 0, Title: "General"})
|
||||
})
|
||||
|
||||
t.Run("When get folder by uid should return access denied error", func(t *testing.T) {
|
||||
_, err := service.Get(context.Background(), &folder.GetFolderQuery{
|
||||
UID: &folderUID,
|
||||
@@ -176,7 +160,6 @@ func TestIntegrationFolderService(t *testing.T) {
|
||||
newFolder := folder.NewFolder("Folder", "")
|
||||
newFolder.UID = folderUID
|
||||
|
||||
folderStore.On("GetFolderByID", mock.Anything, orgID, folderId).Return(newFolder, nil)
|
||||
folderStore.On("GetFolderByUID", mock.Anything, orgID, folderUID).Return(newFolder, nil)
|
||||
|
||||
err := service.Delete(context.Background(), &folder.DeleteFolderCommand{
|
||||
@@ -267,8 +250,6 @@ func TestIntegrationFolderService(t *testing.T) {
|
||||
|
||||
t.Run("When deleting folder by uid should not return access denied error", func(t *testing.T) {
|
||||
f := folder.NewFolder(util.GenerateShortUID(), "")
|
||||
// nolint:staticcheck
|
||||
f.ID = rand.Int63()
|
||||
f.UID = util.GenerateShortUID()
|
||||
folderStore.On("GetFolders", mock.Anything, orgID, []string{f.UID}).Return(map[string]*folder.Folder{f.UID: f}, nil)
|
||||
folderStore.On("GetFolderByUID", mock.Anything, orgID, f.UID).Return(f, nil)
|
||||
@@ -287,8 +268,6 @@ func TestIntegrationFolderService(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, actualCmd)
|
||||
// nolint:staticcheck
|
||||
require.Equal(t, f.ID, actualCmd.ID)
|
||||
require.Equal(t, orgID, actualCmd.OrgID)
|
||||
require.Equal(t, expectedForceDeleteRules, actualCmd.ForceDeleteFolderRules)
|
||||
})
|
||||
@@ -302,20 +281,6 @@ func TestIntegrationFolderService(t *testing.T) {
|
||||
origNewGuardian := guardian.New
|
||||
guardian.MockDashboardGuardian(&guardian.FakeDashboardGuardian{CanViewValue: true})
|
||||
|
||||
t.Run("When get folder by id should return folder", func(t *testing.T) {
|
||||
expected := folder.NewFolder(util.GenerateShortUID(), "")
|
||||
// nolint:staticcheck
|
||||
expected.ID = rand.Int63()
|
||||
|
||||
// nolint:staticcheck
|
||||
folderStore.On("GetFolderByID", mock.Anything, orgID, expected.ID).Return(expected, nil)
|
||||
|
||||
// nolint:staticcheck
|
||||
actual, err := service.getFolderByID(context.Background(), expected.ID, orgID)
|
||||
require.Equal(t, expected, actual)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("When get folder by uid should return folder", func(t *testing.T) {
|
||||
expected := folder.NewFolder(util.GenerateShortUID(), "")
|
||||
expected.UID = util.GenerateShortUID()
|
||||
@@ -1384,8 +1349,6 @@ func CreateSubtreeInStore(t *testing.T, store *sqlStore, service *Service, depth
|
||||
f, err := service.Create(context.Background(), &cmd)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, title, f.Title)
|
||||
// nolint:staticcheck
|
||||
require.NotEmpty(t, f.ID)
|
||||
require.NotEmpty(t, f.UID)
|
||||
|
||||
parents, err := store.GetParents(context.Background(), folder.GetParentsQuery{
|
||||
|
||||
@@ -70,8 +70,7 @@ func TestIntegrationCreate(t *testing.T) {
|
||||
|
||||
assert.Equal(t, folderTitle, f.Title)
|
||||
assert.Equal(t, folderDsc, f.Description)
|
||||
// nolint:staticcheck
|
||||
assert.NotEmpty(t, f.ID)
|
||||
assert.NotEmpty(t, f.UID)
|
||||
assert.Equal(t, uid, f.UID)
|
||||
assert.Empty(t, f.ParentUID)
|
||||
assert.NotEmpty(t, f.URL)
|
||||
@@ -98,8 +97,7 @@ func TestIntegrationCreate(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "parent", parent.Title)
|
||||
// nolint:staticcheck
|
||||
require.NotEmpty(t, parent.ID)
|
||||
require.NotEmpty(t, parent.UID)
|
||||
assert.Equal(t, parentUID, parent.UID)
|
||||
assert.NotEmpty(t, parent.URL)
|
||||
|
||||
@@ -125,8 +123,7 @@ func TestIntegrationCreate(t *testing.T) {
|
||||
|
||||
assert.Equal(t, folderTitle, f.Title)
|
||||
assert.Equal(t, folderDsc, f.Description)
|
||||
// nolint:staticcheck
|
||||
assert.NotEmpty(t, f.ID)
|
||||
assert.NotEmpty(t, f.UID)
|
||||
assert.Equal(t, uid, f.UID)
|
||||
assert.Equal(t, parentUID, f.ParentUID)
|
||||
assert.NotEmpty(t, f.URL)
|
||||
@@ -404,8 +401,6 @@ func TestIntegrationGet(t *testing.T) {
|
||||
OrgID: orgID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
// nolint:staticcheck
|
||||
assert.Equal(t, f.ID, ff.ID)
|
||||
assert.Equal(t, f.UID, ff.UID)
|
||||
assert.Equal(t, f.OrgID, ff.OrgID)
|
||||
assert.Equal(t, f.Title, ff.Title)
|
||||
@@ -422,8 +417,6 @@ func TestIntegrationGet(t *testing.T) {
|
||||
OrgID: orgID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
// nolint:staticcheck
|
||||
assert.Equal(t, f.ID, ff.ID)
|
||||
assert.Equal(t, f.UID, ff.UID)
|
||||
assert.Equal(t, f.OrgID, ff.OrgID)
|
||||
assert.Equal(t, f.Title, ff.Title)
|
||||
@@ -436,11 +429,10 @@ func TestIntegrationGet(t *testing.T) {
|
||||
|
||||
t.Run("get folder by title should succeed", func(t *testing.T) {
|
||||
ff, err := folderStore.Get(context.Background(), folder.GetFolderQuery{
|
||||
ID: &f.ID, // nolint:staticcheck
|
||||
UID: &f.UID,
|
||||
OrgID: orgID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
// nolint:staticcheck
|
||||
assert.Equal(t, f.ID, ff.ID)
|
||||
assert.Equal(t, f.UID, ff.UID)
|
||||
assert.Equal(t, f.OrgID, ff.OrgID)
|
||||
assert.Equal(t, f.Title, ff.Title)
|
||||
@@ -777,8 +769,7 @@ func TestIntegrationGetFolders(t *testing.T) {
|
||||
})
|
||||
assert.NotEqual(t, -1, folderInResponseIdx)
|
||||
rf := ff[folderInResponseIdx]
|
||||
// nolint:staticcheck
|
||||
assert.Equal(t, f.ID, rf.ID)
|
||||
assert.Equal(t, f.UID, rf.UID)
|
||||
assert.Equal(t, f.OrgID, rf.OrgID)
|
||||
assert.Equal(t, f.Title, rf.Title)
|
||||
assert.Equal(t, f.Description, rf.Description)
|
||||
@@ -822,8 +813,6 @@ func CreateSubtree(t *testing.T, store *sqlStore, orgID int64, parentUID string,
|
||||
f, err := store.Create(context.Background(), cmd)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, title, f.Title)
|
||||
// nolint:staticcheck
|
||||
require.NotEmpty(t, f.ID)
|
||||
require.NotEmpty(t, f.UID)
|
||||
|
||||
parents, err := store.GetParents(context.Background(), folder.GetParentsQuery{
|
||||
|
||||
Reference in New Issue
Block a user