summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHuabing Zhao <zhaohuabing@gmail.com>2018-07-31 07:44:42 +0000
committerGerrit Code Review <gerrit@onap.org>2018-07-31 07:44:42 +0000
commitf2d7ee8e726abb9e69b6ed0416d2493eac74a2b3 (patch)
treea94e68665d12d79484d78c32ad98a647eb554c64
parent2401f9f8f855c55c30c7b8aadd57fda518df5f2c (diff)
parent8cce6f20d71c009380d9eff4097cee98aef0da4e (diff)
Merge "add ut for yaml convertor"
-rw-r--r--msb2pilot/src/msb2pilot/util/yaml_test.go89
1 files changed, 89 insertions, 0 deletions
diff --git a/msb2pilot/src/msb2pilot/util/yaml_test.go b/msb2pilot/src/msb2pilot/util/yaml_test.go
new file mode 100644
index 0000000..6b5b938
--- /dev/null
+++ b/msb2pilot/src/msb2pilot/util/yaml_test.go
@@ -0,0 +1,89 @@
+/**
+ * Copyright (c) 2018 ZTE Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and the Apache License 2.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ * ZTE - initial Project
+ */
+package util
+
+import (
+ "testing"
+)
+
+type T struct {
+ F int `yaml:"a,omitempty"`
+ B int
+}
+
+func TestMarshalYaml(t *testing.T) {
+
+ cases := []struct {
+ in *T
+ want string
+ }{
+ {
+ in: &T{
+ 1, 2,
+ },
+ want: "a: 1\nb: 2\n",
+ }, {
+ in: &T{
+ B: 2,
+ },
+ want: "b: 2\n",
+ }}
+
+ for _, cas := range cases {
+ got, err := MarshalYaml(cas.in)
+ if err != nil {
+ t.Errorf(err.Error())
+ }
+
+ if got != cas.want {
+ t.Errorf("MarshalYaml error: want %s, got %s", cas.want, got)
+ }
+
+ }
+
+}
+
+func TestUnmarshalYaml(t *testing.T) {
+ cases := []struct {
+ in string
+ want T
+ }{
+ {
+ in: "a: 1\nb: 2",
+ want: T{
+ 1, 2,
+ },
+ },
+ {
+ in: "b: 2\n",
+ want: T{
+ B: 2,
+ },
+ },
+ {
+ in: "c: 2\n",
+ want: T{},
+ }}
+
+ for _, cas := range cases {
+ got := new(T)
+ err := UnmarshalYaml(cas.in, got)
+
+ if err != nil {
+ t.Errorf("UnmarshalYaml error: want err, got %v", cas.want)
+ }
+
+ if got.F != cas.want.F || got.B != cas.want.B {
+ t.Errorf("UnmarshalYaml error: want %v, got %v", cas.want, got)
+ }
+ }
+}