Skip to content

Commit

Permalink
Merge pull request #399 from Patrick0308/rest
Browse files Browse the repository at this point in the history
Fix problem of rest protocol PR #352
  • Loading branch information
zouyx authored Mar 12, 2020
2 parents 73119b4 + 0c55d99 commit 46af97f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 12 deletions.
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)
}

0 comments on commit 46af97f

Please sign in to comment.