From e447f4165016b9c6baf7aa192c29195b3d073b67 Mon Sep 17 00:00:00 2001 From: Samuel Berthe Date: Thu, 9 May 2024 21:31:29 +0200 Subject: [PATCH] chore: upgrade go-type-to-string --- di_alias_test.go | 10 ++++----- di_test.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- go.work.sum | 4 ++-- service_alias_test.go | 48 +++++++++++++++++++++---------------------- service_test.go | 2 +- 7 files changed, 36 insertions(+), 36 deletions(-) diff --git a/di_alias_test.go b/di_alias_test.go index 7574fc7..933f449 100644 --- a/di_alias_test.go +++ b/di_alias_test.go @@ -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") } @@ -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") } @@ -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) { diff --git a/di_test.go b/di_test.go index 829a6d5..7e4dc9c 100644 --- a/di_test.go +++ b/di_test.go @@ -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) { diff --git a/go.mod b/go.mod index e674230..8936320 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 45bc8bd..f400ab9 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/go.work.sum b/go.work.sum index c7bf3ef..8508aed 100644 --- a/go.work.sum +++ b/go.work.sum @@ -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= diff --git a/service_alias_test.go b/service_alias_test.go index 29fe7c1..ceadeca 100644 --- a/service_alias_test.go +++ b/service_alias_test.go @@ -59,15 +59,15 @@ 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) { @@ -75,9 +75,9 @@ func TestServiceAlias_getInstanceAny(t *testing.T) { }) // 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 @@ -95,15 +95,15 @@ 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) { @@ -111,9 +111,9 @@ func TestServiceAlias_getInstance(t *testing.T) { }) // 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 @@ -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()) @@ -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()) @@ -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)) @@ -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)) @@ -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()) @@ -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()) @@ -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)) @@ -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)) diff --git a/service_test.go b/service_test.go index ce3e982..0bda0e1 100644 --- a/service_test.go +++ b/service_test.go @@ -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) {