@@ -51,3 +51,92 @@ func TestSource_IsDefaultGroup(t *testing.T) {
5151 assert .True (t , sources [1 ].IsDefaultGroup ())
5252 assert .False (t , sources [2 ].IsDefaultGroup ())
5353}
54+
55+
56+ func TestSource_Equal (t * testing.T ) {
57+ var correctInterval float64 = 60
58+ var incorrectInterval float64 = 10
59+
60+ s1 := sources.Source {
61+ Metrics : map [string ]float64 {"wal" : correctInterval },
62+ MetricsStandby : map [string ]float64 {"wal" : correctInterval },
63+ }
64+
65+ srcs := sources.Sources {
66+ {
67+ PresetMetrics : "basic" ,
68+ PresetMetricsStandby : "basic" ,
69+ },
70+ {
71+ PresetMetrics : "basic" ,
72+ PresetMetricsStandby : "basic" ,
73+ Metrics : map [string ]float64 {"wal" : correctInterval },
74+ MetricsStandby : map [string ]float64 {"wal" : correctInterval },
75+ },
76+ {
77+ PresetMetrics : "basic" ,
78+ PresetMetricsStandby : "basic" ,
79+ Metrics : map [string ]float64 {"wal" : incorrectInterval },
80+ MetricsStandby : map [string ]float64 {"wal" : incorrectInterval },
81+ },
82+ {
83+ Metrics : map [string ]float64 {"wal" : incorrectInterval },
84+ MetricsStandby : map [string ]float64 {"wal" : incorrectInterval },
85+ },
86+ {
87+ Metrics : map [string ]float64 {"wal" : correctInterval , "db_size" : correctInterval },
88+ MetricsStandby : map [string ]float64 {"wal" : correctInterval , "db_size" : correctInterval },
89+ },
90+ {
91+ Metrics : map [string ]float64 {"wal" : correctInterval },
92+ MetricsStandby : map [string ]float64 {"wal" : correctInterval },
93+ },
94+ }
95+
96+ assert .False (t , s1 .Equal (srcs [0 ]))
97+ assert .False (t , s1 .Equal (srcs [1 ]))
98+ assert .False (t , s1 .Equal (srcs [2 ]))
99+ assert .False (t , s1 .Equal (srcs [3 ]))
100+ assert .False (t , s1 .Equal (srcs [4 ]))
101+ assert .True (t , s1 .Equal (srcs [5 ]))
102+
103+ s1 = sources.Source {
104+ PresetMetrics : "basic" ,
105+ PresetMetricsStandby : "basic" ,
106+ Metrics : map [string ]float64 {"wal" : correctInterval },
107+ MetricsStandby : map [string ]float64 {"wal" : correctInterval },
108+ }
109+
110+ srcs = sources.Sources {
111+ {
112+ PresetMetrics : "basic" ,
113+ PresetMetricsStandby : "basic" ,
114+ },
115+ {
116+ PresetMetrics : "basic" ,
117+ PresetMetricsStandby : "basic" ,
118+ Metrics : map [string ]float64 {"wal" : incorrectInterval },
119+ MetricsStandby : map [string ]float64 {"wal" : incorrectInterval },
120+ },
121+ {
122+ PresetMetrics : "azure" ,
123+ PresetMetricsStandby : "azure" ,
124+ },
125+ {
126+ PresetMetrics : "azure" ,
127+ PresetMetricsStandby : "azure" ,
128+ Metrics : map [string ]float64 {"wal" : correctInterval },
129+ MetricsStandby : map [string ]float64 {"wal" : correctInterval },
130+ },
131+ {
132+ Metrics : map [string ]float64 {"wal" : correctInterval },
133+ MetricsStandby : map [string ]float64 {"wal" : correctInterval },
134+ },
135+ }
136+
137+ assert .True (t , s1 .Equal (srcs [0 ]))
138+ assert .True (t , s1 .Equal (srcs [1 ]))
139+ assert .False (t , s1 .Equal (srcs [2 ]))
140+ assert .False (t , s1 .Equal (srcs [3 ]))
141+ assert .False (t , s1 .Equal (srcs [4 ]))
142+ }
0 commit comments