UnifiedSearch: Introduce a DocumentBuilder interface (#96738)
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package resource
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestStandardDocumentBuilder(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
builder := StandardDocumentBuilder().Builder
|
||||
|
||||
body, err := os.ReadFile("testdata/playlist-resource.json")
|
||||
require.NoError(t, err)
|
||||
doc, err := builder.BuildDocument(ctx, &ResourceKey{
|
||||
Namespace: "default",
|
||||
Group: "playlists.grafana.app",
|
||||
Resource: "playlists",
|
||||
Name: "test1",
|
||||
}, 10, body)
|
||||
require.NoError(t, err)
|
||||
|
||||
jj, _ := json.MarshalIndent(doc, "", " ")
|
||||
fmt.Printf("%s\n", string(jj))
|
||||
require.JSONEq(t, `{
|
||||
"key": {
|
||||
"namespace": "default",
|
||||
"group": "playlists.grafana.app",
|
||||
"resource": "playlists",
|
||||
"name": "test1"
|
||||
},
|
||||
"rv": 10,
|
||||
"title": "test1",
|
||||
"created": 1717236672000,
|
||||
"createdBy": "user:ABC",
|
||||
"updatedBy": "user:XYZ",
|
||||
"repository": {
|
||||
"name": "SQL",
|
||||
"path": "15",
|
||||
"hash": "xyz"
|
||||
}
|
||||
}`, string(jj))
|
||||
}
|
||||
Reference in New Issue
Block a user