Skip to content

Commit

Permalink
Addressing comments final chapter
Browse files Browse the repository at this point in the history
  • Loading branch information
denisonbarbosa committed Aug 29, 2023
1 parent 89241af commit f8cbb0f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
5 changes: 4 additions & 1 deletion internal/brokers/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ func generateValidators(ctx context.Context, sessionID string, supportedUILayout
required: (required == "required"),
}
if supportedValues != "" {
validator.supportedValues = strings.Split(supportedValues, ",")
values := strings.Split(supportedValues, ",")
for _, value := range values {
validator.supportedValues = append(validator.supportedValues, strings.TrimSpace(value))
}
}
layoutValidator[key] = validator
}
Expand Down
11 changes: 8 additions & 3 deletions internal/brokers/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ var supportedLayouts = map[string]map[string]string{
"type": "misconfigured-layout",
"value": "required-but-misformatted",
},
"layout-with-spaces": {
"type": "layout-with-spaces",
"value": "required: value_type, other_value_type",
},
}

func TestNewBroker(t *testing.T) {
Expand Down Expand Up @@ -95,9 +99,10 @@ func TestGetAuthenticationModes(t *testing.T) {

wantErr bool
}{
"Get authentication modes and generate validators": {sessionID: "success", supportedUILayouts: []string{"required-value", "optional-value"}},
"Get authentication modes and ignores invalid UI layout": {sessionID: "success", supportedUILayouts: []string{"required-value", "missing-type"}},
"Get multiple authentication modes and generate validators": {sessionID: "GAM_multiple_modes", supportedUILayouts: []string{"required-value", "optional-value"}},
"Get authentication modes and generate validators": {sessionID: "success", supportedUILayouts: []string{"required-value", "optional-value"}},
"Get authentication modes and generate validator ignoring whitespaces": {sessionID: "success", supportedUILayouts: []string{"layout-with-spaces"}},
"Get authentication modes and ignores invalid UI layout": {sessionID: "success", supportedUILayouts: []string{"required-value", "missing-type"}},
"Get multiple authentication modes and generate validators": {sessionID: "GAM_multiple_modes", supportedUILayouts: []string{"required-value", "optional-value"}},

"Does not error out when no authentication modes are returned": {sessionID: "GAM_empty"},

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MODES:
[{"id":"mode1","label":"Mode 1"}]

VALIDATORS:
layout-with-spaces:
value: { required: true, supportedValues: [value_type other_value_type] }

0 comments on commit f8cbb0f

Please sign in to comment.