MCPcopy
hub / github.com/segmentio/kafka-go / TestAwsMskIamMechanism

Function TestAwsMskIamMechanism

sasl/aws_msk_iam/msk_iam_test.go:24–105  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22var signTime = time.Date(2021, 10, 14, 13, 5, 0, 0, time.UTC)
23
24func TestAwsMskIamMechanism(t *testing.T) {
25 tests := []struct {
26 description string
27 ctx func() context.Context
28 shouldFail bool
29 }{
30 {
31 description: "with metadata",
32 ctx: func() context.Context {
33 return sasl.WithMetadata(context.Background(), &sasl.Metadata{
34 Host: "localhost",
35 Port: 9092,
36 })
37 },
38 },
39 {
40 description: "without metadata",
41 ctx: func() context.Context {
42 return context.Background()
43 },
44 shouldFail: true,
45 },
46 }
47
48 for _, tt := range tests {
49 t.Run(tt.description, func(t *testing.T) {
50 ctx := tt.ctx()
51
52 creds := credentials.NewStaticCredentials(accessKeyId, secretAccessKey, "")
53 mskMechanism := &Mechanism{
54 Signer: sigv4.NewSigner(creds),
55 Region: "us-east-1",
56 SignTime: signTime,
57 }
58
59 sess, auth, err := mskMechanism.Start(ctx)
60 if tt.shouldFail { // if error is expected
61 if err == nil { // but we don't find one
62 t.Fatal("error expected")
63 } else { // but we do find one
64 return // return early since the remaining assertions are irrelevant
65 }
66 } else { // if error is not expected (typical)
67 if err != nil { // but we do find one
68 t.Fatal(err)
69 }
70 }
71
72 if sess != mskMechanism {
73 t.Error(
74 "Unexpected session",
75 "expected", mskMechanism,
76 "got", sess,
77 )
78 }
79
80 expectedMap := map[string]string{
81 "version": "2020_10_22",

Callers

nothing calls this directly

Calls 4

StartMethod · 0.95
WithMetadataFunction · 0.92
MarshalMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected