@@ -2,6 +2,8 @@ package syntheticmonitoring_test
2
2
3
3
import (
4
4
"context"
5
+ "os"
6
+ "path/filepath"
5
7
"regexp"
6
8
"strconv"
7
9
"testing"
@@ -11,6 +13,7 @@ import (
11
13
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
12
14
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
13
15
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
16
+ "github.com/stretchr/testify/require"
14
17
)
15
18
16
19
func TestAccResourceCheck_dns (t * testing.T ) {
@@ -368,10 +371,17 @@ func TestAccResourceCheck_multihttp(t *testing.T) {
368
371
func TestAccResourceCheck_scripted (t * testing.T ) {
369
372
testutils .CheckCloudInstanceTestsEnabled (t )
370
373
374
+ // Find and replace the path.module since it's not available in the test environment
375
+ scriptFilepathAbs , err := filepath .Abs ("../../../examples/resources/grafana_synthetic_monitoring_check" )
376
+ require .NoError (t , err )
377
+ scriptFileContent , err := os .ReadFile (filepath .Join (scriptFilepathAbs , "script.js" ))
378
+ require .NoError (t , err )
379
+
371
380
// Inject random job names to avoid conflicts with other tests
372
381
jobName := acctest .RandomWithPrefix ("scripted" )
373
382
nameReplaceMap := map [string ]string {
374
- `"Scripted defaults"` : strconv .Quote (jobName ),
383
+ `"Validate homepage"` : strconv .Quote (jobName ),
384
+ "${path.module}" : scriptFilepathAbs ,
375
385
}
376
386
resource .ParallelTest (t , resource.TestCase {
377
387
ProtoV5ProviderFactories : testutils .ProtoV5ProviderFactories ,
@@ -382,11 +392,11 @@ func TestAccResourceCheck_scripted(t *testing.T) {
382
392
resource .TestCheckResourceAttrSet ("grafana_synthetic_monitoring_check.scripted" , "id" ),
383
393
resource .TestCheckResourceAttrSet ("grafana_synthetic_monitoring_check.scripted" , "tenant_id" ),
384
394
resource .TestCheckResourceAttr ("grafana_synthetic_monitoring_check.scripted" , "job" , jobName ),
385
- resource .TestCheckResourceAttr ("grafana_synthetic_monitoring_check.scripted" , "target" , "scripted target " ),
395
+ resource .TestCheckResourceAttr ("grafana_synthetic_monitoring_check.scripted" , "target" , "https://grafana.com/ " ),
386
396
resource .TestCheckResourceAttr ("grafana_synthetic_monitoring_check.scripted" , "timeout" , "5000" ), // scripted has a default timeout of 5000
387
397
resource .TestCheckResourceAttrSet ("grafana_synthetic_monitoring_check.scripted" , "probes.0" ),
388
- resource .TestCheckResourceAttr ("grafana_synthetic_monitoring_check.scripted" , "labels.foo " , "bar " ),
389
- resource .TestCheckResourceAttr ("grafana_synthetic_monitoring_check.scripted" , "settings.0.scripted.0.script" , "console.log('Hello, world!')" ),
398
+ resource .TestCheckResourceAttr ("grafana_synthetic_monitoring_check.scripted" , "labels.environment " , "production " ),
399
+ resource .TestCheckResourceAttr ("grafana_synthetic_monitoring_check.scripted" , "settings.0.scripted.0.script" , string ( scriptFileContent ) ),
390
400
),
391
401
},
392
402
{
0 commit comments