fix(contrib/config/polaris): Use injected client properly (#2238)

pull/2217/head
Paul 2 years ago committed by GitHub
parent 14cfd65b62
commit 92b3c8f94a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      contrib/config/polaris/config.go
  2. 4
      contrib/config/polaris/config_test.go

@ -43,11 +43,11 @@ func WithFileName(fileName string) Option {
} }
type source struct { type source struct {
client *polaris.ConfigAPI client polaris.ConfigAPI
options *options options *options
} }
func New(client *polaris.ConfigAPI, opts ...Option) (config.Source, error) { func New(client polaris.ConfigAPI, opts ...Option) (config.Source, error) {
options := &options{ options := &options{
namespace: "default", namespace: "default",
fileGroup: "", fileGroup: "",
@ -74,12 +74,7 @@ func New(client *polaris.ConfigAPI, opts ...Option) (config.Source, error) {
// Load return the config values // Load return the config values
func (s *source) Load() ([]*config.KeyValue, error) { func (s *source) Load() ([]*config.KeyValue, error) {
configAPI, err := polaris.NewConfigAPI() configFile, err := s.client.GetConfigFile(s.options.namespace, s.options.fileGroup, s.options.fileName)
if err != nil {
return nil, err
}
configFile, err := configAPI.GetConfigFile(s.options.namespace, s.options.fileGroup, s.options.fileName)
if err != nil { if err != nil {
fmt.Println("fail to get config.", err) fmt.Println("fail to get config.", err)
return nil, err return nil, err

@ -213,7 +213,7 @@ func TestConfig(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -285,7 +285,7 @@ func TestExtToFormat(t *testing.T) {
t.Fatal(err) 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

Loading…
Cancel
Save