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:
@@ -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
|
||||
}
|
||||
|
||||
15
internal/util/util_test.go
Normal file
15
internal/util/util_test.go
Normal 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"))
|
||||
}
|
||||
Reference in New Issue
Block a user