diff --git a/cel/env.go b/cel/env.go index 03f399ac..69ba34db 100644 --- a/cel/env.go +++ b/cel/env.go @@ -390,7 +390,7 @@ func (e *Env) HasLibrary(libName string) bool { // Libraries returns a list of SingletonLibrary that have been configured in the environment. func (e *Env) Libraries() []string { - libraries := make([]string, len(e.libraries)) + libraries := make([]string, 0, len(e.libraries)) for libName := range e.libraries { libraries = append(libraries, libName) } diff --git a/cel/env_test.go b/cel/env_test.go index d0df18fc..aaba2b99 100644 --- a/cel/env_test.go +++ b/cel/env_test.go @@ -238,9 +238,13 @@ func TestLibraries(t *testing.T) { t.Errorf("Expected HasLibrary() to return true for '%s'", expected) } libMap := map[string]struct{}{} - for _, lib := range e.Libraries() { + libraries := e.Libraries() + for _, lib := range libraries { libMap[lib] = struct{}{} } + if len(libraries) != 2 { + t.Errorf("Expected HasLibrary() to contain exactly 2 libraries but got: %v", libraries) + } if _, ok := libMap[expected]; !ok { t.Errorf("Expected Libraries() to include '%s'", expected)