Skip to content

Commit

Permalink
chore(naming): rename interface{} to any for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
nikoksr committed Aug 11, 2024
1 parent eacac4e commit 6df8949
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,20 @@ func TestApplyDefaultsErrors(t *testing.T) {

tests := []struct {
name string
config interface{}
defaults map[reflect.Type][]interface{}
config any
defaults map[reflect.Type][]any
expected string
}{
{
name: "Non-pointer input",
config: struct{ Name string }{},
defaults: map[reflect.Type][]interface{}{},
defaults: map[reflect.Type][]any{},
expected: "must be a pointer",
},
{
name: "Nil input",
config: (*struct{ Name string })(nil),
defaults: map[reflect.Type][]interface{}{},
defaults: map[reflect.Type][]any{},
expected: "cannot be nil",
},
}
Expand All @@ -109,7 +109,7 @@ func testBasicTypes(t *testing.T) {
}

config := &SimpleStruct{Name: "", Age: 0}
defaults := map[reflect.Type][]interface{}{
defaults := map[reflect.Type][]any{
reflect.TypeOf(SimpleStruct{}): {
SimpleStruct{Name: "Default", Age: 30},
},
Expand Down Expand Up @@ -138,17 +138,17 @@ func testNestedAndEmbeddedStructs(t *testing.T) {

tests := []struct {
name string
config interface{}
defaults map[reflect.Type][]interface{}
expected interface{}
config any
defaults map[reflect.Type][]any
expected any
}{
{
name: "Nested struct",
config: &NestedStruct{
Simple: SimpleStruct{},
Value: 0,
},
defaults: map[reflect.Type][]interface{}{
defaults: map[reflect.Type][]any{
reflect.TypeOf(NestedStruct{}): {
NestedStruct{Value: 3.14},
},
Expand All @@ -167,7 +167,7 @@ func testNestedAndEmbeddedStructs(t *testing.T) {
SimpleStruct: SimpleStruct{},
Extra: "",
},
defaults: map[reflect.Type][]interface{}{
defaults: map[reflect.Type][]any{
reflect.TypeOf(EmbeddedStruct{}): {
EmbeddedStruct{Extra: "ExtraDefault"},
},
Expand Down Expand Up @@ -208,9 +208,9 @@ func testSlicesAndPointers(t *testing.T) {

tests := []struct {
name string
config interface{}
defaults map[reflect.Type][]interface{}
expected interface{}
config any
defaults map[reflect.Type][]any
expected any
}{
{
name: "Slice of structs",
Expand All @@ -220,7 +220,7 @@ func testSlicesAndPointers(t *testing.T) {
{Name: "", Age: 25},
},
},
defaults: map[reflect.Type][]interface{}{
defaults: map[reflect.Type][]any{
reflect.TypeOf(SimpleStruct{}): {
SimpleStruct{Name: "Default", Age: 30},
},
Expand All @@ -237,7 +237,7 @@ func testSlicesAndPointers(t *testing.T) {
config: &PointerStruct{
Ptr: &SimpleStruct{},
},
defaults: map[reflect.Type][]interface{}{
defaults: map[reflect.Type][]any{
reflect.TypeOf(SimpleStruct{}): {
SimpleStruct{Name: "Default", Age: 30},
},
Expand All @@ -249,7 +249,7 @@ func testSlicesAndPointers(t *testing.T) {
{
name: "Nil pointer",
config: &PointerStruct{},
defaults: map[reflect.Type][]interface{}{
defaults: map[reflect.Type][]any{
reflect.TypeOf(SimpleStruct{}): {
SimpleStruct{Name: "Default", Age: 30},
},
Expand All @@ -275,7 +275,7 @@ func testMultipleDefaults(t *testing.T) {
}

config := &SimpleStruct{Name: "", Age: 0}
defaults := map[reflect.Type][]interface{}{
defaults := map[reflect.Type][]any{
reflect.TypeOf(SimpleStruct{}): {
SimpleStruct{Name: "First", Age: 10},
SimpleStruct{Name: "Second", Age: 20},
Expand Down Expand Up @@ -319,7 +319,7 @@ func testComplexNestedStruct(t *testing.T) {
MapField: nil,
}

defaults := map[reflect.Type][]interface{}{
defaults := map[reflect.Type][]any{
reflect.TypeOf(ComplexStruct{}): {
ComplexStruct{
Name: "DefaultName",
Expand Down Expand Up @@ -379,18 +379,18 @@ func testInterfaceSlice(t *testing.T) {
}

type RoomConfig struct {
Devices []interface{}
Devices []any
}

config := &RoomConfig{
Devices: []interface{}{
Devices: []any{
&LightDevice{BaseDevice: BaseDevice{Enabled: true}},
&LightDevice{Brightness: 75},
&ThermostatDevice{},
},
}

defaults := map[reflect.Type][]interface{}{
defaults := map[reflect.Type][]any{
reflect.TypeOf(BaseDevice{}): {BaseDevice{Enabled: false}},
reflect.TypeOf(LightDevice{}): {LightDevice{Brightness: 50}},
reflect.TypeOf(ThermostatDevice{}): {ThermostatDevice{
Expand Down Expand Up @@ -432,7 +432,7 @@ func testCircularReferences(t *testing.T) {
config.Next.Next = &Circular{Name: ""}
config.Next.Next.Next = config

defaults := map[reflect.Type][]interface{}{
defaults := map[reflect.Type][]any{
reflect.TypeOf(Circular{}): {
Circular{Name: "Default"},
},
Expand All @@ -454,8 +454,8 @@ func testInterfaceFields(t *testing.T) {
}

type InterfaceContainer struct {
Data interface{}
NestedContainer interface{}
Data any
NestedContainer any
}

config := &InterfaceContainer{
Expand All @@ -465,7 +465,7 @@ func testInterfaceFields(t *testing.T) {
},
}

defaults := map[reflect.Type][]interface{}{
defaults := map[reflect.Type][]any{
reflect.TypeOf(ConcreteType{}): {
ConcreteType{Value: "default"},
},
Expand Down Expand Up @@ -506,7 +506,7 @@ func testMaps(t *testing.T) {
},
}

defaults := map[reflect.Type][]interface{}{
defaults := map[reflect.Type][]any{
reflect.TypeOf(Config{}): {
Config{
StringMap: map[string]string{"default": "value"},
Expand Down Expand Up @@ -554,7 +554,7 @@ func testEmbeddedStructs(t *testing.T) {

config := &Config{}

defaults := map[reflect.Type][]interface{}{
defaults := map[reflect.Type][]any{
reflect.TypeOf(unexportedEmbedded{}): {
unexportedEmbedded{privateField: "default private"},
},
Expand Down Expand Up @@ -613,7 +613,7 @@ func testSlicesOfInterfaces(t *testing.T) {
},
}

defaults := map[reflect.Type][]interface{}{
defaults := map[reflect.Type][]any{
reflect.TypeOf(&Dog{}): {
&Dog{Name: "DefaultDog"},
},
Expand Down

0 comments on commit 6df8949

Please sign in to comment.