Files
Anisha Gupta US c1ef896e22 feat(controller): expose observed node pool counts (#2400)
* feat(controller): expose observed node pool counts (poc)

Signed-off-by: Anisha Gupta <anisgupta@nvidia.com>

* refactor(controller): keep node pool counts with pool queries

Signed-off-by: Anisha Gupta <anisgupta@nvidia.com>

* refactor(controller): name compared node set current

Signed-off-by: Anisha Gupta <anisgupta@nvidia.com>

* refactor(controller): use a generic json equality helper name

Signed-off-by: Anisha Gupta <anisgupta@nvidia.com>

* refactor(controller): use inner join for node set counts

Signed-off-by: Anisha Gupta <anisgupta@nvidia.com>

* refactor(controller): use node set names in count aggregation

Signed-off-by: Anisha Gupta <anisgupta@nvidia.com>

* refactor(controller): consolidate node pool response mapping

Signed-off-by: Anisha Gupta <anisgupta@nvidia.com>

* docs: keep node pool field definitions in the api reference

Signed-off-by: Anisha Gupta <anisgupta@nvidia.com>

* refactor(controller): restore single node pool response conversion

Signed-off-by: Anisha Gupta <anisgupta@nvidia.com>

* test(controller): colocate node pool count tests

Signed-off-by: Anisha Gupta <anisgupta@nvidia.com>

* test(controller): colocate node pool response count tests

Signed-off-by: Anisha Gupta <anisgupta@nvidia.com>

* refactor(api): name observed node pool count explicitly

Signed-off-by: Anisha Gupta <anisgupta@nvidia.com>

* fix(controller): compare template JSON numbers by exact value

Signed-off-by: Anisha Gupta <anisgupta@nvidia.com>

* refactor(controller): limit JSON comparison to node pool counts

Signed-off-by: Anisha Gupta <anisgupta@nvidia.com>

* refactor(controller): restore shared pool configuration comparison

Signed-off-by: Anisha Gupta <anisgupta@nvidia.com>

* refactor(controller): move json equality to shared utils

Signed-off-by: Anisha Gupta <anisgupta@nvidia.com>

* test(controller): use unambiguous numeric precision fixtures

Signed-off-by: Anisha Gupta <anisgupta@nvidia.com>

* refactor(controller): simplify node pool count responses

Signed-off-by: Anisha Gupta <anisgupta@nvidia.com>

* perf(controller): index nodes by node pool

Signed-off-by: Anisha Gupta <anisgupta@nvidia.com>

---------

Signed-off-by: Anisha Gupta <anisgupta@nvidia.com>
2026-11-23 14:39:40 -05:00

57 lines
2.3 KiB
Go

// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package utils
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/require"
)
func TestJSONEqual(t *testing.T) {
t.Parallel()
for _, tt := range []struct {
name, desired, current string
want bool
}{
{"exponent", `{"spec":{"value":1e-7}}`, `{"spec":{"value":0.0000001}}`, true},
{"nested numbers", `{"values":[1,1e3,-0,true,null,"x"]}`, `{"values":[1.0,1000,0,true,null,"x"]}`, true},
{"large equivalent integers", `{"value":18014398509481985}`, `{"value":18014398509481985.0}`, true},
{"distinct large integers", `{"value":18014398509481984}`, `{"value":18014398509481985}`, false},
{"number and string", `{"value":1}`, `{"value":"1"}`, false},
{"array order", `[1,2]`, `[2,1]`, false},
{"object keys", `{"a":null}`, `{"b":null}`, false},
{"invalid JSON", `{"value":`, `{"value":1}`, false},
{"identical bytes", `{"a":1}`, `{"a":1}`, true},
{"key order", `{"a":1,"b":2}`, `{"b":2,"a":1}`, true},
{"nested key order", `{"a":{"b":1,"c":2}}`, `{"a":{"c":2,"b":1}}`, true},
{"whitespace", ` { "a" : [1, 2] } `, `{"a":[1,2]}`, true},
{"object and array", `{}`, `[]`, false},
{"true and false", `true`, `false`, false},
{"null and string", `null`, `"null"`, false},
{"identical invalid JSON", `{"a":`, `{"a":`, false},
{"trailing garbage", `{"a":1} garbage`, `{"a":1}`, false},
{"trailing JSON value", `{"a":1} {}`, `{"a":1}`, false},
{"trailing delimiter", `{"a":1}]`, `{"a":1}`, false},
{"identical trailing data", `{"a":1} garbage`, `{"a":1} garbage`, false},
{"trailing whitespace", "{\"a\":1} \n\t", `{"a":1}`, true},
{"empty inputs", ``, ``, true},
{"empty and null", ``, `null`, false},
{"whitespace only", ` `, ` `, false},
} {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
require.Equal(t, tt.want, JSONEqual(json.RawMessage(tt.desired), json.RawMessage(tt.current)))
require.Equal(t, tt.want, JSONEqual(json.RawMessage(tt.current), json.RawMessage(tt.desired)))
})
}
t.Run("nil and empty", func(t *testing.T) {
t.Parallel()
require.True(t, JSONEqual(nil, json.RawMessage{}))
require.True(t, JSONEqual(json.RawMessage{}, nil))
require.True(t, JSONEqual(nil, nil))
})
}