-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add test for string.go * Add test for bytearray.go * Add test for errors.go * Add test for auth.go * Fix linter errors * Fix tests after rebasing with the logging/error-reporting PR merge * Remove the old ReportErrors function and test * Run Go tests in the test pipeline * Add more tests to auth_test.go after refactoring loggin and error-reporting * Refactor functions a bit until proper configuration validation is implemented * Fix assertions * Remove schema from function signatures (unused parameter) * Add tests for serde.go * Add tests for avro.go * Update deserializer function interface and add topic * Revamp avro.go to address multiple issues (fetching schemas, manual serialization, etc.) * Add more error codes and errors * Separate various Schema Registry functions * Simplify serialization functions * Explicitly pass srClient to SR functions * Export all functions * Fix tests to reflect changes * Fix linter error * Add more tests to SerializeAvro * Refactor serde and add serde registry * Add tests to serde_registry.go * Rename schema registry module * Remove duplicate code by using a function to get a connection to Kafka * Add tests to configuration.go * Update jsonschema.go with the latest changes to schema registry * Add tests to jsonschema.go * Add more test to avro.go * Add tests to jsonschema.go * Add tests to schema_registry.go * Create coverage report * Fix linter errors * Remove duplicate tests * Refactor configuration_test.go * Use constants * Fix typo * Ignore act * Add tests to topic.go * Run lensesio/fast-data-dev container for testing against Kafka * Use title case * Assert module instance and runtime * WIP: Add tests to producer.go (has issues with default function) * Rename kafkatest.go so it doesnt' get included in non test builds * Make test being able to go to vu code mode and other fixes * Create topic before producing messages * Check output metrics of produce function plus some fixes * Fix bugs and add some TODO comments * Add more tests to producer.go * Fix typos * Separate nil context from cancelled context error * Fix an edge case with setting offset together with groupID * Fix tests * Add tests to consumer.go (buggy) * Add more tests to consumer.go and fix others Co-authored-by: Mihail Stoykov <[email protected]>
- Loading branch information
Showing
39 changed files
with
1,770 additions
and
350 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 |
---|---|---|
|
@@ -15,3 +15,4 @@ | |
vendor/ | ||
k6 | ||
.idea | ||
act |
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,180 @@ | ||
package kafka | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
"time" | ||
|
||
"github.com/segmentio/kafka-go/sasl/plain" | ||
"github.com/segmentio/kafka-go/sasl/scram" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestUnmarshalCredentials(t *testing.T) { | ||
creds, err := UnmarshalCredentials(`{"username": "test", "password": "test", "algorithm": "plain", "clientCertPem": "client.pem", "clientKeyPem": "key.pem", "serverCaPem": "server.pem"}`) | ||
assert.Nil(t, err) | ||
assert.Equal(t, "test", creds.Username) | ||
assert.Equal(t, "test", creds.Password) | ||
assert.Equal(t, "plain", creds.Algorithm) | ||
assert.Equal(t, "client.pem", creds.ClientCertPem) | ||
assert.Equal(t, "key.pem", creds.ClientKeyPem) | ||
assert.Equal(t, "server.pem", creds.ServerCaPem) | ||
} | ||
|
||
func TestUnmarshalCredentialsFails(t *testing.T) { | ||
// This only fails on invalid JSON (apparently) | ||
creds, err := UnmarshalCredentials(`{"invalid": "invalid`) | ||
assert.Nil(t, creds) | ||
assert.NotNil(t, err) | ||
assert.Equal(t, err.Message, "Unable to unmarshal credentials") | ||
// This is the error we get from the json package wrapped inside the Xk6KafkaError | ||
assert.Equal(t, err.Unwrap().Error(), "unexpected end of JSON input") | ||
} | ||
|
||
func TestGetDialerFromCredsWithSASLPlain(t *testing.T) { | ||
creds := &Credentials{ | ||
Username: "test", | ||
Password: "test", | ||
Algorithm: Plain, | ||
} | ||
dialer, err := GetDialerFromCreds(creds) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, dialer) | ||
assert.Equal(t, 10*time.Second, dialer.Timeout) | ||
assert.Equal(t, true, dialer.DualStack) | ||
assert.Nil(t, dialer.TLS) | ||
assert.Equal(t, "PLAIN", dialer.SASLMechanism.Name()) | ||
assert.Equal(t, "test", dialer.SASLMechanism.(plain.Mechanism).Username) | ||
assert.Equal(t, "test", dialer.SASLMechanism.(plain.Mechanism).Password) | ||
} | ||
|
||
func TestGetDialerFromCredsWithSASLScram(t *testing.T) { | ||
creds := &Credentials{ | ||
Username: "test", | ||
Password: "test", | ||
Algorithm: SHA256, | ||
} | ||
dialer, err := GetDialerFromCreds(creds) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, dialer) | ||
assert.Equal(t, 10*time.Second, dialer.Timeout) | ||
assert.Equal(t, true, dialer.DualStack) | ||
assert.Nil(t, dialer.TLS) | ||
assert.Equal(t, scram.SHA256.Name(), dialer.SASLMechanism.Name()) | ||
} | ||
|
||
func TestGetDialerFromCredsFails(t *testing.T) { | ||
creds := &Credentials{ | ||
Username: "https://www.exa\t\r\n", | ||
Password: "test", | ||
Algorithm: "sha256", | ||
} | ||
dialer, wrappedError := GetDialerFromCreds(creds) | ||
assert.Equal(t, wrappedError.Message, "Unable to create SCRAM mechanism") | ||
// This is a stringprep (RFC3454) error wrapped inside the Xk6KafkaError | ||
assert.Equal(t, wrappedError.Unwrap().Error(), "Error SASLprepping username 'https://www.exa\t\r\n': prohibited character (rune: '\\u0009')") | ||
assert.Nil(t, dialer) | ||
} | ||
|
||
func TestGetDialerFromAuth(t *testing.T) { | ||
auth := `{"username": "test", "password": "test", "algorithm": "plain", "clientCertPem": "client.pem", "clientKeyPem": "key.pem", "serverCaPem": "server.pem"}` | ||
dialer, err := GetDialerFromAuth(auth) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, dialer) | ||
assert.Equal(t, 10*time.Second, dialer.Timeout) | ||
assert.Equal(t, true, dialer.DualStack) | ||
assert.Nil(t, dialer.TLS) | ||
assert.Equal(t, "PLAIN", dialer.SASLMechanism.Name()) | ||
assert.Equal(t, "test", dialer.SASLMechanism.(plain.Mechanism).Username) | ||
assert.Equal(t, "test", dialer.SASLMechanism.(plain.Mechanism).Password) | ||
} | ||
|
||
func TestGetDialerFromAuthNoAuthString(t *testing.T) { | ||
dialer, err := GetDialerFromAuth("") | ||
assert.Nil(t, err) | ||
assert.NotNil(t, dialer) | ||
assert.Equal(t, 10*time.Second, dialer.Timeout) | ||
assert.Equal(t, false, dialer.DualStack) | ||
assert.Nil(t, dialer.TLS) | ||
} | ||
|
||
func TestFileExists(t *testing.T) { | ||
assert.True(t, FileExists("auth_test.go")) | ||
assert.False(t, FileExists("test.go.not")) | ||
} | ||
|
||
type SimpleTLSConfig struct { | ||
creds *Credentials | ||
err *Xk6KafkaError | ||
} | ||
|
||
func TestTlsConfig(t *testing.T) { | ||
creds := &Credentials{ | ||
ClientCertPem: "fixtures/client.cer", | ||
ClientKeyPem: "fixtures/client.pem", | ||
ServerCaPem: "fixtures/caroot.cer", | ||
} | ||
tlsConfig, err := TLSConfig(creds) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, tlsConfig) | ||
} | ||
|
||
func TestTlsConfigFails(t *testing.T) { | ||
creds := []*SimpleTLSConfig{ | ||
{ | ||
creds: &Credentials{}, | ||
err: &Xk6KafkaError{ | ||
Code: fileNotFound, | ||
Message: "Client certificate file not found.", | ||
}, | ||
}, | ||
{ | ||
creds: &Credentials{ | ||
ClientCertPem: "fixtures/client.cer", | ||
}, | ||
err: &Xk6KafkaError{ | ||
Code: fileNotFound, | ||
Message: "Client key file not found.", | ||
}, | ||
}, | ||
{ | ||
creds: &Credentials{ | ||
ClientCertPem: "fixtures/client.cer", | ||
ClientKeyPem: "fixtures/client.pem", | ||
}, | ||
err: &Xk6KafkaError{ | ||
Code: fileNotFound, | ||
Message: "CA certificate file not found.", | ||
}, | ||
}, | ||
{ | ||
creds: &Credentials{ | ||
ClientCertPem: "fixtures/invalid-client.cer", | ||
ClientKeyPem: "fixtures/invalid-client.pem", | ||
}, | ||
err: &Xk6KafkaError{ | ||
Code: failedLoadX509KeyPair, | ||
Message: "Error creating x509 keypair from client cert file \"fixtures/invalid-client.cer\" and client key file \"fixtures/invalid-client.pem\"", | ||
OriginalError: errors.New("tls: failed to find any PEM data in certificate input"), | ||
}, | ||
}, | ||
{ | ||
creds: &Credentials{ | ||
ClientCertPem: "fixtures/client.cer", | ||
ClientKeyPem: "fixtures/client.pem", | ||
ServerCaPem: "fixtures/invalid-caroot.cer", | ||
}, | ||
err: &Xk6KafkaError{ | ||
Code: failedAppendCaCertFile, | ||
Message: "Error appending CA certificate file \"fixtures/invalid-caroot.cer\"", | ||
}, | ||
}, | ||
} | ||
|
||
for _, c := range creds { | ||
tlsConfig, err := TLSConfig(c.creds) | ||
assert.NotNil(t, err) | ||
assert.Equal(t, c.err, err) | ||
assert.Nil(t, tlsConfig) | ||
} | ||
} |
Oops, something went wrong.