Files
kmsvc-sdk/auth_test.go
T
riotpiaoleandClaude Haiku 4.5 e4017aea9e feat: add CI/release automation and complete SDK implementation
- Add Forgejo CI workflow: gofmt checks, module caching, coverage reporting
- Add release workflow: auto-tag-triggered release with changelog extraction
- Update module paths from rock/ to homelab/ namespace
- Enhance test coverage and documentation (PLAN.md, README.md)

Co-Authored-By: Claude Haiku 4.5 <[email protected]>
2026-06-29 13:34:22 -07:00

45 lines
1.4 KiB
Go

package kmsvc
import (
"context"
"testing"
kafkamgmtv1 "forgejo.riotpiao.homelab.com/homelab/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)
}
}