Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions decoders/yaml/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ func TestShallowlyNestedYAML(t *testing.T) {
}`

myConfig := &testConfig{}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()
d, err := dials.Config(
ctx,
myConfig,
Expand Down Expand Up @@ -127,8 +126,7 @@ func TestEmbedded(t *testing.T) {
}`

myConfig := &testConfig{}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()
d, err := dials.Config(
ctx,
myConfig,
Expand Down Expand Up @@ -235,8 +233,7 @@ func TestAnonymousNestedYAML(t *testing.T) {
}`

myConfig := &testConfig{}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()
d, err := dials.Config(
ctx,
myConfig,
Expand Down
5 changes: 2 additions & 3 deletions dials.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (p Params[T]) Config(ctx context.Context, t *T, sources ...Source) (*Dials[
watcherChan := make(chan watchStatusUpdate)
computed := make([]sourceValue, len(sources))

typeOfT := reflect.TypeOf(t)
typeOfT := reflect.TypeFor[*T]()
if typeOfT.Kind() != reflect.Pointer {
return nil, fmt.Errorf("config type %T is not a pointer", t)
}
Expand Down Expand Up @@ -533,7 +533,6 @@ func (d *Dials[T]) updateSourceValue(
}

func (d *Dials[T]) markSourceDone(
ctx context.Context,
sourceValues []sourceValue,
watchTab *watcherDone,
) bool {
Expand Down Expand Up @@ -729,7 +728,7 @@ func (d *Dials[T]) monitor(
})
}
case *watcherDone:
if !d.markSourceDone(ctx, sourceValues, v) {
if !d.markSourceDone(sourceValues, v) {
// if there are no watching sources, just exit.
d.sourceVals.Store(&sourceValues)
return
Expand Down
33 changes: 11 additions & 22 deletions dials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ func TestConfigWithoutVerifier(t *testing.T) {
}

// setup a cancelable context so the monitor goroutine gets shutdown.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

w := fakeWatchingSource{fakeSource: fakeSource{outVal: foozleConfig}}
d, err := Config(ctx, &base, &fakeSource{outVal: emptyConf}, &w)
Expand Down Expand Up @@ -150,8 +149,7 @@ func TestConfigWithFailVerifier(t *testing.T) {
}

// setup a cancelable context so the monitor goroutine gets shutdown.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

w := fakeWatchingSource{fakeSource: fakeSource{outVal: foozleConfig}}
_, err := Config(ctx, &base, &fakeSource{outVal: emptyConf}, &w)
Expand Down Expand Up @@ -184,8 +182,7 @@ func TestConfigWithSkippedInitialVerify(t *testing.T) {
}

// setup a cancelable context so the monitor goroutine gets shutdown.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

w := fakeWatchingSource{fakeSource: fakeSource{outVal: foozleConfig}}
_, err := Params[testConfig]{
Expand Down Expand Up @@ -218,8 +215,7 @@ func TestConfigWithDelayInitialVerifyFailNoWatch(t *testing.T) {
}

// setup a cancelable context so the monitor goroutine gets shutdown.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

s := fakeSource{outVal: foozleConfig}
d, err := Params[testConfig]{
Expand Down Expand Up @@ -257,8 +253,7 @@ func TestConfigWithDelayInitialVerifyFailWatchNoGlobalCBSuppress(t *testing.T) {
}

// setup a cancelable context so the monitor goroutine gets shutdown.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

globalCfgCh := make(chan *configurableVerifier, 1)
w := fakeWatchingSource{fakeSource: fakeSource{outVal: foozleConfig}}
Expand Down Expand Up @@ -313,8 +308,7 @@ func TestConfigWithDelayInitialVerifyFailWatchlobalCBSuppress(t *testing.T) {
}

// setup a cancelable context so the monitor goroutine gets shutdown.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

errCBCh := make(chan error, 1)
expglobalCBCall := make(chan struct{})
Expand Down Expand Up @@ -426,8 +420,7 @@ func TestConfigWithSuccessVerifier(t *testing.T) {
}

// setup a cancelable context so the monitor goroutine gets shutdown.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

w := fakeWatchingSource{fakeSource: fakeSource{outVal: foozleConfig}}
d, err := Config(ctx, &base, &fakeSource{outVal: emptyConf}, &w)
Expand Down Expand Up @@ -502,8 +495,7 @@ func TestConfigWithConfigureVerifier(t *testing.T) {
}

// setup a cancelable context so the monitor goroutine gets shutdown.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

errCh := make(chan error, 1)
params := Params[configurableVerifier]{
Expand Down Expand Up @@ -588,8 +580,7 @@ func TestWatcherWithDoneAndErrorCallback(t *testing.T) {
}

// setup a cancelable context so the monitor goroutine gets shutdown.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

reportedErrCh := make(chan error)
p := Params[testConfig]{
Expand Down Expand Up @@ -673,8 +664,7 @@ func TestConfigWithNewConfigCallbacks(t *testing.T) {
}

// setup a cancelable context so the monitor goroutine gets shutdown.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

oldConf := make(chan *testConfig, 1)
newConf := make(chan *testConfig)
Expand Down Expand Up @@ -792,8 +782,7 @@ func TestConfigWithNewConfigCallbacksSaturate(t *testing.T) {
}

// setup a cancelable context so the monitor goroutine gets shutdown.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

// give oldConf a large capacity (we don't want to block on both)
oldConf := make(chan *testConfig, 128)
Expand Down
18 changes: 6 additions & 12 deletions ez/ez_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ func (c *config) ConfigPath() (string, bool) {
// TestYAMLConfigEnvFlag cannot run concurrently with other tests because of
// environment manipulation.
func TestYAMLConfigEnvFlagWithValidConfig(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

t.Setenv("CONFIGPATH", "../testhelper/testconfig.yaml")

Expand All @@ -58,8 +57,7 @@ func TestYAMLConfigEnvFlagWithValidConfig(t *testing.T) {
}

func TestYAMLConfigEnvFlagWithValidConfigAndAlias(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

t.Setenv("ALTCONFIGPATH", "../testhelper/testconfig.yaml")

Expand Down Expand Up @@ -94,8 +92,7 @@ func (bc *beatlesConfig) ConfigPath() (string, bool) {
}

func TestYAMLConfigEnvFlagWithFileKeyNaming(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

c := &beatlesConfig{YAMLPath: "../testhelper/testconfig.yaml"}
view, dialsErr := YAMLConfigEnvFlag(ctx, c, Params[beatlesConfig]{
Expand Down Expand Up @@ -147,8 +144,7 @@ func (c *validatingConfig) Verify() error {
}

func TestYAMLConfigEnvFlagWithValidatingConfig(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

tmpFile, tmpErr := os.CreateTemp(t.TempDir(), "*")
require.NoError(t, tmpErr)
Expand All @@ -164,8 +160,7 @@ func TestYAMLConfigEnvFlagWithValidatingConfig(t *testing.T) {
}

func TestYAMLConfigEnvFlagWithValidatingConfigInitiallyValid(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

tmpDir := t.TempDir()
path := filepath.Join(tmpDir, "fim1.yaml")
Expand Down Expand Up @@ -204,8 +199,7 @@ func TestYAMLConfigEnvFlagWithValidatingConfigInitiallyValid(t *testing.T) {
}

func TestJSONConfigEnvFlagWithNewConfigCallback(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

tmpDir := t.TempDir()
path := filepath.Join(tmpDir, "fim1.json")
Expand Down
6 changes: 3 additions & 3 deletions helper/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func TestOnImplements(t *testing.T) {
textUnmarshalerType := reflect.TypeOf((*encoding.TextUnmarshaler)(nil)).Elem()
textUnmarshalerType := reflect.TypeFor[encoding.TextUnmarshaler]()

for testName, itbl := range map[string]struct {
seed func() any
Expand All @@ -25,7 +25,7 @@ func TestOnImplements(t *testing.T) {
assert.Equal(t, "10.1.1.1", inputIP.String())

newType := v.Type()
assert.Equal(t, reflect.PointerTo(reflect.TypeOf(net.IP{})), newType)
assert.Equal(t, reflect.PointerTo(reflect.TypeFor[net.IP]()), newType)

outputIP, ok := v.Interface().(*net.IP)
assert.True(t, ok)
Expand All @@ -51,7 +51,7 @@ func TestOnImplements(t *testing.T) {
assert.Equal(t, "10.1.1.1", inputIP.String())

newType := v.Type()
assert.Equal(t, reflect.PointerTo(reflect.TypeOf(net.IP{})), newType)
assert.Equal(t, reflect.PointerTo(reflect.TypeFor[net.IP]()), newType)

outputIP, ok := v.Interface().(*net.IP)
assert.True(t, ok)
Expand Down
1 change: 0 additions & 1 deletion parse/complex.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !go1.15
// +build !go1.15

package parse

Expand Down
1 change: 0 additions & 1 deletion parse/complex_go115.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build go1.15
// +build go1.15

package parse

Expand Down
1 change: 0 additions & 1 deletion parse/complex_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !go1.15
// +build !go1.15

package parse

Expand Down
2 changes: 1 addition & 1 deletion parse/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestParseMapForStringStringMaps(t *testing.T) {
} {
tbl := itbl
t.Run(tbl.name, func(t *testing.T) {
ss, err := Map(tbl.input, reflect.TypeOf(map[string]string{}))
ss, err := Map(tbl.input, reflect.TypeFor[map[string]string]())
if tbl.expectedErr != nil {
assert.EqualError(t, err, tbl.expectedErr.Error())
return
Expand Down
2 changes: 1 addition & 1 deletion parse/number.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"
)

var durationType = reflect.TypeOf(time.Duration(0))
var durationType = reflect.TypeFor[time.Duration]()

func parseNumber(strVal string, numberType reflect.Type) (reflect.Value, error) {
var castVal reflect.Value
Expand Down
2 changes: 1 addition & 1 deletion parse/parse_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func String(str string, t reflect.Type) (reflect.Value, error) {

case reflect.Map:
switch t {
case reflect.TypeOf(map[string][]string{}):
case reflect.TypeFor[map[string][]string]():
converted, err := StringStringSliceMap(str)
if err != nil {
return reflect.Value{}, err
Expand Down
2 changes: 1 addition & 1 deletion ptrify/ptrify.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// Note: this looks weird because it is, you need to call TypeOf on a nil
// pointer here then take the element type, otherwise you get a nil type and
// that's not useful (it actually generates a panic when it's used further down).
var textUnmarshaler = reflect.TypeOf((*encoding.TextUnmarshaler)(nil)).Elem()
var textUnmarshaler = reflect.TypeFor[encoding.TextUnmarshaler]()

// Pointerify takes a type and returns another type with all its members
// set to pointers of their respective types
Expand Down
Loading
Loading