| 
									
										
										
										
											2016-06-10 04:21:28 +08:00
										 |  |  | package models | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/grafana/grafana/pkg/components/simplejson" | 
					
						
							|  |  |  | 	. "github.com/smartystreets/goconvey/convey" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestAlertingModelTest(t *testing.T) { | 
					
						
							|  |  |  | 	Convey("Testing Alerting model", t, func() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		json1, _ := simplejson.NewJson([]byte(`{ "field": "value" }`)) | 
					
						
							|  |  |  | 		json2, _ := simplejson.NewJson([]byte(`{ "field": "value" }`)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-11 16:26:48 +08:00
										 |  |  | 		rule1 := &Alert{ | 
					
						
							| 
									
										
										
										
											2016-08-12 16:12:04 +08:00
										 |  |  | 			Settings: json1, | 
					
						
							|  |  |  | 			Name:     "Namn", | 
					
						
							|  |  |  | 			Message:  "Message", | 
					
						
							| 
									
										
										
										
											2016-06-10 04:21:28 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-11 16:26:48 +08:00
										 |  |  | 		rule2 := &Alert{ | 
					
						
							| 
									
										
										
										
											2016-08-12 16:12:04 +08:00
										 |  |  | 			Settings: json2, | 
					
						
							|  |  |  | 			Name:     "Namn", | 
					
						
							|  |  |  | 			Message:  "Message", | 
					
						
							| 
									
										
										
										
											2016-06-10 04:21:28 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Convey("Testing AlertRule equals", func() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			So(rule1.ContainsUpdates(rule2), ShouldBeFalse) | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Convey("Changing the expression should contain update", func() { | 
					
						
							|  |  |  | 			json2, _ := simplejson.NewJson([]byte(`{ "field": "newValue" }`)) | 
					
						
							| 
									
										
										
										
											2016-06-13 21:18:19 +08:00
										 |  |  | 			rule1.Settings = json2 | 
					
						
							| 
									
										
										
										
											2016-06-10 04:21:28 +08:00
										 |  |  | 			So(rule1.ContainsUpdates(rule2), ShouldBeTrue) | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | } |