Files
kmsvc-sdk/auth_test.go
T
riotpiaole 6ef58c108f 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.
2026-06-21 19:57:41 -07:00

45 lines
1.4 KiB
Go

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)
}
}