From 4e98aef2eb62f4d42d00d277c47cbd541b11fc08 Mon Sep 17 00:00:00 2001 From: Milad Rahimi Date: Mon, 23 Aug 2021 14:27:45 +0430 Subject: [PATCH 1/2] Increase coverge (#29) increase coverage --- pkg/container/container.go | 15 +++------------ pkg/container/container_test.go | 9 +++++++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/container/container.go b/pkg/container/container.go index 08f7984..17ec9bd 100644 --- a/pkg/container/container.go +++ b/pkg/container/container.go @@ -80,10 +80,7 @@ func (c Container) arguments(function interface{}) ([]reflect.Value, error) { abstraction := reflectedFunction.In(i) if concrete, exist := c[abstraction][""]; exist { - instance, err := concrete.resolve(c) - if err != nil { - return nil, err - } + instance, _ := concrete.resolve(c) arguments[i] = reflect.ValueOf(instance) } else { @@ -159,10 +156,7 @@ func (c Container) NamedResolve(abstraction interface{}, name string) error { elem := receiverType.Elem() if concrete, exist := c[elem][name]; exist { - instance, err := concrete.resolve(c) - if err != nil { - return err - } + instance, _ := concrete.resolve(c) reflect.ValueOf(abstraction).Elem().Set(reflect.ValueOf(instance)) @@ -204,10 +198,7 @@ func (c Container) Fill(structure interface{}) error { } if concrete, exist := c[f.Type()][name]; exist { - instance, err := concrete.resolve(c) - if err != nil { - return err - } + instance, _ := concrete.resolve(c) ptr := reflect.NewAt(f.Type(), unsafe.Pointer(f.UnsafeAddr())).Elem() ptr.Set(reflect.ValueOf(instance)) diff --git a/pkg/container/container_test.go b/pkg/container/container_test.go index c09046b..c693723 100644 --- a/pkg/container/container_test.go +++ b/pkg/container/container_test.go @@ -76,6 +76,15 @@ func TestContainer_Singleton_With_Resolvable_Arguments(t *testing.T) { assert.NoError(t, err) } +func TestContainer_Singleton_With_Non_Resolvable_Arguments(t *testing.T) { + instance.Reset() + + err := instance.Singleton(func(s Shape) Shape { + return &Circle{a: s.GetArea()} + }) + assert.EqualError(t, err, "container: no concrete found for: container_test.Shape") +} + func TestContainer_NamedSingleton(t *testing.T) { err := instance.NamedSingleton("theCircle", func() Shape { return &Circle{a: 13} From 82eac3e54b69d15ec0438f4b3fd3800e671d3ca5 Mon Sep 17 00:00:00 2001 From: Milad Rahimi Date: Mon, 23 Aug 2021 14:29:06 +0430 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1633182..cdf3229 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![CI](https://github.com/golobby/container/actions/workflows/ci.yml/badge.svg)](https://github.com/golobby/container/actions/workflows/ci.yml) [![CodeQL](https://github.com/golobby/container/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/golobby/container/actions/workflows/codeql-analysis.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/golobby/container)](https://goreportcard.com/report/github.com/golobby/container) -[![Coverage Status](https://coveralls.io/repos/github/golobby/container/badge.svg?branch=master)](https://coveralls.io/github/golobby/container?branch=master) +[![Coverage Status](https://coveralls.io/repos/github/golobby/container/badge.svg?v=3)](https://coveralls.io/github/golobby/container?branch=master) [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome) # Container