Kinds: Use apimachinery ObjectMeta for metadata (#68668)

This commit is contained in:
Ryan McKinley
2023-05-24 09:13:44 -07:00
committed by GitHub
parent f91c1b9897
commit c66d5721f7
22 changed files with 695 additions and 11 deletions

View File

@@ -81,3 +81,10 @@ type GetPlaylistItemsByUidQuery struct {
PlaylistUID string
OrgId int64
}
func PlaylistToResource(p PlaylistDTO) playlist.K8sResource {
copy := p
r := playlist.NewK8sResource(p.Uid, &copy)
copy.Uid = "" // remove it from the payload
return r
}

View File

@@ -0,0 +1,64 @@
package playlist
import (
"encoding/json"
"fmt"
"testing"
"github.com/grafana/grafana/pkg/kinds/playlist"
"github.com/grafana/grafana/pkg/util"
"github.com/stretchr/testify/require"
)
func TestPlaylistConversion(t *testing.T) {
src := PlaylistDTO{
Uid: "abc",
Name: "TeamA",
Interval: "10s",
Items: []playlist.Item{
{Title: util.Pointer("First"), Type: playlist.ItemTypeDashboardByUid, Value: "UID0"},
{Title: util.Pointer("Second"), Type: playlist.ItemTypeDashboardByTag, Value: "tagA"},
{Title: util.Pointer("Third"), Type: playlist.ItemTypeDashboardById, Value: "123"},
},
}
dst := PlaylistToResource(src)
require.Equal(t, "abc", src.Uid)
require.Equal(t, "abc", dst.Metadata.Name)
require.Equal(t, src.Name, dst.Spec.Name)
out, err := json.MarshalIndent(dst, "", " ")
require.NoError(t, err)
fmt.Printf("%s", string(out))
require.JSONEq(t, `{
"apiVersion": "v0.0-alpha",
"kind": "Playlist",
"metadata": {
"name": "abc",
"creationTimestamp": null
},
"spec": {
"interval": "10s",
"items": [
{
"title": "First",
"type": "dashboard_by_uid",
"value": "UID0"
},
{
"title": "Second",
"type": "dashboard_by_tag",
"value": "tagA"
},
{
"title": "Third",
"type": "dashboard_by_id",
"value": "123"
}
],
"name": "TeamA",
"uid": ""
}
}`, string(out))
}