-
Notifications
You must be signed in to change notification settings - Fork 66
fix(kafka topic): update regexp for topic name #663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,7 +13,7 @@ import ( | |||||
| ) | ||||||
|
|
||||||
| const ( | ||||||
| legalNameChars = "^[a-zA-Z0-9\\_\\-]+$" | ||||||
| legalNameChars = `[a-zA-Z0-9._-]` | ||||||
| maxNameLength = 249 | ||||||
| minPartitions = 1 | ||||||
| maxPartitions = 100 | ||||||
|
|
@@ -32,13 +32,17 @@ func ValidateName(val interface{}) error { | |||||
| return fmt.Errorf("topic name cannot exceed %v characters", maxNameLength) | ||||||
| } | ||||||
|
|
||||||
| if (name == ".") || (name == "..") { | ||||||
| return fmt.Errorf(`invalid topic name "%v"; can't be "." or ".."`, name) | ||||||
|
||||||
| return fmt.Errorf(`invalid topic name "%v"; can't be "." or ".."`, name) | |
| return errors.New(`topic name can not be "." or ".."`) |
This file contains hidden or 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,94 @@ | ||
| package topic | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestValidateName(t *testing.T) { | ||
|
|
||
| type args struct { | ||
| name string | ||
| } | ||
| tests := []struct { | ||
| name string | ||
| args args | ||
| wantErr bool | ||
| }{ | ||
| { | ||
| name: "Should throw error when exceeds 249 characters", | ||
| args: args{ | ||
| name: "verylongkafkanamef8d9dkf9dkc11dfsverylongkafkanamef8d9dkf9dkc11dfsverylongkafkanamef8d9dkf9dkc11dfsverylongkafkanamef8d9dkf9dkc11dfsverylongkafkanamef8d9dkf9dkc11dfsverylongkafkanamef8d9dkf9dkc11dfsverylongkafkanamef8d9dkf9dkc11dfsverylongkafkanamef8d9dkf9dkc11dfsverylongkafkanamef8d9dkf9dkc11dfsverylongkafkanamef8d9dkf9dkc11dfs", | ||
| }, | ||
| wantErr: true, | ||
| }, | ||
| { | ||
| name: "Should be valid when name is exactly 32 characters", | ||
| args: args{ | ||
| name: "verylongtopicnamef8d9dkf9dkc11dd", | ||
| }, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "Should be valid when containing dots", | ||
| args: args{ | ||
| name: "k.afk.a", | ||
| }, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "Should be invalid when containing special characters", | ||
| args: args{ | ||
| name: "r*maujj??", | ||
| }, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "Should be invalid when name is exactly 0 characters", | ||
| args: args{ | ||
| name: "", | ||
| }, | ||
| wantErr: true, | ||
| }, | ||
| { | ||
| name: "Should be valid when using hyphens", | ||
| args: args{ | ||
| name: "my-kafka-topic", | ||
| }, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "Should be valid when starts with number", | ||
| args: args{ | ||
| name: "1my-kafka-instance", | ||
| }, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "Should be invalid when only two dots", | ||
| args: args{ | ||
| name: "..", | ||
| }, | ||
| wantErr: true, | ||
| }, | ||
| { | ||
| name: "Should be invalid when only one dot", | ||
| args: args{ | ||
| name: ".", | ||
| }, | ||
| wantErr: true, | ||
| }, | ||
| { | ||
| name: "Should be valid when only three dots", | ||
| args: args{ | ||
| name: "...", | ||
| }, | ||
| wantErr: false, | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| // nolint | ||
| if err := ValidateName(tt.args.name); (err != nil) != tt.wantErr { | ||
| t.Errorf("ValidateName() error = %v, wantErr %v", err, tt.wantErr) | ||
| } | ||
| }) | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.