summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLvbo163 <lv.bo163@zte.com.cn>2018-07-31 15:28:24 +0800
committerLvbo163 <lv.bo163@zte.com.cn>2018-07-31 15:28:24 +0800
commit8cce6f20d71c009380d9eff4097cee98aef0da4e (patch)
tree77c896a07eb853ffe677b2c96a8a5dae97675943
parent9d46f1ab7add9e257f6d0ac7442bed0b901e1aa5 (diff)
add ut for yaml convertor
Issue-ID: MSB-236 Change-Id: Ib6899928d7c41b05cdfaae617dd3ab1c41352df2 Signed-off-by: Lvbo163 <lv.bo163@zte.com.cn>
-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)
+ }
+ }
+}