From: Lvbo163 Date: Tue, 31 Jul 2018 03:32:15 +0000 (+0800) Subject: add ut for file util X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=1c419c915a7860f7cc82d1ecd10b74d4f46d2818;p=msb%2Fservice-mesh.git add ut for file util add ut for file util Issue-ID: MSB-233 Change-Id: I5f7271d392943fdec244894b4340ec63cf798e3d Signed-off-by: Lvbo163 --- 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) + } + } +}