K8s: Add dashboard service (requires dev mode) (#78565)
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
package dashboards
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -91,54 +88,3 @@ func TestSlugifyTitle(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceConversion(t *testing.T) {
|
||||
body := simplejson.New()
|
||||
body.Set("title", "test dash")
|
||||
body.Set("tags", []string{"hello", "world"})
|
||||
|
||||
dash := NewDashboardFromJson(body)
|
||||
dash.SetUID("TheUID")
|
||||
dash.SetVersion(10)
|
||||
dash.Created = time.UnixMilli(946713600000).UTC() // 2000-01-01
|
||||
dash.Updated = time.UnixMilli(1262332800000).UTC() // 2010-01-01
|
||||
dash.CreatedBy = 10
|
||||
dash.UpdatedBy = 11
|
||||
dash.PluginID = "plugin-xyz"
|
||||
// nolint:staticcheck
|
||||
dash.FolderID = 1234
|
||||
dash.SetID(12345) // should be removed in resource version
|
||||
|
||||
dst := dash.ToResource()
|
||||
require.Equal(t, int64(12345), dash.ID)
|
||||
require.Equal(t, int64(12345), dash.Data.Get("id").MustInt64(0))
|
||||
|
||||
out, err := json.MarshalIndent(dst, "", " ")
|
||||
require.NoError(t, err)
|
||||
fmt.Printf("%s", string(out))
|
||||
require.JSONEq(t, `{
|
||||
"apiVersion": "v0-0-alpha",
|
||||
"kind": "Dashboard",
|
||||
"metadata": {
|
||||
"name": "TheUID",
|
||||
"resourceVersion": "10",
|
||||
"creationTimestamp": "2000-01-01T08:00:00Z",
|
||||
"annotations": {
|
||||
"grafana.app/createdBy": "user:10",
|
||||
"grafana.app/folder": "folder:1234",
|
||||
"grafana.app/originKey": "plugin-xyz",
|
||||
"grafana.app/originName": "plugin",
|
||||
"grafana.app/slug": "test-dash",
|
||||
"grafana.app/updatedBy": "user:11",
|
||||
"grafana.app/updatedTimestamp": "2010-01-01T08:00:00Z"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"tags": [
|
||||
"hello",
|
||||
"world"
|
||||
],
|
||||
"title": "test dash"
|
||||
}
|
||||
}`, string(out))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user