forked from segmentio/kafka-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add methods for parsing and stringifying acl related resources (segme…
…ntio#1218) * Add methods for marshalling/unmarshalling ACLOperationType and ACLPermissionType * Fix unknown types * Implement ResourceType * make function ordering more consistent * add patterntype and resourcetype * make capitalization consistent * add comment and test around ResourceTypeBroker and ResourceTypeCluster having same value
- Loading branch information
1 parent
f2d9e08
commit c6378c3
Showing
4 changed files
with
272 additions
and
0 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
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,58 @@ | ||
package kafka | ||
|
||
import "testing" | ||
|
||
func TestResourceTypeMarshal(t *testing.T) { | ||
for i := ResourceTypeUnknown; i <= ResourceTypeDelegationToken; i++ { | ||
text, err := i.MarshalText() | ||
if err != nil { | ||
t.Errorf("couldn't marshal %d to text: %s", i, err) | ||
} | ||
var got ResourceType | ||
err = got.UnmarshalText(text) | ||
if err != nil { | ||
t.Errorf("couldn't unmarshal %s to ResourceType: %s", text, err) | ||
} | ||
if got != i { | ||
t.Errorf("got %d, want %d", got, i) | ||
} | ||
} | ||
} | ||
|
||
// Verify that the text version of ResourceTypeBroker is "Cluster". | ||
// This is added since ResourceTypeBroker and ResourceTypeCluster | ||
// have the same value. | ||
func TestResourceTypeBroker(t *testing.T) { | ||
text, err := ResourceTypeBroker.MarshalText() | ||
if err != nil { | ||
t.Errorf("couldn't marshal %d to text: %s", ResourceTypeBroker, err) | ||
} | ||
if string(text) != "Cluster" { | ||
t.Errorf("got %s, want %s", string(text), "Cluster") | ||
} | ||
var got ResourceType | ||
err = got.UnmarshalText(text) | ||
if err != nil { | ||
t.Errorf("couldn't unmarshal %s to ResourceType: %s", text, err) | ||
} | ||
if got != ResourceTypeBroker { | ||
t.Errorf("got %d, want %d", got, ResourceTypeBroker) | ||
} | ||
} | ||
|
||
func TestPatternTypeMarshal(t *testing.T) { | ||
for i := PatternTypeUnknown; i <= PatternTypePrefixed; i++ { | ||
text, err := i.MarshalText() | ||
if err != nil { | ||
t.Errorf("couldn't marshal %d to text: %s", i, err) | ||
} | ||
var got PatternType | ||
err = got.UnmarshalText(text) | ||
if err != nil { | ||
t.Errorf("couldn't unmarshal %s to PatternType: %s", text, err) | ||
} | ||
if got != i { | ||
t.Errorf("got %d, want %d", got, i) | ||
} | ||
} | ||
} |