Skip to content

Commit

Permalink
fix: make sure with testing experiment config is always a struct
Browse files Browse the repository at this point in the history
  • Loading branch information
bassosimone committed Jun 27, 2024
1 parent d1f243d commit 21c62db
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 0 additions & 1 deletion internal/registry/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ func (b *Factory) SetOptionsJSON(value json.RawMessage) error {

// otherwise unmarshal into the configuration, which we assume
// to be a pointer to a structure.
// TODO(bassosimone): make sure with testing that b.config is always a pointer.
return json.Unmarshal(value, b.config)
}

Expand Down
18 changes: 18 additions & 0 deletions internal/registry/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"math"
"os"
"reflect"
"testing"

"github.com/apex/log"
Expand Down Expand Up @@ -964,3 +965,20 @@ func TestFactoryNewTargetLoader(t *testing.T) {
}
})
}

func TestExperimentConfigIsAlwaysAPointerToStruct(t *testing.T) {
for name, ffunc := range AllExperiments {
t.Run(name, func(t *testing.T) {
factory := ffunc()
config := factory.config
ctype := reflect.TypeOf(config)
if ctype.Kind() != reflect.Pointer {
t.Fatal("expected a pointer")
}
ctype = ctype.Elem()
if ctype.Kind() != reflect.Struct {
t.Fatal("expected a struct")
}
})
}
}
4 changes: 2 additions & 2 deletions internal/registry/webconnectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ func init() {
return &Factory{
build: func(config any) model.ExperimentMeasurer {
return webconnectivity.NewExperimentMeasurer(
config.(webconnectivity.Config),
*config.(*webconnectivity.Config),
)
},
canonicalName: canonicalName,
config: webconnectivity.Config{},
config: &webconnectivity.Config{},
enabledByDefault: true,
interruptible: false,
inputPolicy: model.InputOrQueryBackend,
Expand Down

0 comments on commit 21c62db

Please sign in to comment.