diff --git a/pkg/resource/internal/kv/kv.go b/pkg/resource/internal/kv/kv.go index c8be7dc..17fada1 100644 --- a/pkg/resource/internal/kv/kv.go +++ b/pkg/resource/internal/kv/kv.go @@ -82,22 +82,7 @@ func (kv *KV) Raw() map[string]string { // Equal checks kv for equality. func (kv KV) Equal(other KV) bool { - // shortcut for common case of having no keys - if kv.m == nil && other.m == nil { - return true - } - - if len(kv.m) != len(other.m) { - return false - } - - for k, v := range kv.m { - if v != other.m[k] { - return false - } - } - - return true + return maps.Equal(kv.m, other.m) } // Empty if there are no pairs. diff --git a/pkg/resource/internal/kv/kv_test.go b/pkg/resource/internal/kv/kv_test.go new file mode 100644 index 0000000..cc31712 --- /dev/null +++ b/pkg/resource/internal/kv/kv_test.go @@ -0,0 +1,24 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +package kv_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/cosi-project/runtime/pkg/resource/internal/kv" +) + +func TestEqualSameLenEmptyValue(t *testing.T) { + var kv1, kv2 kv.KV + + kv1.Set("a", "") + kv2.Set("b", "") + + equal := kv1.Equal(kv2) + + assert.False(t, equal, "Expected kv1 and kv2 to be not equal") +}