@@ -18,7 +18,7 @@ func TestAccResourceJobAlert(t *testing.T) {
18
18
testutils .CheckCloudInstanceTestsEnabled (t )
19
19
20
20
randomJobName := acctest .RandomWithPrefix ("Test Job" )
21
- randomAlertName := acctest .RandomWithPrefix ("Test Job Alert" )
21
+ randomAlertName := acctest .RandomWithPrefix ("Test Alert" )
22
22
23
23
var job mlapi.Job
24
24
var alert mlapi.Alert
@@ -37,6 +37,28 @@ func TestAccResourceJobAlert(t *testing.T) {
37
37
Check : resource .ComposeTestCheckFunc (
38
38
testAccMLJobCheckExists ("grafana_machine_learning_job.test_alert_job" , & job ),
39
39
testAccMLJobAlertCheckExists ("grafana_machine_learning_alert.test_job_alert" , & job , & alert ),
40
+ resource .TestCheckResourceAttrSet ("grafana_machine_learning_alert.test_job_alert" , "id" ),
41
+ resource .TestCheckResourceAttr ("grafana_machine_learning_alert.test_job_alert" , "title" , randomAlertName ),
42
+ resource .TestCheckResourceAttr ("grafana_machine_learning_alert.test_job_alert" , "anomaly_condition" , "any" ),
43
+ resource .TestCheckResourceAttr ("grafana_machine_learning_alert.test_job_alert" , "threshold" , ">0.8" ),
44
+ resource .TestCheckResourceAttr ("grafana_machine_learning_alert.test_job_alert" , "window" , "15m" ),
45
+ ),
46
+ },
47
+ // Update the alert with a new anomaly conditon.
48
+ {
49
+ Config : testutils .TestAccExampleWithReplace (t , "resources/grafana_machine_learning_alert/resource.tf" , map [string ]string {
50
+ "Test Job" : randomJobName ,
51
+ "Test Alert" : randomAlertName ,
52
+ "\" any\" " : "\" low\" " ,
53
+ }),
54
+ Check : resource .ComposeTestCheckFunc (
55
+ testAccMLJobCheckExists ("grafana_machine_learning_job.test_alert_job" , & job ),
56
+ testAccMLJobAlertCheckExists ("grafana_machine_learning_alert.test_job_alert" , & job , & alert ),
57
+ resource .TestCheckResourceAttrSet ("grafana_machine_learning_alert.test_job_alert" , "id" ),
58
+ resource .TestCheckResourceAttr ("grafana_machine_learning_alert.test_job_alert" , "title" , randomAlertName ),
59
+ resource .TestCheckResourceAttr ("grafana_machine_learning_alert.test_job_alert" , "anomaly_condition" , "low" ),
60
+ resource .TestCheckResourceAttr ("grafana_machine_learning_alert.test_job_alert" , "threshold" , ">0.8" ),
61
+ resource .TestCheckResourceAttr ("grafana_machine_learning_alert.test_job_alert" , "window" , "15m" ),
40
62
),
41
63
},
42
64
{
@@ -54,8 +76,8 @@ func TestAccResourceJobAlert(t *testing.T) {
54
76
func TestAccResourceOutlierAlert (t * testing.T ) {
55
77
testutils .CheckCloudInstanceTestsEnabled (t )
56
78
57
- randomOutlierName := acctest .RandomWithPrefix ("Test Job " )
58
- randomAlertName := acctest .RandomWithPrefix ("Test Outlier Alert" )
79
+ randomOutlierName := acctest .RandomWithPrefix ("Test Outlier " )
80
+ randomAlertName := acctest .RandomWithPrefix ("Test Alert" )
59
81
60
82
var outlier mlapi.OutlierDetector
61
83
var alert mlapi.Alert
@@ -74,6 +96,22 @@ func TestAccResourceOutlierAlert(t *testing.T) {
74
96
Check : resource .ComposeTestCheckFunc (
75
97
testAccMLOutlierCheckExists ("grafana_machine_learning_outlier_detector.test_alert_outlier_detector" , & outlier ),
76
98
testAccMLOutlierAlertCheckExists ("grafana_machine_learning_alert.test_outlier_alert" , & outlier , & alert ),
99
+ resource .TestCheckResourceAttr ("grafana_machine_learning_alert.test_outlier_alert" , "title" , randomAlertName ),
100
+ resource .TestCheckResourceAttr ("grafana_machine_learning_alert.test_outlier_alert" , "window" , "1h" ),
101
+ ),
102
+ },
103
+ // Test updating the window.
104
+ {
105
+ Config : testutils .TestAccExampleWithReplace (t , "resources/grafana_machine_learning_alert/outlier_alert.tf" , map [string ]string {
106
+ "Test Outlier" : randomOutlierName ,
107
+ "Test Alert" : randomAlertName ,
108
+ "\" 1h\" " : "\" 30m\" " ,
109
+ }),
110
+ Check : resource .ComposeTestCheckFunc (
111
+ testAccMLOutlierCheckExists ("grafana_machine_learning_outlier_detector.test_alert_outlier_detector" , & outlier ),
112
+ testAccMLOutlierAlertCheckExists ("grafana_machine_learning_alert.test_outlier_alert" , & outlier , & alert ),
113
+ resource .TestCheckResourceAttr ("grafana_machine_learning_alert.test_outlier_alert" , "title" , randomAlertName ),
114
+ resource .TestCheckResourceAttr ("grafana_machine_learning_alert.test_outlier_alert" , "window" , "30m" ),
77
115
),
78
116
},
79
117
{
0 commit comments