ipn/ipnlocal: add test support code for app connectors

Change-Id: I75242082414b14f64a1636a1f41a27ef58aec830
This commit is contained in:
M. J. Fromberger 2025-09-19 09:23:23 -07:00
parent eca10c0c19
commit db329058ff

View File

@ -7042,3 +7042,41 @@ func toStrings[T ~string](in []T) []string {
}
return out
}
type textUpdate struct {
Advertise []string
Unadvertise []string
}
func routeUpdateToText(u appc.RouteUpdate) textUpdate {
var out textUpdate
for _, p := range u.Advertise {
out.Advertise = append(out.Advertise, p.String())
}
for _, p := range u.Unadvertise {
out.Unadvertise = append(out.Unadvertise, p.String())
}
return out
}
func mustPrefix(ss ...string) (out []netip.Prefix) {
for _, s := range ss {
out = append(out, netip.MustParsePrefix(s))
}
return
}
// eqUpdate generates an eventbus test filter that matches an appc.RouteUpdate
// message equal to want, or reports an error giving a human-readable diff.
//
// TODO(creachadair): This is copied from the appc test package, but we can't
// put it into the appctest package because the appc tests depend on it and
// that makes a cycle. Clean up those tests and put this somewhere common.
func eqUpdate(want appc.RouteUpdate) func(appc.RouteUpdate) error {
return func(got appc.RouteUpdate) error {
if diff := cmp.Diff(routeUpdateToText(got), routeUpdateToText(want)); diff != "" {
return fmt.Errorf("wrong update (-got, +want):\n%s", diff)
}
return nil
}
}