2 * Copyright (c) 2018 ZTE Corporation.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * and the Apache License 2.0 which both accompany this distribution,
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
7 * and http://www.apache.org/licenses/LICENSE-2.0
10 * ZTE - initial Project
20 func TestSetConsulAddress(t *testing.T) {
22 env, path, want string
32 want: `http://127.0.0.1:8500`,
35 env: "testEnvWithPath",
37 want: `testEnvWithPath`,
42 want: `http://localhost:8500`,
46 path: `controller.go`,
47 want: `http://localhost:8500`,
51 oldEnv := os.Getenv(models.EnvConsulAddress)
53 for _, cas := range cases {
54 os.Setenv(models.EnvConsulAddress, cas.env)
56 res := getConsulAddress(cas.path)
58 t.Errorf("getConsulAddress() => want %s, got %s", cas.want, res)
62 os.Setenv(models.EnvConsulAddress, oldEnv)
65 func TestLoadCfgInfo(t *testing.T) {
75 status: `path is empty`,
78 path: `controller.go`,
79 status: `yaml format error`,
83 for _, cas := range cases {
84 _, err := loadCfgInfo(cas.path)
85 if (cas.status == "success" && err != nil) || (cas.status != "success" && err == nil) {
86 t.Errorf("loadCfgInfo() => want %s, got %v", cas.status, err)