feat: initial kmsvc-sdk Go client for kafkamgmt.v1 message-plane API

Client/auth/message-plane methods/long-poll/typed errors, all tested
against an in-process bufconn fake. Consumes [email protected] via
go get (GOPRIVATE), no submodule or local codegen.
This commit is contained in:
riotpiaole
2026-06-21 19:57:41 -07:00
commit 6ef58c108f
17 changed files with 1125 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
package kmsvc
import (
"context"
"testing"
kafkamgmtv1 "forgejo.riotpiao.homelab.com/rock/kmsvc-proto/gen/kafkamgmt/v1"
)
func TestClientAttachesBearerToken(t *testing.T) {
fake := &fakeQueueService{
sendMessage: func(ctx context.Context, req *kafkamgmtv1.SendMessageRequest) (*kafkamgmtv1.SendMessageResponse, error) {
return &kafkamgmtv1.SendMessageResponse{MessageId: "m1"}, nil
},
}
client := newTestClient(t, fake, WithTokenSource(StaticToken("test-token")))
_, err := client.SendMessage(context.Background(), SendMessageInput{QueueName: "q", Body: []byte("hi")})
if err != nil {
t.Fatalf("SendMessage: %v", err)
}
if got, want := fake.lastIncomingAuth, "Bearer test-token"; got != want {
t.Errorf("authorization header = %q, want %q", got, want)
}
}
func TestClientWithoutTokenSourceSendsNoAuthHeader(t *testing.T) {
fake := &fakeQueueService{
sendMessage: func(ctx context.Context, req *kafkamgmtv1.SendMessageRequest) (*kafkamgmtv1.SendMessageResponse, error) {
return &kafkamgmtv1.SendMessageResponse{MessageId: "m1"}, nil
},
}
client := newTestClient(t, fake)
_, err := client.SendMessage(context.Background(), SendMessageInput{QueueName: "q", Body: []byte("hi")})
if err != nil {
t.Fatalf("SendMessage: %v", err)
}
if fake.lastIncomingAuth != "" {
t.Errorf("authorization header = %q, want empty", fake.lastIncomingAuth)
}
}