Skip to content

Commit ce950fc

Browse files
add NewValidationConfig() func, initiate DisabledValidators when not defined -- as discussed by @steiler
1 parent 830e789 commit ce950fc

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

pkg/config/validation.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
package config
22

3+
func NewValidationConfig() *Validation {
4+
return &Validation{
5+
DisabledValidators: &Validators{},
6+
DisableConcurrency: bool(false),
7+
}
8+
}
9+
310
type Validation struct {
411
DisabledValidators *Validators `yaml:"disabled-validators,omitempty" json:"disabled-validators,omitempty"`
512
DisableConcurrency bool `yaml:"disable-concurrency,omitempty" json:"disable-concurrency,omitempty"`
613
}
714

815
func (v *Validation) validateSetDefaults() error {
916
// no change required, all the bools default to false
17+
if v.DisabledValidators == nil {
18+
v.DisabledValidators = &Validators{}
19+
}
1020
return nil
1121
}
1222

23+
func (v *Validation) SetDisableConcurrency(b bool) {
24+
v.DisableConcurrency = b
25+
}
26+
1327
func (v *Validation) DeepCopy() *Validation {
1428
return &Validation{
1529
DisabledValidators: v.DisabledValidators.DeepCopy(),

pkg/datastore/tree_operation_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,15 @@ import (
3535

3636
var (
3737
// TypedValue Bool True and false
38-
TypedValueTrue = &sdcpb.TypedValue{Value: &sdcpb.TypedValue_BoolVal{BoolVal: true}}
39-
TypedValueFalse = &sdcpb.TypedValue{Value: &sdcpb.TypedValue_BoolVal{BoolVal: false}}
38+
TypedValueTrue = &sdcpb.TypedValue{Value: &sdcpb.TypedValue_BoolVal{BoolVal: true}}
39+
TypedValueFalse = &sdcpb.TypedValue{Value: &sdcpb.TypedValue_BoolVal{BoolVal: false}}
40+
validationConfig = config.NewValidationConfig()
4041
)
4142

43+
func init() {
44+
validationConfig.SetDisableConcurrency(true)
45+
}
46+
4247
func TestDatastore_populateTree(t *testing.T) {
4348
prio15 := int32(15)
4449
prio10 := int32(10)
@@ -818,7 +823,7 @@ func TestDatastore_populateTree(t *testing.T) {
818823
}
819824
fmt.Println(root.String())
820825

821-
validationResult := root.Validate(ctx, &config.Validation{DisableConcurrency: true})
826+
validationResult := root.Validate(ctx, validationConfig)
822827

823828
fmt.Printf("Validation Errors:\n%v\n", strings.Join(validationResult.ErrorsStr(), "\n"))
824829
fmt.Printf("Tree:%s\n", root.String())

pkg/datastore/tree_operation_validation_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
"github.com/openconfig/ygot/ygot"
2525
"github.com/sdcio/data-server/pkg/cache"
26-
"github.com/sdcio/data-server/pkg/config"
2726
schemaClient "github.com/sdcio/data-server/pkg/datastore/clients/schema"
2827
"github.com/sdcio/data-server/pkg/tree"
2928
json_importer "github.com/sdcio/data-server/pkg/tree/importer/json"
@@ -206,7 +205,7 @@ func TestDatastore_validateTree(t *testing.T) {
206205
t.Error(err)
207206
}
208207

209-
validationResult := root.Validate(ctx, &config.Validation{DisableConcurrency: true})
208+
validationResult := root.Validate(ctx, validationConfig)
210209

211210
t.Log(root.String())
212211

pkg/tree/entry_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ import (
1818
var (
1919
flagsNew *types.UpdateInsertFlags
2020
flagsExisting *types.UpdateInsertFlags
21-
validationConfig = &config.Validation{DisableConcurrency: true}
21+
validationConfig = config.NewValidationConfig()
2222
)
2323

2424
func init() {
2525
flagsNew = types.NewUpdateInsertFlags()
2626
flagsNew.SetNewFlag()
2727
flagsExisting = types.NewUpdateInsertFlags()
28+
validationConfig.SetDisableConcurrency(true)
2829
}
2930

3031
func Test_Entry(t *testing.T) {

pkg/tree/sharedEntryAttributes_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -714,11 +714,12 @@ func Test_sharedEntryAttributes_validateMandatory(t *testing.T) {
714714
t.Run(tt.name, func(t *testing.T) {
715715
root := tt.r(t)
716716

717-
dv := &config.Validators{}
718-
dv.DisableAll()
719-
dv.Mandatory = false
717+
validationConfig := config.NewValidationConfig()
718+
validationConfig.SetDisableConcurrency(true)
719+
validationConfig.DisabledValidators.DisableAll()
720+
validationConfig.DisabledValidators.Mandatory = false
720721

721-
validationResults := root.Validate(ctx, &config.Validation{DisableConcurrency: true, DisabledValidators: dv})
722+
validationResults := root.Validate(ctx, validationConfig)
722723

723724
results := []string{}
724725
for _, e := range validationResults {

0 commit comments

Comments
 (0)