refactor: use slices.Contains to simplify code (#16680)

### Summary

There is a [new function](https://pkg.go.dev/slices@go1.21.0#Contains)
added in the go1.21 standard library, which can make the code more
concise and easy to read.

Signed-off-by: weifanglab <weifanglab@outlook.com>
This commit is contained in:
weifanglab
2026-07-07 11:12:38 +08:00
committed by GitHub
parent 863b35db7f
commit 7a4e1b6034
15 changed files with 41 additions and 141 deletions

View File

@@ -15,6 +15,7 @@ package component
import (
"context"
"errors"
"slices"
"testing"
"github.com/cloudwego/eino/schema"
@@ -178,14 +179,7 @@ func TestLLM_Invoke_InvokerError(t *testing.T) {
func TestLLM_Registered(t *testing.T) {
names := RegisteredNames()
found := false
for _, n := range names {
if n == "llm" {
found = true
break
}
}
if !found {
if !slices.Contains(names, "llm") {
t.Fatalf("LLM not registered; names=%v", names)
}
// And a factory round-trip.

View File

@@ -35,6 +35,7 @@ package component
import (
"context"
"slices"
"testing"
)
@@ -45,14 +46,7 @@ import (
// assert their absence here.
func TestParallel_Registered(t *testing.T) {
names := RegisteredNames()
hasParallel := false
for _, n := range names {
if n == "parallel" {
hasParallel = true
break
}
}
if !hasParallel {
if !slices.Contains(names, "parallel") {
t.Errorf("Parallel not registered; RegisteredNames=%v", names)
}
}