@@ -3,6 +3,7 @@ package gapi
33import  (
44	"encoding/json" 
55	"testing" 
6+ 	"time" 
67
78	"github.com/gobs/pretty" 
89)
@@ -26,17 +27,17 @@ func TestAlertRules(t *testing.T) {
2627		server , client  :=  gapiTestTools (t , 200 , getAlertRuleGroupJSON )
2728		defer  server .Close ()
2829
29- 		group , err  :=  client .AlertRuleGroup ("d8-gk06nz " , "test " )
30+ 		group , err  :=  client .AlertRuleGroup ("project_test " , "eval_group_1 " )
3031
3132		if  err  !=  nil  {
3233			t .Error (err )
3334		}
3435		t .Log (pretty .PrettyFormat (group ))
35- 		if  group .Title  !=  "test "  {
36- 			t .Errorf ("incorrect title - expected %s got %s" , "test " , group .Title )
36+ 		if  group .Title  !=  "eval_group_1 "  {
37+ 			t .Errorf ("incorrect title - expected %s got %s" , "eval_group_1 " , group .Title )
3738		}
38- 		if  group .FolderUID  !=  "d8-gk06nz "  {
39- 			t .Errorf ("incorrect folderUID - expected %s got %s" , "d8-gk06nz " , group .FolderUID )
39+ 		if  group .FolderUID  !=  "project_test "  {
40+ 			t .Errorf ("incorrect folderUID - expected %s got %s" , "project_test " , group .FolderUID )
4041		}
4142		if  len (group .Rules ) !=  1  {
4243			t .Errorf ("wrong number of rules, got %d" , len (group .Rules ))
@@ -138,7 +139,7 @@ func createAlertRule() AlertRule {
138139		OrgID :        1 ,
139140		RuleGroup :    "eval_group_1" ,
140141		Title :        "Always in alarm" ,
141- 		ForDuration :  0 ,
142+ 		ForDuration :  60   *   time . Second ,
142143	}
143144}
144145
@@ -165,7 +166,7 @@ const writeAlertRuleJSON = `
165166	"orgId": 1, 
166167	"ruleGroup": "eval_group_1", 
167168	"title": "Always in alarm", 
168- 	"for": 0  
169+ 	"for": "1m"  
169170} 
170171` 
171172
@@ -180,95 +181,84 @@ const getAlertRuleJSON = `
180181	"uid": "123abcd", 
181182	"ruleGroup": "eval_group_1", 
182183	"title": "Always in alarm", 
183- 	"for": 0  
184+ 	"for": "1m"  
184185} 
185186` 
186187
187188const  getAlertRuleGroupJSON  =  ` 
188189{ 
189- 	"title": "test ", 
190- 	"folderUid": "d8-gk06nz ", 
190+ 	"title": "eval_group_1 ", 
191+ 	"folderUid": "project_test ", 
191192	"interval": 60, 
192193	"rules": [ 
193- 		{ 
194- 			"ID": 1, 
195- 			"OrgID": 1, 
196- 			"Title": "abc", 
197- 			"Condition": "B", 
198- 			"Data": [ 
199- 				{ 
200- 					"refId": "A", 
201- 					"queryType": "", 
202- 					"relativeTimeRange": { 
203- 						"from": 600, 
204- 						"to": 0 
194+ 	  { 
195+ 		"id": 212, 
196+ 		"uid": "HW7RYci4z", 
197+ 		"orgID": 1, 
198+ 		"folderUID": "project_test", 
199+ 		"ruleGroup": "eval_group_1", 
200+ 		"title": "Always in alarm", 
201+ 		"condition": "A", 
202+ 		"data": [ 
203+ 		  { 
204+ 			"refId": "A", 
205+ 			"queryType": "", 
206+ 			"relativeTimeRange": { 
207+ 			  "from": 0, 
208+ 			  "to": 0 
209+ 			}, 
210+ 			"datasourceUid": "-100", 
211+ 			"model": { 
212+ 			  "datasourceUid": "-100", 
213+ 			  "intervalMs": 1000, 
214+ 			  "maxDataPoints": 43200, 
215+ 			  "model": { 
216+ 				"conditions": [ 
217+ 				  { 
218+ 					"evaluator": { 
219+ 					  "params": [ 
220+ 						0, 
221+ 						0 
222+ 					  ], 
223+ 					  "type": "gt" 
205224					}, 
206- 					"datasourceUid": "PD8C576611E62080A", 
207- 					"model": { 
208- 						"hide": false, 
209- 						"intervalMs": 1000, 
210- 						"maxDataPoints": 43200, 
211- 						"refId": "A" 
212- 					} 
213- 				}, 
214- 				{ 
215- 					"refId": "B", 
216- 					"queryType": "", 
217- 					"relativeTimeRange": { 
218- 						"from": 0, 
219- 						"to": 0 
225+ 					"operator": { 
226+ 					  "type": "and" 
220227					}, 
221- 					"datasourceUid": "-100", 
222- 					"model": { 
223- 						"conditions": [ 
224- 							{ 
225- 								"evaluator": { 
226- 									"params": [ 
227- 										3 
228- 									], 
229- 									"type": "gt" 
230- 								}, 
231- 								"operator": { 
232- 									"type": "and" 
233- 								}, 
234- 								"query": { 
235- 									"params": [ 
236- 										"A" 
237- 									] 
238- 								}, 
239- 								"reducer": { 
240- 									"params": [], 
241- 									"type": "last" 
242- 								}, 
243- 								"type": "query" 
244- 							} 
245- 						], 
246- 						"datasource": { 
247- 							"type": "__expr__", 
248- 							"uid": "-100" 
249- 						}, 
250- 						"hide": false, 
251- 						"intervalMs": 1000, 
252- 						"maxDataPoints": 43200, 
253- 						"refId": "B", 
254- 						"type": "classic_conditions" 
255- 					} 
256- 				} 
257- 			], 
258- 			"Updated": "2022-07-07T16:23:56-05:00", 
259- 			"IntervalSeconds": 60, 
260- 			"Version": 1, 
261- 			"UID": "hsXgz0enz", 
262- 			"NamespaceUID": "d8-gk06nz", 
263- 			"DashboardUID": null, 
264- 			"PanelID": null, 
265- 			"RuleGroup": "test", 
266- 			"RuleGroupIndex": 1, 
267- 			"NoDataState": "NoData", 
268- 			"ExecErrState": "Alerting", 
269- 			"For": 300000000000, 
270- 			"Annotations": {}, 
271- 			"Labels": {} 
272- 		} 
228+ 					"query": { 
229+ 					  "params": [] 
230+ 					}, 
231+ 					"reducer": { 
232+ 					  "params": [], 
233+ 					  "type": "avg" 
234+ 					}, 
235+ 					"type": "query" 
236+ 				  } 
237+ 				], 
238+ 				"datasource": { 
239+ 				  "type": "__expr__", 
240+ 				  "uid": "__expr__" 
241+ 				}, 
242+ 				"expression": "1 == 1", 
243+ 				"hide": false, 
244+ 				"intervalMs": 1000, 
245+ 				"maxDataPoints": 43200, 
246+ 				"refId": "A", 
247+ 				"type": "math" 
248+ 			  }, 
249+ 			  "queryType": "", 
250+ 			  "refId": "A", 
251+ 			  "relativeTimeRange": { 
252+ 				"from": 0, 
253+ 				"to": 0 
254+ 			  } 
255+ 			} 
256+ 		  } 
257+ 		], 
258+ 		"updated": "2022-08-12T15:44:43-05:00", 
259+ 		"noDataState": "OK", 
260+ 		"execErrState": "OK", 
261+ 		"for": "2m" 
262+ 	  } 
273263	] 
274- }` 
264+    }`
0 commit comments