summaryrefslogtreecommitdiffstats
path: root/msb2pilot/src
diff options
context:
space:
mode:
authorLvbo163 <lv.bo163@zte.com.cn>2018-07-31 11:32:15 +0800
committerLvbo163 <lv.bo163@zte.com.cn>2018-07-31 11:32:15 +0800
commit1c419c915a7860f7cc82d1ecd10b74d4f46d2818 (patch)
tree4378b8f93047f1ac57b93bfa308a62df7ea52903 /msb2pilot/src
parent6af2e407eb00d3e612abc9221efa2ef45563c1af (diff)
add ut for file util
add ut for file util Issue-ID: MSB-233 Change-Id: I5f7271d392943fdec244894b4340ec63cf798e3d Signed-off-by: Lvbo163 <lv.bo163@zte.com.cn>
Diffstat (limited to 'msb2pilot/src')
-rw-r--r--msb2pilot/src/msb2pilot/util/file_test.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/msb2pilot/src/msb2pilot/util/file_test.go b/msb2pilot/src/msb2pilot/util/file_test.go
new file mode 100644
index 0000000..e2fcc99
--- /dev/null
+++ b/msb2pilot/src/msb2pilot/util/file_test.go
@@ -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)
+ }
+ }
+}