--- /dev/null
+/**
+ * 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 consul
+
+import (
+ "testing"
+)
+
+func TestSetConsulAddress(t *testing.T) {
+ cases := []struct {
+ path, want string
+ }{
+ {
+ path: cfgFilePath,
+ want: `http://127.0.0.1:8500`,
+ },
+ {
+ path: ``,
+ want: `http://localhost:8500`,
+ },
+ {
+ path: `controller.go`,
+ want: `http://localhost:8500`,
+ },
+ }
+
+ for _, cas := range cases {
+ res := getConsulAddress(cas.path)
+ if res != cas.want {
+ t.Errorf("getConsulAddress() => want %s, got %s", cas.want, res)
+ }
+ }
+}
+
+func TestLoadCfgInfo(t *testing.T) {
+ cases := []struct {
+ path, status string
+ }{
+ {
+ path: cfgFilePath,
+ status: `success`,
+ },
+ {
+ path: ``,
+ status: `path is empty`,
+ },
+ {
+ path: `controller.go`,
+ status: `yaml format error`,
+ },
+ }
+
+ for _, cas := range cases {
+ _, err := loadCfgInfo(cas.path)
+ if (cas.status == "success" && err != nil) || (cas.status != "success" && err == nil) {
+ t.Errorf("loadCfgInfo() => want %s, got %v", cas.status, err)
+ }
+ }
+}
package log
import (
- "apiroute/util"
+ "msb2pilot/util"
"os"
"strings"
"testing"
)
func TestCheckLogDir(t *testing.T) {
- pathSep := string(os.PathSeparator)
cases := []struct {
path string
exist bool
exist: false,
},
{
- path: `.` + pathSep + `test` + pathSep + `test.log`,
+ path: `.` + util.PathSep + `test` + util.PathSep + `test.log`,
exist: true,
},
}
for _, cas := range cases {
checkLogDir(cas.path)
- index := strings.LastIndex(cas.path, pathSep)
+ index := strings.LastIndex(cas.path, util.PathSep)
if cas.exist && !util.FileExists(cas.path[0:index]) {
t.Errorf("checkLogDir() => dir not exist, want %s", cas.path)
}
}
func TestLoadCustom(t *testing.T) {
- pathSep := string(os.PathSeparator)
cases := []struct {
path string
want string
}{
{
- path: `..` + pathSep + "conf" + pathSep + cfgFileName,
+ path: `..` + util.PathSep + "conf" + util.PathSep + cfgFileName,
want: "success",
},
{