You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by jo...@apache.org on 2020/03/12 05:14:26 UTC
[dubbo-go] branch feature/rest updated: add yaml unit test
This is an automated email from the ASF dual-hosted git repository.
joezou pushed a commit to branch feature/rest
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/feature/rest by this push:
new 0c55d99 add yaml unit test
new 46af97f Merge pull request #399 from Patrick0308/rest
0c55d99 is described below
commit 0c55d9959236065a6e21107eb48bb77242cd25a0
Author: Patrick <dr...@foxmail.com>
AuthorDate: Thu Mar 12 12:55:24 2020 +0800
add yaml unit test
---
common/yaml/testdata/config.yml | 7 +++++++
common/yaml/yaml.go | 17 +++++++++++++++++
common/yaml/yaml_test.go | 38 ++++++++++++++++++++++++++++++++++++++
config/base_config_test.go | 12 ------------
4 files changed, 62 insertions(+), 12 deletions(-)
diff --git a/common/yaml/testdata/config.yml b/common/yaml/testdata/config.yml
new file mode 100644
index 0000000..b5c2ca8
--- /dev/null
+++ b/common/yaml/testdata/config.yml
@@ -0,0 +1,7 @@
+
+intTest: 11
+booleanTest: false
+strTest: "strTest"
+
+child:
+ strTest: "childStrTest"
\ No newline at end of file
diff --git a/common/yaml/yaml.go b/common/yaml/yaml.go
index 6c0829b..1d8ac65 100644
--- a/common/yaml/yaml.go
+++ b/common/yaml/yaml.go
@@ -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 (
diff --git a/common/yaml/yaml_test.go b/common/yaml/yaml_test.go
new file mode 100644
index 0000000..8d0eefd
--- /dev/null
+++ b/common/yaml/yaml_test.go
@@ -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"`
+}
diff --git a/config/base_config_test.go b/config/base_config_test.go
index 34a8852..d16b242 100644
--- a/config/base_config_test.go
+++ b/config/base_config_test.go
@@ -18,7 +18,6 @@ package config
import (
"fmt"
- "path/filepath"
"reflect"
"testing"
)
@@ -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"
)
@@ -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)
-}