From 1603add6e69faff20f94f4f65b57b41b2d52d067 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 16 Mar 2023 07:25:01 +0300 Subject: [PATCH] add before Init func support Signed-off-by: Vasiliy Tolstov --- go.mod | 2 +- go.sum | 4 ++-- vault.go | 2 +- vault_test.go | 23 +++++++++++++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 vault_test.go diff --git a/go.mod b/go.mod index 012b33f..b29ef7b 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.18 require ( github.com/hashicorp/vault/api v1.9.0 github.com/imdario/mergo v0.3.13 - go.unistack.org/micro/v3 v3.10.16 + go.unistack.org/micro/v3 v3.10.18 ) require github.com/stretchr/testify v1.7.2 // indirect diff --git a/go.sum b/go.sum index 6c365c3..5ac9492 100644 --- a/go.sum +++ b/go.sum @@ -71,8 +71,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -go.unistack.org/micro/v3 v3.10.16 h1:2er/SKKYbV60M+UuJM4eYCF0MZYAIq/yNUrAbTfgq8Q= -go.unistack.org/micro/v3 v3.10.16/go.mod h1:uMAc0U/x7dmtICCrblGf0ZLgYegu3VwQAquu+OFCw1Q= +go.unistack.org/micro/v3 v3.10.18 h1:iz193N8eZKGrKPXuX6XMsGIRHMqdvUaZSfb9mzwlUYM= +go.unistack.org/micro/v3 v3.10.18/go.mod h1:uMAc0U/x7dmtICCrblGf0ZLgYegu3VwQAquu+OFCw1Q= golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= diff --git a/vault.go b/vault.go index 81a836e..af60a7a 100644 --- a/vault.go +++ b/vault.go @@ -87,7 +87,7 @@ func (c *vaultConfig) Init(opts ...config.Option) error { return err } - if err := config.DefaultAfterInit(c.opts.Context, c); err != nil && !c.opts.AllowFail { + if err = config.DefaultAfterInit(c.opts.Context, c); err != nil && !c.opts.AllowFail { return err } diff --git a/vault_test.go b/vault_test.go new file mode 100644 index 0000000..c98e666 --- /dev/null +++ b/vault_test.go @@ -0,0 +1,23 @@ +package vault + +import ( + "context" + "testing" + + "go.unistack.org/micro/v3/codec" + "go.unistack.org/micro/v3/config" +) + +func TestInit(t *testing.T) { + c := NewConfig( + config.Context(context.TODO()), + config.Codec(codec.NewCodec()), + config.BeforeInit(func(ctx context.Context, c config.Config) error { + return c.Init(Token("tkn"), config.BeforeInit(nil)) + }), + ) + + if err := c.Init(); err != nil { + t.Fatal(err) + } +} -- 2.45.2