mirror of
https://github.com/amir20/dozzle.git
synced 2025-12-21 21:33:18 +01:00
feat: support for dozzle_* roles (#4153)
This commit is contained in:
@@ -43,15 +43,15 @@ func ParseRole(input string) Role {
|
|||||||
for _, r := range parts {
|
for _, r := range parts {
|
||||||
role := strings.TrimSpace(strings.ToLower(r))
|
role := strings.TrimSpace(strings.ToLower(r))
|
||||||
switch role {
|
switch role {
|
||||||
case "shell":
|
case "shell", "dozzle_shell":
|
||||||
roles |= Shell
|
roles |= Shell
|
||||||
case "actions":
|
case "actions", "dozzle_actions":
|
||||||
roles |= Actions
|
roles |= Actions
|
||||||
case "download":
|
case "download", "dozzle_download":
|
||||||
roles |= Download
|
roles |= Download
|
||||||
case "none":
|
case "none", "dozzle_none":
|
||||||
return None
|
return None
|
||||||
case "all":
|
case "all", "dozzle_all":
|
||||||
return All
|
return All
|
||||||
default:
|
default:
|
||||||
log.Debug().Str("role", role).Msg("invalid role")
|
log.Debug().Str("role", role).Msg("invalid role")
|
||||||
|
|||||||
@@ -17,26 +17,42 @@ func TestParseRole(t *testing.T) {
|
|||||||
{"None role", "none", None},
|
{"None role", "none", None},
|
||||||
{"All role", "all", All},
|
{"All role", "all", All},
|
||||||
|
|
||||||
|
// Single dozzle_ prefixed role tests
|
||||||
|
{"Single dozzle_shell role", "dozzle_shell", Shell},
|
||||||
|
{"Single dozzle_actions role", "dozzle_actions", Actions},
|
||||||
|
{"Single dozzle_download role", "dozzle_download", Download},
|
||||||
|
{"Dozzle_none role", "dozzle_none", None},
|
||||||
|
{"Dozzle_all role", "dozzle_all", All},
|
||||||
|
|
||||||
// Case insensitive tests
|
// Case insensitive tests
|
||||||
{"Shell uppercase", "SHELL", Shell},
|
{"Shell uppercase", "SHELL", Shell},
|
||||||
{"Actions mixed case", "AcTiOnS", Actions},
|
{"Actions mixed case", "AcTiOnS", Actions},
|
||||||
{"Download with spaces", " download ", Download},
|
{"Download with spaces", " download ", Download},
|
||||||
|
{"Dozzle_shell uppercase", "DOZZLE_SHELL", Shell},
|
||||||
|
{"Dozzle_actions mixed case", "DoZzLe_AcTiOnS", Actions},
|
||||||
|
{"Dozzle_download with spaces", " dozzle_download ", Download},
|
||||||
|
|
||||||
// Multiple roles with comma separator
|
// Multiple roles with comma separator
|
||||||
{"Shell and actions", "shell,actions", Shell | Actions},
|
{"Shell and actions", "shell,actions", Shell | Actions},
|
||||||
{"All three roles", "shell,actions,download", Shell | Actions | Download},
|
{"All three roles", "shell,actions,download", Shell | Actions | Download},
|
||||||
{"Roles with spaces", "shell , actions , download", Shell | Actions | Download},
|
{"Roles with spaces", "shell , actions , download", Shell | Actions | Download},
|
||||||
|
{"Dozzle roles with comma", "dozzle_shell,dozzle_actions", Shell | Actions},
|
||||||
|
{"Mixed dozzle and regular", "shell,dozzle_actions,download", Shell | Actions | Download},
|
||||||
|
|
||||||
// Multiple roles with pipe separator
|
// Multiple roles with pipe separator
|
||||||
{"Shell and actions with pipe", "shell|actions", Shell | Actions},
|
{"Shell and actions with pipe", "shell|actions", Shell | Actions},
|
||||||
{"All three with pipe", "shell|actions|download", Shell | Actions | Download},
|
{"All three with pipe", "shell|actions|download", Shell | Actions | Download},
|
||||||
{"Mixed separators", "shell,actions|download", Shell | Actions | Download},
|
{"Mixed separators", "shell,actions|download", Shell | Actions | Download},
|
||||||
|
{"Dozzle roles with pipe", "dozzle_shell|dozzle_actions", Shell | Actions},
|
||||||
|
|
||||||
// JSON format tests
|
// JSON format tests
|
||||||
{"JSON single role", `["shell"]`, Shell},
|
{"JSON single role", `["shell"]`, Shell},
|
||||||
{"JSON multiple roles", `["shell", "actions"]`, Shell | Actions},
|
{"JSON multiple roles", `["shell", "actions"]`, Shell | Actions},
|
||||||
{"JSON all roles", `["shell", "actions", "download"]`, Shell | Actions | Download},
|
{"JSON all roles", `["shell", "actions", "download"]`, Shell | Actions | Download},
|
||||||
{"JSON with spaces", ` ["shell", "actions"] `, Shell | Actions},
|
{"JSON with spaces", ` ["shell", "actions"] `, Shell | Actions},
|
||||||
|
{"JSON single dozzle role", `["dozzle_shell"]`, Shell},
|
||||||
|
{"JSON multiple dozzle roles", `["dozzle_shell", "dozzle_actions"]`, Shell | Actions},
|
||||||
|
{"JSON mixed dozzle and regular", `["shell", "dozzle_actions"]`, Shell | Actions},
|
||||||
|
|
||||||
// Edge cases
|
// Edge cases
|
||||||
{"Empty string", "", None},
|
{"Empty string", "", None},
|
||||||
@@ -45,6 +61,8 @@ func TestParseRole(t *testing.T) {
|
|||||||
{"Mixed valid and invalid", "shell,invalid,actions", Shell | Actions},
|
{"Mixed valid and invalid", "shell,invalid,actions", Shell | Actions},
|
||||||
{"None overrides others", "shell,none,actions", None},
|
{"None overrides others", "shell,none,actions", None},
|
||||||
{"All overrides others", "shell,all,actions", All},
|
{"All overrides others", "shell,all,actions", All},
|
||||||
|
{"Dozzle_none overrides others", "dozzle_shell,dozzle_none,dozzle_actions", None},
|
||||||
|
{"Dozzle_all overrides others", "dozzle_shell,dozzle_all,dozzle_actions", All},
|
||||||
|
|
||||||
// Invalid JSON
|
// Invalid JSON
|
||||||
{"Invalid JSON format", `["shell"`, None},
|
{"Invalid JSON format", `["shell"`, None},
|
||||||
|
|||||||
Reference in New Issue
Block a user