mirror of
https://github.com/absmach/magistrala.git
synced 2026-08-07 07:14:46 +00:00
NOISSUE - Simplify alarms
Signed-off-by: dusan <borovcanindusan1@gmail.com>
This commit is contained in:
@@ -554,8 +554,11 @@ func (c *Client) ListResources(ctx context.Context, q Query) (ResourceList, erro
|
||||
if q.Name != "" && q.Q == "" {
|
||||
vars["q"] = q.Name
|
||||
}
|
||||
err := c.graphQL(ctx, `query Resources($q: String, $kind: String, $tenantId: ID, $limit: Int, $offset: Int) {
|
||||
resources(q: $q, kind: $kind, tenantId: $tenantId, limit: $limit, offset: $offset) {
|
||||
if len(q.AttributesContains) > 0 {
|
||||
vars["attributesContains"] = q.AttributesContains
|
||||
}
|
||||
err := c.graphQL(ctx, `query Resources($q: String, $kind: String, $tenantId: ID, $attributesContains: JSON, $limit: Int, $offset: Int) {
|
||||
resources(q: $q, kind: $kind, tenantId: $tenantId, attributesContains: $attributesContains, limit: $limit, offset: $offset) {
|
||||
total
|
||||
items { id kind name tenant_id: tenantId owner_id: ownerId attributes created_at: createdAt updated_at: updatedAt }
|
||||
}
|
||||
|
||||
@@ -65,14 +65,22 @@ func TestListResources(t *testing.T) {
|
||||
t.Fatalf("unexpected request: %s %s", r.Method, r.URL.Path)
|
||||
}
|
||||
var payload struct {
|
||||
Query string `json:"query"`
|
||||
Variables map[string]any `json:"variables"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
|
||||
t.Fatalf("decode request: %v", err)
|
||||
}
|
||||
if !strings.Contains(payload.Query, "$attributesContains: JSON") || !strings.Contains(payload.Query, "attributesContains: $attributesContains") {
|
||||
t.Fatalf("query does not include attributesContains: %s", payload.Query)
|
||||
}
|
||||
if payload.Variables["kind"] != KindRule || payload.Variables["tenantId"] != testDomainID {
|
||||
t.Fatalf("unexpected variables: %+v", payload.Variables)
|
||||
}
|
||||
attrs, ok := payload.Variables["attributesContains"].(map[string]any)
|
||||
if !ok || attrs["status"] != "active" {
|
||||
t.Fatalf("unexpected attributesContains: %+v", payload.Variables)
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
"data": map[string]any{
|
||||
"resources": map[string]any{
|
||||
@@ -85,7 +93,11 @@ func TestListResources(t *testing.T) {
|
||||
defer srv.Close()
|
||||
|
||||
client := NewClient(Config{URL: srv.URL, Timeout: time.Second})
|
||||
got, err := client.ListResources(context.Background(), Query{Kind: KindRule, TenantID: testDomainID})
|
||||
got, err := client.ListResources(context.Background(), Query{
|
||||
Kind: KindRule,
|
||||
TenantID: testDomainID,
|
||||
AttributesContains: Attributes{"status": "active"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("list failed: %v", err)
|
||||
}
|
||||
|
||||
+10
-9
@@ -55,15 +55,16 @@ type Resource struct {
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
IDs []string
|
||||
Q string
|
||||
Kind string
|
||||
TenantID string
|
||||
Name string
|
||||
Route string
|
||||
Status string
|
||||
Limit uint64
|
||||
Offset uint64
|
||||
IDs []string
|
||||
Q string
|
||||
Kind string
|
||||
TenantID string
|
||||
Name string
|
||||
Route string
|
||||
Status string
|
||||
AttributesContains Attributes
|
||||
Limit uint64
|
||||
Offset uint64
|
||||
}
|
||||
|
||||
type AuthzRequest struct {
|
||||
|
||||
Reference in New Issue
Block a user