Skip to content

Commit

Permalink
settings: make .Override set the value origin
Browse files Browse the repository at this point in the history
Prior to this patch, setting overrides in tests did not have their
value origin set properly. This patch fixes it.

Release note: None
  • Loading branch information
knz committed Sep 25, 2023
1 parent e94de87 commit dc36146
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/settings/bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ var _ = (*BoolSetting).Default
//
// For testing usage only.
func (b *BoolSetting) Override(ctx context.Context, sv *Values, v bool) {
sv.setValueOrigin(ctx, b.slot, OriginExplicitlySet)
b.set(ctx, sv, v)
sv.setDefaultOverride(b.slot, v)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/settings/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func (d *DurationSetting) Validate(v time.Duration) error {
//
// For testing usage only.
func (d *DurationSetting) Override(ctx context.Context, sv *Values, v time.Duration) {
sv.setValueOrigin(ctx, d.slot, OriginExplicitlySet)
sv.setInt64(ctx, d.slot, int64(v))
sv.setDefaultOverride(d.slot, v)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/settings/float.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ var _ = (*FloatSetting).Default
//
// For testing usage only.
func (f *FloatSetting) Override(ctx context.Context, sv *Values, v float64) {
sv.setValueOrigin(ctx, f.slot, OriginExplicitlySet)
if err := f.set(ctx, sv, v); err != nil {
panic(err)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/settings/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func (i *IntSetting) Validate(v int64) error {
//
// For testing usage only.
func (i *IntSetting) Override(ctx context.Context, sv *Values, v int64) {
sv.setValueOrigin(ctx, i.slot, OriginExplicitlySet)
sv.setInt64(ctx, i.slot, v)
sv.setDefaultOverride(i.slot, v)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/settings/protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (s *ProtobufSetting) Validate(sv *Values, p protoutil.Message) error {

// Override sets the setting to the given value, assuming it passes validation.
func (s *ProtobufSetting) Override(ctx context.Context, sv *Values, p protoutil.Message) {
sv.setValueOrigin(ctx, s.slot, OriginExplicitlySet)
_ = s.set(ctx, sv, p)
sv.setDefaultOverride(s.slot, p)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/settings/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (s *StringSetting) Validate(sv *Values, v string) error {
// Override sets the setting to the given value, assuming
// it passes validation.
func (s *StringSetting) Override(ctx context.Context, sv *Values, v string) {
sv.setValueOrigin(ctx, s.slot, OriginExplicitlySet)
_ = s.set(ctx, sv, v)
sv.setDefaultOverride(s.slot, v)
}
Expand Down

0 comments on commit dc36146

Please sign in to comment.