From 92b3c8f94a973cc7d3e50d58b4ca07617ad0022e Mon Sep 17 00:00:00 2001 From: Paul <52645166+paulip1792@users.noreply.github.com> Date: Wed, 27 Jul 2022 10:44:48 +0800 Subject: [PATCH] fix(contrib/config/polaris): Use injected client properly (#2238) --- contrib/config/polaris/config.go | 11 +++-------- contrib/config/polaris/config_test.go | 4 ++-- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/contrib/config/polaris/config.go b/contrib/config/polaris/config.go index f5d52d18e..c3c39ecee 100644 --- a/contrib/config/polaris/config.go +++ b/contrib/config/polaris/config.go @@ -43,11 +43,11 @@ func WithFileName(fileName string) Option { } type source struct { - client *polaris.ConfigAPI + client polaris.ConfigAPI options *options } -func New(client *polaris.ConfigAPI, opts ...Option) (config.Source, error) { +func New(client polaris.ConfigAPI, opts ...Option) (config.Source, error) { options := &options{ namespace: "default", fileGroup: "", @@ -74,12 +74,7 @@ func New(client *polaris.ConfigAPI, opts ...Option) (config.Source, error) { // Load return the config values func (s *source) Load() ([]*config.KeyValue, error) { - configAPI, err := polaris.NewConfigAPI() - if err != nil { - return nil, err - } - - configFile, err := configAPI.GetConfigFile(s.options.namespace, s.options.fileGroup, s.options.fileName) + configFile, err := s.client.GetConfigFile(s.options.namespace, s.options.fileGroup, s.options.fileName) if err != nil { fmt.Println("fail to get config.", err) return nil, err diff --git a/contrib/config/polaris/config_test.go b/contrib/config/polaris/config_test.go index 6dfaeb3f6..fc864526c 100644 --- a/contrib/config/polaris/config_test.go +++ b/contrib/config/polaris/config_test.go @@ -213,7 +213,7 @@ func TestConfig(t *testing.T) { if err != nil { t.Fatal(err) } - config, err := New(&configAPI, WithNamespace(namespace), WithFileGroup(fileGroup), WithFileName(name)) + config, err := New(configAPI, WithNamespace(namespace), WithFileGroup(fileGroup), WithFileName(name)) if err != nil { t.Fatal(err) } @@ -285,7 +285,7 @@ func TestExtToFormat(t *testing.T) { t.Fatal(err) } - config, err := New(&configAPI, WithNamespace(namespace), WithFileGroup(fileGroup), WithFileName(name)) + config, err := New(configAPI, WithNamespace(namespace), WithFileGroup(fileGroup), WithFileName(name)) if err != nil { t.Fatal(err) }