Skip to content

Commit

Permalink
Remove duplicated error messages from EnsemblerStandardConfig custom …
Browse files Browse the repository at this point in the history
…validation checks
  • Loading branch information
deadlycoconuts committed Sep 18, 2022
1 parent 0aee805 commit d397131
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
4 changes: 0 additions & 4 deletions api/turing/validation/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,11 @@ func validateEnsemblerStandardConfig(sl validator.StructLevel) {
if (len(ensemblerStandardConfig.ExperimentMappings) == 0) && ensemblerStandardConfig.RouteNamePath == "" {
sl.ReportError(ensemblerStandardConfig.ExperimentMappings,
"ExperimentMappings", "ExperimentMappings", "required when RouteNamePath is not set", "")
sl.ReportError(ensemblerStandardConfig.RouteNamePath,
"RouteNamePath", "RouteNamePath", "required when ExperimentMappings is not set", "")
}
// Verify that the ExperimentMappings and RouteNamePath are not both set at the same time
if len(ensemblerStandardConfig.ExperimentMappings) > 0 && ensemblerStandardConfig.RouteNamePath != "" {
sl.ReportError(ensemblerStandardConfig.ExperimentMappings,
"ExperimentMappings", "ExperimentMappings", "excluded when RouteNamePath is set", "")
sl.ReportError(ensemblerStandardConfig.RouteNamePath,
"RouteNamePath", "RouteNamePath", "excluded when ExperimentMappings is set", "")
}
}

Expand Down
20 changes: 5 additions & 15 deletions api/turing/validation/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,29 @@ func TestValidateEnsemblerStandardConfig(t *testing.T) {
"failure | experiment mappings and route name path undefined": {
input: models.EnsemblerStandardConfig{},
err: "Key: 'EnsemblerStandardConfig.ExperimentMappings' Error:Field validation for 'ExperimentMappings' " +
"failed on the 'required when RouteNamePath is not set' tag\n" +
"Key: 'EnsemblerStandardConfig.RouteNamePath' Error:Field validation for 'RouteNamePath' failed on " +
"the 'required when ExperimentMappings is not set' tag",
"failed on the 'required when RouteNamePath is not set' tag",
},
"failure | experiment mappings and route name path empty": {
input: models.EnsemblerStandardConfig{
ExperimentMappings: []models.ExperimentMapping{},
RouteNamePath: "",
},
err: "Key: 'EnsemblerStandardConfig.ExperimentMappings' Error:Field validation for 'ExperimentMappings' " +
"failed on the 'required when RouteNamePath is not set' tag\n" +
"Key: 'EnsemblerStandardConfig.RouteNamePath' Error:Field validation for 'RouteNamePath' failed on " +
"the 'required when ExperimentMappings is not set' tag",
"failed on the 'required when RouteNamePath is not set' tag",
},
"failure | experiment mappings empty and route name path undefined": {
input: models.EnsemblerStandardConfig{
ExperimentMappings: []models.ExperimentMapping{},
},
err: "Key: 'EnsemblerStandardConfig.ExperimentMappings' Error:Field validation for 'ExperimentMappings' " +
"failed on the 'required when RouteNamePath is not set' tag\n" +
"Key: 'EnsemblerStandardConfig.RouteNamePath' Error:Field validation for 'RouteNamePath' failed on " +
"the 'required when ExperimentMappings is not set' tag",
"failed on the 'required when RouteNamePath is not set' tag",
},
"failure | experiment mappings undefined and route name path empty": {
input: models.EnsemblerStandardConfig{
RouteNamePath: "",
},
err: "Key: 'EnsemblerStandardConfig.ExperimentMappings' Error:Field validation for 'ExperimentMappings' " +
"failed on the 'required when RouteNamePath is not set' tag\n" +
"Key: 'EnsemblerStandardConfig.RouteNamePath' Error:Field validation for 'RouteNamePath' failed on " +
"the 'required when ExperimentMappings is not set' tag",
"failed on the 'required when RouteNamePath is not set' tag",
},
"failure | experiment mappings and route name path defined": {
input: models.EnsemblerStandardConfig{
Expand All @@ -72,9 +64,7 @@ func TestValidateEnsemblerStandardConfig(t *testing.T) {
RouteNamePath: "route-1",
},
err: "Key: 'EnsemblerStandardConfig.ExperimentMappings' Error:Field validation for 'ExperimentMappings' " +
"failed on the 'excluded when RouteNamePath is set' tag\n" +
"Key: 'EnsemblerStandardConfig.RouteNamePath' Error:Field validation for 'RouteNamePath' " +
"failed on the 'excluded when ExperimentMappings is set' tag",
"failed on the 'excluded when RouteNamePath is set' tag",
},
"success | only experiment mappings defined": {
input: models.EnsemblerStandardConfig{
Expand Down

0 comments on commit d397131

Please sign in to comment.