Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problem of rest protocol PR #352 #399

Merged
merged 1 commit into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions common/yaml/testdata/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

intTest: 11
booleanTest: false
strTest: "strTest"

child:
strTest: "childStrTest"
17 changes: 17 additions & 0 deletions common/yaml/yaml.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package yaml

import (
Expand Down
38 changes: 38 additions & 0 deletions common/yaml/yaml_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package yaml

import (
"path/filepath"
"testing"
)

import (
"github.com/stretchr/testify/assert"
)

func TestUnmarshalYMLConfig(t *testing.T) {
conPath, err := filepath.Abs("./testdata/config.yml")
assert.NoError(t, err)
c := &Config{}
assert.NoError(t, UnmarshalYMLConfig(conPath, c))
assert.Equal(t, "strTest", c.StrTest)
assert.Equal(t, 11, c.IntTest)
assert.Equal(t, false, c.BooleanTest)
assert.Equal(t, "childStrTest", c.ChildConfig.StrTest)
}

func TestUnmarshalYMLConfig_Error(t *testing.T) {
c := &Config{}
assert.Error(t, UnmarshalYMLConfig("./testdata/config", c))
assert.Error(t, UnmarshalYMLConfig("", c))
}

type Config struct {
StrTest string `yaml:"strTest" default:"default" json:"strTest,omitempty" property:"strTest"`
IntTest int `default:"109" yaml:"intTest" json:"intTest,omitempty" property:"intTest"`
BooleanTest bool `yaml:"booleanTest" default:"true" json:"booleanTest,omitempty"`
ChildConfig ChildConfig `yaml:"child" json:"child,omitempty"`
}

type ChildConfig struct {
StrTest string `default:"strTest" default:"default" yaml:"strTest" json:"strTest,omitempty"`
}
12 changes: 0 additions & 12 deletions config/base_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package config

import (
"fmt"
"path/filepath"
"reflect"
"testing"
)
Expand All @@ -28,7 +27,6 @@ import (
import (
"github.com/apache/dubbo-go/common/config"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/common/yaml"
"github.com/apache/dubbo-go/config_center"
_ "github.com/apache/dubbo-go/config_center/apollo"
)
Expand Down Expand Up @@ -519,13 +517,3 @@ func Test_initializeStruct(t *testing.T) {
return consumerConfig.References != nil
})
}

func TestUnmarshalYMLConfig(t *testing.T) {
conPath, err := filepath.Abs("./testdata/consumer_config_with_configcenter.yml")
assert.NoError(t, err)
c := &ConsumerConfig{}
assert.NoError(t, yaml.UnmarshalYMLConfig(conPath, c))
assert.Equal(t, "default", c.ProxyFactory)
assert.Equal(t, "dubbo.properties", c.ConfigCenterConfig.ConfigFile)
assert.Equal(t, "100ms", c.Connect_Timeout)
}