From c0c66db69f330bfa1babbde493b1a6f49a2fd4ce Mon Sep 17 00:00:00 2001 From: ewezy Date: Mon, 19 Sep 2022 00:10:48 +0800 Subject: [PATCH] Remove duplicated error messages from EnsemblerStandardConfig custom validation checks --- api/turing/validation/validator.go | 4 ---- api/turing/validation/validator_test.go | 20 +++++--------------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/api/turing/validation/validator.go b/api/turing/validation/validator.go index 4a36045ce..45fcf07d7 100644 --- a/api/turing/validation/validator.go +++ b/api/turing/validation/validator.go @@ -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", "") } } diff --git a/api/turing/validation/validator_test.go b/api/turing/validation/validator_test.go index feaaa9602..51cf31b35 100644 --- a/api/turing/validation/validator_test.go +++ b/api/turing/validation/validator_test.go @@ -28,9 +28,7 @@ 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{ @@ -38,27 +36,21 @@ func TestValidateEnsemblerStandardConfig(t *testing.T) { 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{ @@ -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{