1b0565335b6a6560a6c9ade7c992e2863abbad94
[msb/service-mesh.git] / msb2pilot / src / msb2pilot / consul / controller_test.go
1 /**
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
8  *
9  * Contributors:
10  *     ZTE - initial Project
11  */
12 package consul
13
14 import (
15         "testing"
16 )
17
18 func TestSetConsulAddress(t *testing.T) {
19         cases := []struct {
20                 path, want string
21         }{
22                 {
23                         path: cfgFilePath,
24                         want: `http://127.0.0.1:8500`,
25                 },
26                 {
27                         path: ``,
28                         want: `http://localhost:8500`,
29                 },
30                 {
31                         path: `controller.go`,
32                         want: `http://localhost:8500`,
33                 },
34         }
35
36         for _, cas := range cases {
37                 res := getConsulAddress(cas.path)
38                 if res != cas.want {
39                         t.Errorf("getConsulAddress() => want %s, got %s", cas.want, res)
40                 }
41         }
42 }
43
44 func TestLoadCfgInfo(t *testing.T) {
45         cases := []struct {
46                 path, status string
47         }{
48                 {
49                         path:   cfgFilePath,
50                         status: `success`,
51                 },
52                 {
53                         path:   ``,
54                         status: `path is empty`,
55                 },
56                 {
57                         path:   `controller.go`,
58                         status: `yaml format error`,
59                 },
60         }
61
62         for _, cas := range cases {
63                 _, err := loadCfgInfo(cas.path)
64                 if (cas.status == "success" && err != nil) || (cas.status != "success" && err == nil) {
65                         t.Errorf("loadCfgInfo() => want %s, got %v", cas.status, err)
66                 }
67         }
68 }