EntityStore: support filtering by labels (#59905)
* label filtering * filtering in sql * filtering in sql group by * label is unique - no need for distinct * capitalize * fix capitalization
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package entity_server_tests
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
@@ -15,6 +16,13 @@ import (
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed testdata/dashboard-with-tags-b-g.json
|
||||
dashboardWithTagsBlueGreen string
|
||||
//go:embed testdata/dashboard-with-tags-r-g.json
|
||||
dashboardWithTagsRedGreen string
|
||||
)
|
||||
|
||||
type rawEntityMatcher struct {
|
||||
grn *entity.GRN
|
||||
createdRange []time.Time
|
||||
@@ -379,4 +387,88 @@ func TestIntegrationEntityServer(t *testing.T) {
|
||||
w2.Entity.Version,
|
||||
}, version)
|
||||
})
|
||||
|
||||
t.Run("should be able to filter objects based on their labels", func(t *testing.T) {
|
||||
kind := models.StandardKindDashboard
|
||||
_, err := testCtx.client.Write(ctx, &entity.WriteEntityRequest{
|
||||
GRN: &entity.GRN{
|
||||
Kind: kind,
|
||||
UID: "blue-green",
|
||||
},
|
||||
Body: []byte(dashboardWithTagsBlueGreen),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = testCtx.client.Write(ctx, &entity.WriteEntityRequest{
|
||||
GRN: &entity.GRN{
|
||||
Kind: kind,
|
||||
UID: "red-green",
|
||||
},
|
||||
Body: []byte(dashboardWithTagsRedGreen),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
search, err := testCtx.client.Search(ctx, &entity.EntitySearchRequest{
|
||||
Kind: []string{kind},
|
||||
WithBody: false,
|
||||
WithLabels: true,
|
||||
Labels: map[string]string{
|
||||
"red": "",
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, search)
|
||||
require.Len(t, search.Results, 1)
|
||||
require.Equal(t, search.Results[0].GRN.UID, "red-green")
|
||||
|
||||
search, err = testCtx.client.Search(ctx, &entity.EntitySearchRequest{
|
||||
Kind: []string{kind},
|
||||
WithBody: false,
|
||||
WithLabels: true,
|
||||
Labels: map[string]string{
|
||||
"red": "",
|
||||
"green": "",
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, search)
|
||||
require.Len(t, search.Results, 1)
|
||||
require.Equal(t, search.Results[0].GRN.UID, "red-green")
|
||||
|
||||
search, err = testCtx.client.Search(ctx, &entity.EntitySearchRequest{
|
||||
Kind: []string{kind},
|
||||
WithBody: false,
|
||||
WithLabels: true,
|
||||
Labels: map[string]string{
|
||||
"red": "invalid",
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, search)
|
||||
require.Len(t, search.Results, 0)
|
||||
|
||||
search, err = testCtx.client.Search(ctx, &entity.EntitySearchRequest{
|
||||
Kind: []string{kind},
|
||||
WithBody: false,
|
||||
WithLabels: true,
|
||||
Labels: map[string]string{
|
||||
"green": "",
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, search)
|
||||
require.Len(t, search.Results, 2)
|
||||
|
||||
search, err = testCtx.client.Search(ctx, &entity.EntitySearchRequest{
|
||||
Kind: []string{kind},
|
||||
WithBody: false,
|
||||
WithLabels: true,
|
||||
Labels: map[string]string{
|
||||
"yellow": "",
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, search)
|
||||
require.Len(t, search.Results, 0)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user