Skip to content

Commit

Permalink
chore: upgrade go-type-to-string
Browse files Browse the repository at this point in the history
  • Loading branch information
samber committed May 9, 2024
1 parent 49259a8 commit e447f41
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 36 deletions.
10 changes: 5 additions & 5 deletions di_alias_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestAs(t *testing.T) {
Provide(i, func(i Injector) (*lazyTestHeathcheckerOK, error) { return &lazyTestHeathcheckerOK{}, nil })

is.Nil(As[*lazyTestHeathcheckerOK, Healthchecker](i))
is.EqualError(As[*lazyTestShutdownerOK, Healthchecker](i), "DI: `*github.com/samber/do/v2.lazyTestShutdownerOK` is not `*github.com/samber/do/v2.Healthchecker`")
is.EqualError(As[*lazyTestShutdownerOK, Healthchecker](i), "DI: `*github.com/samber/do/v2.lazyTestShutdownerOK` is not `github.com/samber/do/v2.Healthchecker`")
is.EqualError(As[*lazyTestHeathcheckerKO, Healthchecker](i), "DI: service `*github.com/samber/do/v2.lazyTestHeathcheckerKO` has not been declared")
is.EqualError(As[*lazyTestShutdownerOK, *lazyTestShutdownerOK](i), "DI: service `*github.com/samber/do/v2.lazyTestShutdownerOK` has not been declared")
}
Expand All @@ -32,9 +32,9 @@ func TestAsNamed(t *testing.T) {
i := New()
Provide(i, func(i Injector) (*lazyTestHeathcheckerOK, error) { return &lazyTestHeathcheckerOK{}, nil })

is.Nil(AsNamed[*lazyTestHeathcheckerOK, Healthchecker](i, "*github.com/samber/do/v2.lazyTestHeathcheckerOK", "*github.com/samber/do/v2.Healthchecker"))
is.EqualError(AsNamed[*lazyTestShutdownerOK, Healthchecker](i, "*github.com/samber/do/v2.lazyTestShutdownerOK", "*github.com/samber/do/v2.Healthchecker"), "DI: `*github.com/samber/do/v2.lazyTestShutdownerOK` is not `*github.com/samber/do/v2.Healthchecker`")
is.EqualError(AsNamed[*lazyTestHeathcheckerKO, Healthchecker](i, "*github.com/samber/do/v2.lazyTestHeathcheckerKO", "*github.com/samber/do/v2.Healthchecker"), "DI: service `*github.com/samber/do/v2.lazyTestHeathcheckerKO` has not been declared")
is.Nil(AsNamed[*lazyTestHeathcheckerOK, Healthchecker](i, "*github.com/samber/do/v2.lazyTestHeathcheckerOK", "github.com/samber/do/v2.Healthchecker"))
is.EqualError(AsNamed[*lazyTestShutdownerOK, Healthchecker](i, "*github.com/samber/do/v2.lazyTestShutdownerOK", "github.com/samber/do/v2.Healthchecker"), "DI: `*github.com/samber/do/v2.lazyTestShutdownerOK` is not `github.com/samber/do/v2.Healthchecker`")
is.EqualError(AsNamed[*lazyTestHeathcheckerKO, Healthchecker](i, "*github.com/samber/do/v2.lazyTestHeathcheckerKO", "github.com/samber/do/v2.Healthchecker"), "DI: service `*github.com/samber/do/v2.lazyTestHeathcheckerKO` has not been declared")
is.EqualError(AsNamed[*lazyTestShutdownerOK, *lazyTestShutdownerOK](i, "*github.com/samber/do/v2.lazyTestShutdownerOK", "*github.com/samber/do/v2.lazyTestShutdownerOK"), "DI: service `*github.com/samber/do/v2.lazyTestShutdownerOK` has not been declared")
}

Expand Down Expand Up @@ -67,7 +67,7 @@ func TestInvokeAs(t *testing.T) {
// not found
svc2, err := InvokeAs[Shutdowner](i)
is.Empty(svc2)
is.EqualError(err, "DI: could not find service satisfying interface `*github.com/samber/do/v2.Shutdowner`, available services: `*github.com/samber/do/v2.lazyTestHeathcheckerOK`")
is.EqualError(err, "DI: could not find service satisfying interface `github.com/samber/do/v2.Shutdowner`, available services: `*github.com/samber/do/v2.lazyTestHeathcheckerOK`")
}

func TestMustInvokeAs(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion di_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestNameOf(t *testing.T) {
is.Equal("github.com/samber/do/v2.eagerTest", NameOf[eagerTest]())
is.Equal("*github.com/samber/do/v2.eagerTest", NameOf[*eagerTest]())
is.Equal("*map[int]bool", NameOf[*map[int]bool]())
is.Equal("*github.com/samber/do/v2.Service[int]", NameOf[Service[int]]())
is.Equal("github.com/samber/do/v2.Service[int]", NameOf[Service[int]]())
}

func TestProvide(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ go 1.18
//

require (
github.com/samber/go-type-to-string v1.2.0
github.com/samber/go-type-to-string v1.3.0
github.com/stretchr/testify v1.8.3
go.uber.org/goleak v1.2.1
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/samber/go-type-to-string v1.2.0 h1:Pvdqx3r/EHn9/DTKoW6RoHz/850s5yV1vA6MqKKG5Ys=
github.com/samber/go-type-to-string v1.2.0/go.mod h1:jpU77vIDoIxkahknKDoEx9C8bQ1ADnh2sotZ8I4QqBU=
github.com/samber/go-type-to-string v1.3.0 h1:JcgXHFwSc+4491D/Tc0PfDgOJhEp8bLOwI4ytGoFEEE=
github.com/samber/go-type-to-string v1.3.0/go.mod h1:jpU77vIDoIxkahknKDoEx9C8bQ1ADnh2sotZ8I4QqBU=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
Expand Down
4 changes: 2 additions & 2 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvSc
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0=
github.com/samber/go-type-to-string v1.2.0 h1:Pvdqx3r/EHn9/DTKoW6RoHz/850s5yV1vA6MqKKG5Ys=
github.com/samber/go-type-to-string v1.2.0/go.mod h1:jpU77vIDoIxkahknKDoEx9C8bQ1ADnh2sotZ8I4QqBU=
github.com/samber/go-type-to-string v1.3.0 h1:JcgXHFwSc+4491D/Tc0PfDgOJhEp8bLOwI4ytGoFEEE=
github.com/samber/go-type-to-string v1.3.0/go.mod h1:jpU77vIDoIxkahknKDoEx9C8bQ1ADnh2sotZ8I4QqBU=
github.com/tinylib/msgp v1.1.8/go.mod h1:qkpG+2ldGg4xRFmx+jfTvZPxfGFhi64BcnL9vkCm/Tw=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
Expand Down
48 changes: 24 additions & 24 deletions service_alias_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,25 @@ func TestServiceAlias_getInstanceAny(t *testing.T) {
is.Nil(As[*lazyTestHeathcheckerOK, Healthchecker](i))

// basic type
service1 := newServiceAlias[*lazyTestHeathcheckerOK, Healthchecker]("*github.com/samber/do/v2.Healthchecker", i, "*github.com/samber/do/v2.lazyTestHeathcheckerOK")
service1 := newServiceAlias[*lazyTestHeathcheckerOK, Healthchecker]("github.com/samber/do/v2.Healthchecker", i, "*github.com/samber/do/v2.lazyTestHeathcheckerOK")
instance1, err1 := service1.getInstanceAny(i)
is.Nil(err1)
is.EqualValues(&lazyTestHeathcheckerOK{foobar: "foobar"}, instance1)

// target service not found
service2 := newServiceAlias[*lazyTestHeathcheckerOK, int]("*github.com/samber/do/v2.Healthchecker", i, "int")
service2 := newServiceAlias[*lazyTestHeathcheckerOK, int]("github.com/samber/do/v2.Healthchecker", i, "int")
instance2, err2 := service2.getInstanceAny(i)
is.EqualError(err2, "DI: could not find service `int`, available services: `*github.com/samber/do/v2.Healthchecker`, `*github.com/samber/do/v2.lazyTestHeathcheckerOK`")
is.EqualError(err2, "DI: could not find service `int`, available services: `*github.com/samber/do/v2.lazyTestHeathcheckerOK`, `github.com/samber/do/v2.Healthchecker`")
is.EqualValues(0, instance2)

Provide(i, func(i Injector) (int, error) {
return 42, nil
})

// target service found but not convertible type
service3 := newServiceAlias[*lazyTestHeathcheckerOK, int]("*github.com/samber/do/v2.Healthchecker", i, "int")
service3 := newServiceAlias[*lazyTestHeathcheckerOK, int]("github.com/samber/do/v2.Healthchecker", i, "int")
instance3, err3 := service3.getInstanceAny(i)
is.EqualError(err3, "DI: could not find service `int`, available services: `*github.com/samber/do/v2.Healthchecker`, `*github.com/samber/do/v2.lazyTestHeathcheckerOK`, `int`")
is.EqualError(err3, "DI: could not find service `int`, available services: `*github.com/samber/do/v2.lazyTestHeathcheckerOK`, `github.com/samber/do/v2.Healthchecker`, `int`")
is.EqualValues(0, instance3)

// @TODO: missing test with child scopes
Expand All @@ -95,25 +95,25 @@ func TestServiceAlias_getInstance(t *testing.T) {
is.Nil(As[*lazyTestHeathcheckerOK, Healthchecker](i))

// basic type
service1 := newServiceAlias[*lazyTestHeathcheckerOK, Healthchecker]("*github.com/samber/do/v2.Healthchecker", i, "*github.com/samber/do/v2.lazyTestHeathcheckerOK")
service1 := newServiceAlias[*lazyTestHeathcheckerOK, Healthchecker]("github.com/samber/do/v2.Healthchecker", i, "*github.com/samber/do/v2.lazyTestHeathcheckerOK")
instance1, err1 := service1.getInstance(i)
is.Nil(err1)
is.EqualValues(&lazyTestHeathcheckerOK{foobar: "foobar"}, instance1)

// target service not found
service2 := newServiceAlias[*lazyTestHeathcheckerOK, int]("*github.com/samber/do/v2.Healthchecker", i, "int")
service2 := newServiceAlias[*lazyTestHeathcheckerOK, int]("github.com/samber/do/v2.Healthchecker", i, "int")
instance2, err2 := service2.getInstance(i)
is.EqualError(err2, "DI: could not find service `int`, available services: `*github.com/samber/do/v2.Healthchecker`, `*github.com/samber/do/v2.lazyTestHeathcheckerOK`")
is.EqualError(err2, "DI: could not find service `int`, available services: `*github.com/samber/do/v2.lazyTestHeathcheckerOK`, `github.com/samber/do/v2.Healthchecker`")
is.EqualValues(0, instance2)

Provide(i, func(i Injector) (int, error) {
return 42, nil
})

// target service found but not convertible type
service3 := newServiceAlias[*lazyTestHeathcheckerOK, int]("*github.com/samber/do/v2.Healthchecker", i, "int")
service3 := newServiceAlias[*lazyTestHeathcheckerOK, int]("github.com/samber/do/v2.Healthchecker", i, "int")
instance3, err3 := service3.getInstance(i)
is.EqualError(err3, "DI: could not find service `int`, available services: `*github.com/samber/do/v2.Healthchecker`, `*github.com/samber/do/v2.lazyTestHeathcheckerOK`, `int`")
is.EqualError(err3, "DI: could not find service `int`, available services: `*github.com/samber/do/v2.lazyTestHeathcheckerOK`, `github.com/samber/do/v2.Healthchecker`, `int`")
is.EqualValues(0, instance3)

// @TODO: missing test with child scopes
Expand All @@ -139,7 +139,7 @@ func TestServiceAlias_isHealthchecker(t *testing.T) {
return &lazyTestHeathcheckerOK{foobar: "foobar"}, nil
})
is.Nil(As[*lazyTestHeathcheckerOK, Healthchecker](i2))
service2, _ := i2.serviceGet("*github.com/samber/do/v2.Healthchecker")
service2, _ := i2.serviceGet("github.com/samber/do/v2.Healthchecker")
is.False(service2.(serviceIsHealthchecker).isHealthchecker())
_, _ = service2.(serviceGetInstanceAny).getInstanceAny(nil)
is.True(service2.(serviceIsHealthchecker).isHealthchecker())
Expand All @@ -150,21 +150,21 @@ func TestServiceAlias_isHealthchecker(t *testing.T) {
return &lazyTestHeathcheckerKO{foobar: "foobar"}, nil
})
is.Nil(As[*lazyTestHeathcheckerKO, Healthchecker](i3))
service3, _ := i3.serviceGet("*github.com/samber/do/v2.Healthchecker")
service3, _ := i3.serviceGet("github.com/samber/do/v2.Healthchecker")
is.False(service3.(serviceIsHealthchecker).isHealthchecker())
_, _ = service3.(serviceGetInstanceAny).getInstanceAny(nil)
is.True(service3.(serviceIsHealthchecker).isHealthchecker())

// service not found (wrong type)
i4 := New()
service4 := newServiceAlias[*lazyTestHeathcheckerKO, Healthchecker]("*github.com/samber/do/v2.Healthchecker", i4, "*github.com/samber/do/v2.lazyTestHeathcheckerKO")
service4 := newServiceAlias[*lazyTestHeathcheckerKO, Healthchecker]("github.com/samber/do/v2.Healthchecker", i4, "*github.com/samber/do/v2.lazyTestHeathcheckerKO")
is.False(service4.isHealthchecker())
_, _ = service4.getInstanceAny(nil)
is.False(service4.isHealthchecker())

// service not found (wrong name)
i5 := New()
service5 := newServiceAlias[*lazyTestHeathcheckerOK, Healthchecker]("*github.com/samber/do/v2.Healthchecker", i5, "*github.com/samber/do/v2.lazyTestHeathcheckerKO")
service5 := newServiceAlias[*lazyTestHeathcheckerOK, Healthchecker]("github.com/samber/do/v2.Healthchecker", i5, "*github.com/samber/do/v2.lazyTestHeathcheckerKO")
is.False(service5.isHealthchecker())
_, _ = service5.getInstanceAny(nil)
is.False(service5.isHealthchecker())
Expand Down Expand Up @@ -192,7 +192,7 @@ func TestServiceAlias_healthcheck(t *testing.T) {
return &lazyTestHeathcheckerOK{foobar: "foobar"}, nil
})
is.Nil(As[*lazyTestHeathcheckerOK, Healthchecker](i2))
service2, _ := i2.serviceGet("*github.com/samber/do/v2.Healthchecker")
service2, _ := i2.serviceGet("github.com/samber/do/v2.Healthchecker")
is.Nil(service2.(Service[Healthchecker]).healthcheck(ctx))
_, _ = service2.(Service[Healthchecker]).getInstance(nil)
is.Nil(service2.(Service[Healthchecker]).healthcheck(ctx))
Expand All @@ -203,21 +203,21 @@ func TestServiceAlias_healthcheck(t *testing.T) {
return &lazyTestHeathcheckerKO{foobar: "foobar"}, nil
})
is.Nil(As[*lazyTestHeathcheckerKO, Healthchecker](i3))
service3, _ := i3.serviceGet("*github.com/samber/do/v2.Healthchecker")
service3, _ := i3.serviceGet("github.com/samber/do/v2.Healthchecker")
is.Nil(service3.(Service[Healthchecker]).healthcheck(ctx))
_, _ = service3.(Service[Healthchecker]).getInstance(nil)
is.Equal(assert.AnError, service3.(Service[Healthchecker]).healthcheck(ctx))

// service not found (wrong type)
i4 := New()
service4 := newServiceAlias[*lazyTestHeathcheckerKO, Healthchecker]("*github.com/samber/do/v2.Healthchecker", i4, "*github.com/samber/do/v2.lazyTestHeathcheckerKO")
service4 := newServiceAlias[*lazyTestHeathcheckerKO, Healthchecker]("github.com/samber/do/v2.Healthchecker", i4, "*github.com/samber/do/v2.lazyTestHeathcheckerKO")
is.Nil(service4.healthcheck(ctx))
_, _ = service4.getInstanceAny(nil)
is.Nil(service4.healthcheck(ctx))

// service not found (wrong name)
i5 := New()
service5 := newServiceAlias[*lazyTestHeathcheckerOK, Healthchecker]("*github.com/samber/do/v2.Healthchecker", i5, "*github.com/samber/do/v2.lazyTestHeathcheckerKO")
service5 := newServiceAlias[*lazyTestHeathcheckerOK, Healthchecker]("github.com/samber/do/v2.Healthchecker", i5, "*github.com/samber/do/v2.lazyTestHeathcheckerKO")
is.Nil(service5.healthcheck(ctx))
_, _ = service5.getInstanceAny(nil)
is.Nil(service5.healthcheck(ctx))
Expand All @@ -243,7 +243,7 @@ func TestServiceAlias_isShutdowner(t *testing.T) {
return &lazyTestShutdownerOK{foobar: "foobar"}, nil
})
is.Nil(As[*lazyTestShutdownerOK, ShutdownerWithContextAndError](i2))
service2, _ := i2.serviceGet("*github.com/samber/do/v2.ShutdownerWithContextAndError")
service2, _ := i2.serviceGet("github.com/samber/do/v2.ShutdownerWithContextAndError")
is.False(service2.(Service[ShutdownerWithContextAndError]).isShutdowner())
_, _ = service2.(Service[ShutdownerWithContextAndError]).getInstance(nil)
is.True(service2.(Service[ShutdownerWithContextAndError]).isShutdowner())
Expand All @@ -254,7 +254,7 @@ func TestServiceAlias_isShutdowner(t *testing.T) {
return &lazyTestShutdownerKO{foobar: "foobar"}, nil
})
is.Nil(As[*lazyTestShutdownerKO, ShutdownerWithError](i3))
service3, _ := i3.serviceGet("*github.com/samber/do/v2.ShutdownerWithError")
service3, _ := i3.serviceGet("github.com/samber/do/v2.ShutdownerWithError")
is.False(service3.(Service[ShutdownerWithError]).isShutdowner())
_, _ = service3.(Service[ShutdownerWithError]).getInstance(nil)
is.True(service3.(Service[ShutdownerWithError]).isShutdowner())
Expand Down Expand Up @@ -295,7 +295,7 @@ func TestServiceAlias_shutdown(t *testing.T) {
return &lazyTestShutdownerOK{foobar: "foobar"}, nil
})
is.Nil(As[*lazyTestShutdownerOK, ShutdownerWithContextAndError](i2))
service2, _ := i2.serviceGet("*github.com/samber/do/v2.ShutdownerWithContextAndError")
service2, _ := i2.serviceGet("github.com/samber/do/v2.ShutdownerWithContextAndError")
is.Nil(service2.(Service[ShutdownerWithContextAndError]).shutdown(ctx))
_, _ = service2.(Service[ShutdownerWithContextAndError]).getInstance(nil)
is.Nil(service2.(Service[ShutdownerWithContextAndError]).shutdown(ctx))
Expand All @@ -306,21 +306,21 @@ func TestServiceAlias_shutdown(t *testing.T) {
return &lazyTestShutdownerKO{foobar: "foobar"}, nil
})
is.Nil(As[*lazyTestShutdownerKO, ShutdownerWithError](i3))
service3, _ := i3.serviceGet("*github.com/samber/do/v2.ShutdownerWithError")
service3, _ := i3.serviceGet("github.com/samber/do/v2.ShutdownerWithError")
is.Nil(service3.(Service[ShutdownerWithError]).shutdown(ctx))
_, _ = service3.(Service[ShutdownerWithError]).getInstance(nil)
is.Equal(assert.AnError, service3.(Service[ShutdownerWithError]).shutdown(ctx))

// service not found (wrong type)
i4 := New()
service4 := newServiceAlias[*lazyTestShutdownerKO, Healthchecker]("*github.com/samber/do/v2.Healthchecker", i4, "*github.com/samber/do/v2.lazyTestShutdownerKO")
service4 := newServiceAlias[*lazyTestShutdownerKO, Healthchecker]("github.com/samber/do/v2.Healthchecker", i4, "*github.com/samber/do/v2.lazyTestShutdownerKO")
is.Nil(service4.shutdown(ctx))
_, _ = service4.getInstanceAny(nil)
is.Nil(service4.shutdown(ctx))

// service not found (wrong name)
i5 := New()
service5 := newServiceAlias[*lazyTestShutdownerOK, Healthchecker]("*github.com/samber/do/v2.Healthchecker", i5, "*github.com/samber/do/v2.lazyTestHeathcheckerKO")
service5 := newServiceAlias[*lazyTestShutdownerOK, Healthchecker]("github.com/samber/do/v2.Healthchecker", i5, "*github.com/samber/do/v2.lazyTestHeathcheckerKO")
is.Nil(service5.shutdown(ctx))
_, _ = service5.getInstanceAny(nil)
is.Nil(service5.shutdown(ctx))
Expand Down
2 changes: 1 addition & 1 deletion service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestInferServiceName(t *testing.T) {
is.Equal("int", inferServiceName[int]())
is.Equal("github.com/samber/do/v2.eagerTest", inferServiceName[eagerTest]())
is.Equal("*github.com/samber/do/v2.eagerTest", inferServiceName[*eagerTest]())
is.Equal("*github.com/samber/do/v2.Healthchecker", inferServiceName[Healthchecker]())
is.Equal("github.com/samber/do/v2.Healthchecker", inferServiceName[Healthchecker]())
}

func TestInferServiceProviderStacktrace(t *testing.T) {
Expand Down

0 comments on commit e447f41

Please sign in to comment.