8000 Fix slice handling in Env.Libraries() (#825) · google/cel-go@dd6d31d · GitHub
[go: up one dir, main page]

Skip to content

Commit dd6d31d

Browse files
authored
Fix slice handling in Env.Libraries() (#825)
1 parent 8a45955 commit dd6d31d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

cel/env.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ func (e *Env) HasLibrary(libName string) bool {
391391

392392
// Libraries returns a list of SingletonLibrary that have been configured in the environment.
393393
func (e *Env) Libraries() []string {
394-
libraries := make([]string, len(e.libraries))
394+
libraries := make([]string, 0, len(e.libraries))
395395
for libName := range e.libraries {
396396
libraries = append(libraries, libName)
397397
}

cel/env_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,13 @@ func TestLibraries(t *testing.T) {
257257
t.Errorf("Expected HasLibrary() to return true for '%s'", expected)
258258
}
259259
libMap := map[string]struct{}{}
260-
for _, lib := range e.Libraries() {
260+
libraries := e.Libraries()
261+
for _, lib := range libraries {
261262
libMap[lib] = struct{}{}
262263
}
264+
if len(libraries) != 2 {
265+
t.Errorf("Expected HasLibrary() to contain exactly 2 libraries but got: %v", libraries)
266+
}
263267

264268
if _, ok := libMap[expected]; !ok {
265269
t.Errorf("Expected Libraries() to include '%s'", expected)

0 commit comments

Comments
 (0)
0