-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAliyunApi_test.go
130 lines (122 loc) · 3.18 KB
/
AliyunApi_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// This file is auto-generated, don't edit it. Thanks.
package utils
import (
"encoding/json"
"fmt"
"github.com/mitchellh/mapstructure"
"gopkg.in/yaml.v3"
"horizon/config"
"horizon/model"
"testing"
)
func TestListClusters(t *testing.T) {
clusters, err := ListClusters(1, 10, "")
var totalCount int64
var configCenterInstances []model.ConfigCenterInstance
if err != nil {
return
}
body := clusters["body"]
if b, ok := body.(map[string]interface{}); ok {
instanceData := b["Data"]
if tc, isInt := b["TotalCount"].(json.Number); isInt {
totalCount, _ = tc.Int64()
}
if d, ok2 := instanceData.([]interface{}); ok2 {
for _, cluster := range d {
var configCenterInstance model.ConfigCenterInstance
err := mapstructure.Decode(cluster, &configCenterInstance)
if err != nil {
return
}
configCenterInstances = append(configCenterInstances, configCenterInstance)
}
}
}
fmt.Println("totalCount", totalCount)
fmt.Println("configCenterInstances", configCenterInstances)
}
func TestListNacosConfigs(t *testing.T) {
configs, err := ListNacosConfigs(1, 10, "", "", "")
var totalCount int64
var configCenterInstanceConfigs []model.ConfigCenterInstanceConfig
if err != nil {
return
}
body := configs["body"]
if b, ok := body.(map[string]interface{}); ok {
instanceConfigData := b["Configurations"]
if tc, isInt := b["TotalCount"].(json.Number); isInt {
totalCount, _ = tc.Int64()
}
if d, ok2 := instanceConfigData.([]interface{}); ok2 {
for _, cluster := range d {
var configCenterInstanceConfig model.ConfigCenterInstanceConfig
err := mapstructure.Decode(cluster, &configCenterInstanceConfig)
if err != nil {
return
}
configCenterInstanceConfigs = append(configCenterInstanceConfigs, configCenterInstanceConfig)
}
}
}
fmt.Println("totalCount", totalCount)
fmt.Println("configCenterInstanceConfigs", configCenterInstanceConfigs)
}
func TestGetNacosConfig(t *testing.T) {
configs, err := GetNacosConfig("", "", "", "")
var configCenterInstanceConfig model.ConfigCenterInstanceConfig
if err != nil {
return
}
body := configs["body"]
if b, ok := body.(map[string]interface{}); ok {
instanceConfigData := b["Configuration"]
err := mapstructure.Decode(instanceConfigData, &configCenterInstanceConfig)
if err != nil {
return
}
}
fmt.Println("configCenterInstanceConfig", configCenterInstanceConfig)
}
func TestDesensitizedYamlConfig(t *testing.T) {
content := ""
// var data map[string]interface{}
var dataNode yaml.Node
err := yaml.Unmarshal([]byte(content), &dataNode)
if err != nil {
return
}
flag := 0
iterNode(&dataNode, &flag)
marshal, err := yaml.Marshal(&dataNode)
if err != nil {
println(err.Error())
return
}
fmt.Println(marshal)
}
func iterNode(node *yaml.Node, flag *int) {
if node.Content != nil && len(node.Content) > 0 {
for _, n := range node.Content {
iterNode(n, flag)
}
} else {
if node.Value == "password" || node.Value == "appSecret" {
*flag = 1
return
}
if *flag == 1 {
node.Value = "******"
*flag = 0
}
}
}
func TestMain(m *testing.M) {
fmt.Println("begin")
help := HelpInit()
config.InitConfig(help.ConfigFile)
model.InitDb()
m.Run()
fmt.Println("end")
}