mirror of
https://github.com/grafana/grafana.git
synced 2025-01-16 11:42:35 -06:00
SQLstore: Fix fetching an inexistent playlist response (#51962)
* SQLstore: Fix fetching and deleting an inexistent playlist xorm's session.Get() does not return an error if the raw does not exist. It returns a boolean instead. The playlist `sqlstore.GetPlaylist()` used to check only the error and in case of inexistent UID didn't return an error.
This commit is contained in:
parent
169a1c5b0f
commit
4ff0f006dd
@ -103,7 +103,10 @@ func (ss *SQLStore) GetPlaylist(ctx context.Context, query *models.GetPlaylistBy
|
||||
|
||||
return ss.WithDbSession(ctx, func(sess *DBSession) error {
|
||||
playlist := models.Playlist{UID: query.UID, OrgId: query.OrgId}
|
||||
_, err := sess.Get(&playlist)
|
||||
exists, err := sess.Get(&playlist)
|
||||
if !exists {
|
||||
return models.ErrPlaylistNotFound
|
||||
}
|
||||
query.Result = &playlist
|
||||
|
||||
return err
|
||||
|
@ -25,6 +25,15 @@ func TestIntegrationPlaylistDataAccess(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
uid := cmd.Result.UID
|
||||
|
||||
t.Run("Can get playlist", func(t *testing.T) {
|
||||
get := &models.GetPlaylistByUidQuery{UID: uid, OrgId: 1}
|
||||
err = ss.GetPlaylist(context.Background(), get)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, get.Result)
|
||||
require.Equal(t, get.Result.Name, "NYC office")
|
||||
require.Equal(t, get.Result.Interval, "10m")
|
||||
})
|
||||
|
||||
t.Run("Can get playlist items", func(t *testing.T) {
|
||||
get := &models.GetPlaylistItemsByUidQuery{PlaylistUID: uid, OrgId: 1}
|
||||
err = ss.GetPlaylistItem(context.Background(), get)
|
||||
@ -49,11 +58,18 @@ func TestIntegrationPlaylistDataAccess(t *testing.T) {
|
||||
|
||||
getQuery := models.GetPlaylistByUidQuery{UID: uid, OrgId: 1}
|
||||
err = ss.GetPlaylist(context.Background(), &getQuery)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, uid, getQuery.Result.UID, "playlist should've been removed")
|
||||
require.Error(t, err)
|
||||
require.ErrorIs(t, err, models.ErrPlaylistNotFound)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("Get playlist that doesn't exist", func(t *testing.T) {
|
||||
get := &models.GetPlaylistByUidQuery{UID: "unknown", OrgId: 1}
|
||||
err := ss.GetPlaylist(context.Background(), get)
|
||||
require.Error(t, err)
|
||||
require.ErrorIs(t, err, models.ErrPlaylistNotFound)
|
||||
})
|
||||
|
||||
t.Run("Delete playlist that doesn't exist", func(t *testing.T) {
|
||||
deleteQuery := models.DeletePlaylistCommand{UID: "654312", OrgId: 1}
|
||||
err := ss.DeletePlaylist(context.Background(), &deleteQuery)
|
||||
|
Loading…
Reference in New Issue
Block a user