mirror of https://github.com/grafana/grafana.git
				
				
				
			Alerting: Refactor of state manager tests (#72849)
* calculate cacheID instead of literals * use mocked clocks * advance clocks with the eval results * use clearer timestamp aliases * make expected state labels be more clear to read Co-authored-by: Matthew Jacobson <matthew.jacobson@grafana.com>
This commit is contained in:
		
							parent
							
								
									9328febbab
								
							
						
					
					
						commit
						0053b07885
					
				|  | @ -67,6 +67,13 @@ func WithState(state State) ResultMutator { | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func WithError(err error) ResultMutator { | ||||||
|  | 	return func(r *Result) { | ||||||
|  | 		r.State = Error | ||||||
|  | 		r.Error = err | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func WithLabels(labels data.Labels) ResultMutator { | func WithLabels(labels data.Labels) ResultMutator { | ||||||
| 	return func(r *Result) { | 	return func(r *Result) { | ||||||
| 		r.Instance = labels | 		r.Instance = labels | ||||||
|  |  | ||||||
|  | @ -179,6 +179,54 @@ func WithFor(duration time.Duration) AlertRuleMutator { | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func WithForNTimes(timesOfInterval int64) AlertRuleMutator { | ||||||
|  | 	return func(rule *AlertRule) { | ||||||
|  | 		rule.For = time.Duration(rule.IntervalSeconds*timesOfInterval) * time.Second | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func WithNoDataExecAs(nodata NoDataState) AlertRuleMutator { | ||||||
|  | 	return func(rule *AlertRule) { | ||||||
|  | 		rule.NoDataState = nodata | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func WithErrorExecAs(err ExecutionErrorState) AlertRuleMutator { | ||||||
|  | 	return func(rule *AlertRule) { | ||||||
|  | 		rule.ExecErrState = err | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func WithAnnotations(a data.Labels) AlertRuleMutator { | ||||||
|  | 	return func(rule *AlertRule) { | ||||||
|  | 		rule.Annotations = a | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func WithAnnotation(key, value string) AlertRuleMutator { | ||||||
|  | 	return func(rule *AlertRule) { | ||||||
|  | 		if rule.Annotations == nil { | ||||||
|  | 			rule.Annotations = data.Labels{} | ||||||
|  | 		} | ||||||
|  | 		rule.Annotations[key] = value | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func WithLabels(a data.Labels) AlertRuleMutator { | ||||||
|  | 	return func(rule *AlertRule) { | ||||||
|  | 		rule.Labels = a | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func WithLabel(key, value string) AlertRuleMutator { | ||||||
|  | 	return func(rule *AlertRule) { | ||||||
|  | 		if rule.Labels == nil { | ||||||
|  | 			rule.Labels = data.Labels{} | ||||||
|  | 		} | ||||||
|  | 		rule.Labels[key] = value | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func GenerateAlertLabels(count int, prefix string) data.Labels { | func GenerateAlertLabels(count int, prefix string) data.Labels { | ||||||
| 	labels := make(data.Labels, count) | 	labels := make(data.Labels, count) | ||||||
| 	for i := 0; i < count; i++ { | 	for i := 0; i < count; i++ { | ||||||
|  |  | ||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Loading…
	
		Reference in New Issue