mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
- Adds a find endpoint to return dashboard bindings that match any of the scopes. For example /apis/scope.grafana.app/v0alpha1/namespaces/default/find/scope_dashboard_bindings?scope=s1&scope=s2 - Updates the ScopeNode find endpoint to a new path, /find/scope_node_children , makes the key "items" for all find endpoints (instead of mix of "found" and "items"), and makes the list item type a ScopeNode instead of its own type. - Updates kubectl get commands to return more information about scopes, scopenodes, and scopedashboard bindings to display more fields in table output --------- Signed-off-by: bergquist <carl.bergquist@gmail.com> Co-authored-by: Ryan McKinley <ryantxu@gmail.com> Co-authored-by: Kyle Brandt <kyle@grafana.com> Co-authored-by: Todd Treece <todd.treece@grafana.com>
72 lines
1.7 KiB
Go
72 lines
1.7 KiB
Go
package scope
|
|
|
|
import (
|
|
"testing"
|
|
|
|
scope "github.com/grafana/grafana/pkg/apis/scope/v0alpha1"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestFilterAndAppendItem(t *testing.T) {
|
|
tcs := []struct {
|
|
Description string
|
|
|
|
ParentName string
|
|
Title string
|
|
|
|
QueryParam string
|
|
ParentParam string
|
|
|
|
ExpectedMatches int
|
|
}{
|
|
{
|
|
Description: "Matching parent without query param",
|
|
ParentName: "ParentNumberOne",
|
|
Title: "item",
|
|
QueryParam: "",
|
|
ParentParam: "ParentNumberOne",
|
|
ExpectedMatches: 1,
|
|
},
|
|
{
|
|
Description: "Not matching parent",
|
|
ParentName: "ParentNumberOne",
|
|
Title: "itemOne",
|
|
QueryParam: "itemTwo",
|
|
ParentParam: "ParentNumberTwo",
|
|
ExpectedMatches: 0,
|
|
},
|
|
{
|
|
Description: "Matching parent and query param",
|
|
ParentName: "ParentNumberOne",
|
|
Title: "itemOne",
|
|
QueryParam: "itemOne",
|
|
ParentParam: "ParentNumberOne",
|
|
ExpectedMatches: 1,
|
|
},
|
|
{
|
|
Description: "matching parent but not matching query param",
|
|
ParentName: "ParentNumberOne",
|
|
Title: "itemOne",
|
|
QueryParam: "itemTwo",
|
|
ParentParam: "ParentNumberOne",
|
|
ExpectedMatches: 0,
|
|
},
|
|
}
|
|
|
|
for _, tc := range tcs {
|
|
results := &scope.FindScopeNodeChildrenResults{}
|
|
item := scope.ScopeNode{
|
|
Spec: scope.ScopeNodeSpec{
|
|
ParentName: tc.ParentName,
|
|
Title: tc.Title,
|
|
Description: "item description",
|
|
NodeType: "item type",
|
|
LinkType: "item link type",
|
|
LinkID: "item link ID",
|
|
},
|
|
}
|
|
filterAndAppendItem(item, tc.ParentParam, tc.QueryParam, results)
|
|
require.Equal(t, len(results.Items), tc.ExpectedMatches, tc.Description)
|
|
}
|
|
}
|