add ut for file util 59/58159/1
authorLvbo163 <lv.bo163@zte.com.cn>
Tue, 31 Jul 2018 03:32:15 +0000 (11:32 +0800)
committerLvbo163 <lv.bo163@zte.com.cn>
Tue, 31 Jul 2018 03:32:15 +0000 (11:32 +0800)
add ut for file util

Issue-ID: MSB-233

Change-Id: I5f7271d392943fdec244894b4340ec63cf798e3d
Signed-off-by: Lvbo163 <lv.bo163@zte.com.cn>
msb2pilot/src/msb2pilot/util/file_test.go [new file with mode: 0644]

diff --git a/msb2pilot/src/msb2pilot/util/file_test.go b/msb2pilot/src/msb2pilot/util/file_test.go
new file mode 100644 (file)
index 0000000..e2fcc99
--- /dev/null
@@ -0,0 +1,67 @@
+/**
+ * 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 (
+       "os"
+       "testing"
+)
+
+func TestWrite(t *testing.T) {
+       cases := []struct {
+               path, data, want string
+               mode             os.FileMode
+       }{
+               {
+                       path: `test.txt`,
+                       data: `test string`,
+                       mode: 0666,
+                       want: `success`,
+               },
+               {
+                       path: ``,
+                       data: `test string`,
+                       mode: 0666,
+                       want: `fail`,
+               },
+       }
+
+       for _, cas := range cases {
+               err := Write(cas.path, cas.data, cas.mode)
+               if (cas.want == "success" && err != nil) || (cas.want == "fail" && err == nil) {
+                       t.Errorf("Write() => got %v, want %s", err, cas.want)
+               }
+       }
+}
+
+func TestRead(t *testing.T) {
+
+       cases := []struct {
+               path, want string
+       }{
+               {
+                       path: `file_test.go`,
+                       want: `success`,
+               },
+               {
+                       path: ``,
+                       want: `fail`,
+               },
+       }
+
+       for _, cas := range cases {
+               _, err := Read(cas.path)
+               if (cas.want == "success" && err != nil) || (cas.want == "fail" && err == nil) {
+                       t.Errorf("Read() => got %v, want %s", err, cas.want)
+               }
+       }
+}