1
0
mirror of https://github.com/containers/buildah.git synced 2026-02-05 09:45:38 +01:00

internal/util.SetHas(): handle maps of [generic]generic

Make SetHas() a generic function for checking if a map holds a value of
whatever kind for a key of some comparable kind.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
This commit is contained in:
Nalin Dahyabhai
2025-05-14 15:46:09 -04:00
parent 5a60789759
commit ee0f750ea7
2 changed files with 16 additions and 1 deletions

View File

@@ -98,7 +98,7 @@ func ExportFromReader(input io.Reader, opts define.BuildOutputOption) error {
return nil
}
func SetHas(m map[string]struct{}, k string) bool {
func SetHas[K comparable, V any](m map[K]V, k K) bool {
_, ok := m[k]
return ok
}

View File

@@ -0,0 +1,15 @@
package util
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSetHas(t *testing.T) {
m := map[string]string{
"key1": "ignored",
}
assert.True(t, SetHas(m, "key1"))
assert.False(t, SetHas(m, "key2"))
}