Skip to content

Commit

Permalink
Fix slice handling in Env.Libraries() (#826)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbetz authored Aug 23, 2023
1 parent ff98bc0 commit 52ee283
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cel/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 5 additions & 1 deletion cel/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 52ee283

Please sign in to comment.