micro--go-micro
c7657f73f4
goreleaser / goreleaser (push) Has been cancelled
* test(harness): read agent plan from the scoped store
The store-scoping change moved an agent's plan from the default table
key agent/{name}/plan to its own table (database "agent", table {name},
key "plan"). The plan-delegate harness tests still read the old key and
failed with 'not found'; read through store.Scope(mem, "agent", name)
like the agent does.
* docs: orient agents-first across README, landing, and docs overview
Lead with agents (then services and flows), surface MCP + A2A as the
interop story, and frame agents as services. Landing hero and feature
grid reordered agents-first with an A2A gateway card.
* v6: module path go-micro.dev/v6, TLS secure by default, NewService
Cut v6. Three breaking changes, bundled so the major bump is paid once:
- Module path go-micro.dev/v5 -> go-micro.dev/v6 across all imports + go.mod.
- TLS verification on by default (was off). MICRO_TLS_SECURE removed;
MICRO_TLS_INSECURE=true opts out for self-signed/dev.
- micro.NewService(name, opts...) is the canonical service constructor,
symmetric with NewAgent/NewFlow; micro.New kept as a deprecated alias;
the old name-less NewService(opts...) removed. Generators emit NewService.
Also ports the JWT auth token provider in-module (go-micro.dev/v6/auth/jwt/token
on golang-jwt/jwt/v5), dropping the v5-pinned github.com/micro/plugins/v5/auth/jwt
and the deprecated dgrijalva/jwt-go.
Docs/README/landing updated to v6 and @latest; v5->v6 migration guide added;
CHANGELOG cut as [6.0.0]. Blog posts left at their historical versions.
---------
Co-authored-by: Claude <noreply@anthropic.com>
185 行
3.7 KiB
Go
185 行
3.7 KiB
Go
package natsjskv
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net"
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
nserver "github.com/nats-io/nats-server/v2/server"
|
|
"github.com/pkg/errors"
|
|
"github.com/test-go/testify/require"
|
|
"go-micro.dev/v6/store"
|
|
)
|
|
|
|
func testSetup(ctx context.Context, t *testing.T, opts ...store.Option) store.Store {
|
|
t.Helper()
|
|
|
|
var err error
|
|
var s store.Store
|
|
for i := 0; i < 5; i++ {
|
|
nCtx, cancel := context.WithCancel(ctx)
|
|
addr := startNatsServer(nCtx, t)
|
|
|
|
opts = append(opts, store.Nodes(addr), EncodeKeys())
|
|
s = NewStore(opts...)
|
|
|
|
err = s.Init()
|
|
if err != nil {
|
|
t.Log(errors.Wrap(err, "Error: Server initialization failed, restarting server"))
|
|
cancel()
|
|
if err = s.Close(); err != nil {
|
|
t.Logf("Failed to close store: %v", err)
|
|
}
|
|
time.Sleep(time.Second)
|
|
continue
|
|
}
|
|
|
|
go func() {
|
|
<-ctx.Done()
|
|
cancel()
|
|
if err = s.Close(); err != nil {
|
|
t.Logf("Failed to close store: %v", err)
|
|
}
|
|
}()
|
|
|
|
return s
|
|
}
|
|
t.Error(errors.Wrap(err, "Store initialization failed"))
|
|
return s
|
|
}
|
|
|
|
func startNatsServer(ctx context.Context, t *testing.T) string {
|
|
t.Helper()
|
|
natsAddr := getFreeLocalhostAddress()
|
|
natsPort, err := strconv.Atoi(strings.Split(natsAddr, ":")[1])
|
|
if err != nil {
|
|
t.Logf("Failed to parse port from address: %v", err)
|
|
}
|
|
|
|
clusterName := "gomicro-store-test-cluster"
|
|
|
|
// start the NATS with JetStream server
|
|
go natsServer(ctx,
|
|
t,
|
|
&nserver.Options{
|
|
Host: strings.Split(natsAddr, ":")[0],
|
|
Port: natsPort,
|
|
Cluster: nserver.ClusterOpts{
|
|
Name: clusterName,
|
|
},
|
|
},
|
|
)
|
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
return natsAddr
|
|
}
|
|
|
|
func getFreeLocalhostAddress() string {
|
|
l, err := net.Listen("tcp", "127.0.0.1:0")
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
|
|
addr := l.Addr().String()
|
|
if err := l.Close(); err != nil {
|
|
return addr
|
|
}
|
|
return addr
|
|
}
|
|
|
|
func natsServer(ctx context.Context, t *testing.T, opts *nserver.Options) {
|
|
t.Helper()
|
|
|
|
opts.TLSTimeout = 180
|
|
server, err := nserver.NewServer(
|
|
opts,
|
|
)
|
|
require.NoError(t, err)
|
|
if err != nil {
|
|
return
|
|
}
|
|
defer server.Shutdown()
|
|
|
|
server.SetLoggerV2(
|
|
NewLogWrapper(),
|
|
false, false, false,
|
|
)
|
|
|
|
tmpdir := t.TempDir()
|
|
natsdir := filepath.Join(tmpdir, "nats-js")
|
|
jsConf := &nserver.JetStreamConfig{
|
|
StoreDir: natsdir,
|
|
}
|
|
|
|
// first start NATS
|
|
go server.Start()
|
|
time.Sleep(time.Second)
|
|
|
|
// second start JetStream
|
|
err = server.EnableJetStream(jsConf)
|
|
require.NoError(t, err)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
// This fixes some issues where tests fail because directory cleanup fails
|
|
t.Cleanup(func() {
|
|
contents, err := filepath.Glob(natsdir + "/*")
|
|
if err != nil {
|
|
t.Logf("Failed to glob directory: %v", err)
|
|
}
|
|
for _, item := range contents {
|
|
if err := os.RemoveAll(item); err != nil {
|
|
t.Logf("Failed to remove file: %v", err)
|
|
}
|
|
}
|
|
if err := os.RemoveAll(natsdir); err != nil {
|
|
t.Logf("Failed to remove directory: %v", err)
|
|
}
|
|
})
|
|
|
|
<-ctx.Done()
|
|
}
|
|
|
|
func NewLogWrapper() *LogWrapper {
|
|
return &LogWrapper{}
|
|
}
|
|
|
|
type LogWrapper struct {
|
|
}
|
|
|
|
// Noticef logs a notice statement.
|
|
func (l *LogWrapper) Noticef(_ string, _ ...interface{}) {
|
|
}
|
|
|
|
// Warnf logs a warning statement.
|
|
func (l *LogWrapper) Warnf(format string, v ...interface{}) {
|
|
fmt.Printf(format+"\n", v...)
|
|
}
|
|
|
|
// Fatalf logs a fatal statement.
|
|
func (l *LogWrapper) Fatalf(format string, v ...interface{}) {
|
|
fmt.Printf(format+"\n", v...)
|
|
}
|
|
|
|
// Errorf logs an error statement.
|
|
func (l *LogWrapper) Errorf(format string, v ...interface{}) {
|
|
fmt.Printf(format+"\n", v...)
|
|
}
|
|
|
|
// Debugf logs a debug statement.
|
|
func (l *LogWrapper) Debugf(_ string, _ ...interface{}) {
|
|
}
|
|
|
|
// Tracef logs a trace statement.
|
|
func (l *LogWrapper) Tracef(format string, v ...interface{}) {
|
|
fmt.Printf(format+"\n", v...)
|
|
}
|