-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package kafkalib | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConnection_Mechanism(t *testing.T) { | ||
{ | ||
c := NewConnection(false, false, "", "") | ||
assert.Equal(t, Plain, c.Mechanism()) | ||
} | ||
{ | ||
c := NewConnection(false, false, "username", "password") | ||
assert.Equal(t, ScramSha512, c.Mechanism()) | ||
|
||
// AWS MSK IAM is enabled, but SCRAM is preferred | ||
c = NewConnection(true, false, "username", "password") | ||
assert.Equal(t, ScramSha512, c.Mechanism()) | ||
} | ||
{ | ||
c := NewConnection(true, false, "", "") | ||
assert.Equal(t, AwsMskIam, c.Mechanism()) | ||
} | ||
} | ||
|
||
func TestConnection_Dialer(t *testing.T) { | ||
ctx := context.Background() | ||
{ | ||
// Plain | ||
c := NewConnection(false, false, "", "") | ||
dialer, err := c.Dialer(ctx) | ||
assert.NoError(t, err) | ||
assert.Nil(t, dialer.TLS) | ||
assert.Nil(t, dialer.SASLMechanism) | ||
} | ||
{ | ||
// SCRAM enabled with TLS | ||
c := NewConnection(false, false, "username", "password") | ||
dialer, err := c.Dialer(ctx) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, dialer.TLS) | ||
assert.NotNil(t, dialer.SASLMechanism) | ||
|
||
// w/o TLS | ||
c = NewConnection(false, true, "username", "password") | ||
dialer, err = c.Dialer(ctx) | ||
assert.NoError(t, err) | ||
assert.Nil(t, dialer.TLS) | ||
assert.NotNil(t, dialer.SASLMechanism) | ||
} | ||
{ | ||
// AWS IAM w/ TLS | ||
c := NewConnection(true, false, "", "") | ||
dialer, err := c.Dialer(ctx) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, dialer.TLS) | ||
assert.NotNil(t, dialer.SASLMechanism) | ||
|
||
// w/o TLS (still enabled because AWS doesn't support not having TLS) | ||
c = NewConnection(true, true, "", "") | ||
dialer, err = c.Dialer(ctx) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, dialer.TLS) | ||
assert.NotNil(t, dialer.SASLMechanism) | ||
} | ||
} |