UnifiedSearch: Introduce a ResourceIndex interface and bleve implementation (#96826)

Co-authored-by: Scott Lepper <scott.lepper@gmail.com>
This commit is contained in:
Ryan McKinley
2024-11-22 16:44:06 +03:00
committed by GitHub
co-authored by Scott Lepper
parent bbae396db4
commit c6848d4b68
20 changed files with 2533 additions and 425 deletions
@@ -1,44 +1,15 @@
package resource
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// AssertTableSnapshot will match a ResourceTable vs the saved value
func AssertTableSnapshot(t *testing.T, path string, table *ResourceTable) {
t.Helper()
k8sTable, err := table.ToK8s()
require.NoError(t, err, "unable to create table response", path)
actual, err := json.MarshalIndent(k8sTable, "", " ")
require.NoError(t, err, "unable to write table json", path)
// Safe to disable, this is a test.
// nolint:gosec
expected, err := os.ReadFile(path)
if err != nil || len(expected) < 1 {
assert.Fail(t, "missing file")
} else if assert.JSONEq(t, string(expected), string(actual)) {
return // everything is OK
}
// Write the snapshot
// Safe to disable, this is a test.
// nolint:gosec
err = os.WriteFile(path, actual, 0600)
require.NoError(t, err)
fmt.Printf("Updated table snapshot: %s\n", path)
}
func TestTableFormat(t *testing.T) {
columns := []*ResourceTableColumnDefinition{
{