-
-
Notifications
You must be signed in to change notification settings - Fork 196
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
kadm: add func to decode AuthorizedOperations #870
Merged
+162
−0
Merged
Changes from 1 commit
Commits
Show all changes
2 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 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,109 @@ | ||
package kadm | ||
|
||
import ( | ||
"math" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/twmb/franz-go/pkg/kmsg" | ||
) | ||
|
||
func TestDecodeACLOperations(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
bitfield int32 | ||
expected []kmsg.ACLOperation | ||
}{ | ||
{ | ||
name: "Example 264", | ||
bitfield: 264, | ||
expected: []kmsg.ACLOperation{ | ||
kmsg.ACLOperationRead, | ||
kmsg.ACLOperationDescribe, | ||
}, | ||
}, | ||
{ | ||
name: "Example 3400", | ||
bitfield: 3400, | ||
expected: []kmsg.ACLOperation{ | ||
kmsg.ACLOperationRead, | ||
kmsg.ACLOperationDescribe, | ||
kmsg.ACLOperationAlterConfigs, | ||
kmsg.ACLOperationDescribeConfigs, | ||
kmsg.ACLOperationDelete, | ||
}, | ||
}, | ||
{ | ||
name: "Example 3968", | ||
bitfield: 3968, | ||
expected: []kmsg.ACLOperation{ | ||
kmsg.ACLOperationAlter, | ||
kmsg.ACLOperationAlterConfigs, | ||
kmsg.ACLOperationClusterAction, | ||
kmsg.ACLOperationDescribe, | ||
kmsg.ACLOperationDescribeConfigs, | ||
}, | ||
}, | ||
{ | ||
name: "Example 4000", | ||
bitfield: 4000, | ||
expected: []kmsg.ACLOperation{ | ||
kmsg.ACLOperationAlter, | ||
kmsg.ACLOperationAlterConfigs, | ||
kmsg.ACLOperationClusterAction, | ||
kmsg.ACLOperationCreate, | ||
kmsg.ACLOperationDescribe, | ||
kmsg.ACLOperationDescribeConfigs, | ||
}, | ||
}, | ||
{ | ||
name: "All Operations", | ||
bitfield: math.MaxInt32, // All bits set | ||
expected: []kmsg.ACLOperation{ | ||
kmsg.ACLOperationRead, | ||
kmsg.ACLOperationWrite, | ||
kmsg.ACLOperationCreate, | ||
kmsg.ACLOperationDelete, | ||
kmsg.ACLOperationAlter, | ||
kmsg.ACLOperationDescribe, | ||
kmsg.ACLOperationClusterAction, | ||
kmsg.ACLOperationDescribeConfigs, | ||
kmsg.ACLOperationAlterConfigs, | ||
kmsg.ACLOperationIdempotentWrite, | ||
kmsg.ACLOperationCreateTokens, | ||
kmsg.ACLOperationDescribeTokens, | ||
}, | ||
}, | ||
{ | ||
name: "Invalid Operations Excluded", | ||
bitfield: 1<<15 | 1<<16, // Bits beyond known operations | ||
expected: []kmsg.ACLOperation{}, | ||
}, | ||
{ | ||
name: "Empty Bitfield", | ||
bitfield: math.MinInt32, | ||
expected: []kmsg.ACLOperation{}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result := DecodeACLOperations(tt.bitfield) | ||
|
||
// Compare slices ignoring order | ||
expectedMap := make(map[kmsg.ACLOperation]bool) | ||
for _, op := range tt.expected { | ||
expectedMap[op] = true | ||
} | ||
|
||
resultMap := make(map[kmsg.ACLOperation]bool) | ||
for _, op := range result { | ||
resultMap[op] = true | ||
} | ||
|
||
if !reflect.DeepEqual(expectedMap, resultMap) { | ||
t.Errorf("DecodeACLOperations(%d) = %v, expected %v", tt.bitfield, result, tt.expected) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.
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.
Can this return an ACLOperation, from this package? It's a type alias, so I think only this line needs to change.
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.
I plan to have a follow up PR that adds authorized operations fields to this package.
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.
Done :)