From 5880aa21eecd3dfa66db039beea7122ef30aeb01 Mon Sep 17 00:00:00 2001 From: Alex Dunmow Date: Fri, 3 Jul 2026 17:51:08 +0800 Subject: [PATCH] test: modernize idiom in wasmguest tests (slices.Contains, any, new(v)) - driver_test.go: use slices.Contains instead of a hand-rolled loop - sqlcgen_test.go: interface{} -> any in the generated-style DBTX shim - caps_roundtrip_test.go: new(idParent.String()) instead of proto.String for the pointer literal Co-Authored-By: Claude Opus 4.8 --- plugin/wasmguest/bnwasm/driver_test.go | 8 ++------ plugin/wasmguest/bnwasm/sqlcgen_test.go | 6 +++--- plugin/wasmguest/caps/caps_roundtrip_test.go | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/plugin/wasmguest/bnwasm/driver_test.go b/plugin/wasmguest/bnwasm/driver_test.go index 019b516..d2dd193 100644 --- a/plugin/wasmguest/bnwasm/driver_test.go +++ b/plugin/wasmguest/bnwasm/driver_test.go @@ -5,6 +5,7 @@ import ( "database/sql" "errors" "reflect" + "slices" "testing" "time" @@ -295,10 +296,5 @@ func TestDatabaseSQLDriverRegistered(t *testing.T) { } func slicesContains(s []string, v string) bool { - for _, x := range s { - if x == v { - return true - } - } - return false + return slices.Contains(s, v) } diff --git a/plugin/wasmguest/bnwasm/sqlcgen_test.go b/plugin/wasmguest/bnwasm/sqlcgen_test.go index 15ceb59..d6c68fc 100644 --- a/plugin/wasmguest/bnwasm/sqlcgen_test.go +++ b/plugin/wasmguest/bnwasm/sqlcgen_test.go @@ -21,9 +21,9 @@ import ( // DBTX interface, the same pgconn.CommandTag / pgx.Rows / pgx.Row signatures. type DBTX interface { - Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error) - Query(context.Context, string, ...interface{}) (pgx.Rows, error) - QueryRow(context.Context, string, ...interface{}) pgx.Row + Exec(context.Context, string, ...any) (pgconn.CommandTag, error) + Query(context.Context, string, ...any) (pgx.Rows, error) + QueryRow(context.Context, string, ...any) pgx.Row } func New(db DBTX) *Queries { return &Queries{db: db} } diff --git a/plugin/wasmguest/caps/caps_roundtrip_test.go b/plugin/wasmguest/caps/caps_roundtrip_test.go index a11b9b4..5016267 100644 --- a/plugin/wasmguest/caps/caps_roundtrip_test.go +++ b/plugin/wasmguest/caps/caps_roundtrip_test.go @@ -322,7 +322,7 @@ func TestCapabilityRoundTrip(t *testing.T) { name: "menus_get_menu_items", wantMethod: "menus.get_menu_items", resp: &abiv1.MenusGetMenuItemsResponse{Items: []*abiv1.MenuItem{{ Id: idItem.String(), MenuId: idMenu.String(), Label: "Home", Url: "/", - PageSlug: "home", ParentId: proto.String(idParent.String()), SortOrder: 1, + PageSlug: "home", ParentId: new(idParent.String()), SortOrder: 1, OpenInNewTab: true, CssClass: "nav", ItemType: "link", Icon: "home", }}}, run: func(t *testing.T, cs plugin.CoreServices) {