github.com/newrelic/newrelic-client-go@v1.1.0/pkg/synthetics/synthetics_api_integration_test.go (about)

     1  //go:build integration
     2  // +build integration
     3  
     4  package synthetics
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/require"
    10  
    11  	"fmt"
    12  	"os"
    13  
    14  	mock "github.com/newrelic/newrelic-client-go/pkg/testhelpers"
    15  )
    16  
    17  var tv bool = true
    18  
    19  func TestSyntheticsSecureCredential_Basic(t *testing.T) {
    20  	t.Parallel()
    21  
    22  	testAccountID, err := mock.GetTestAccountID()
    23  	if err != nil {
    24  		t.Skipf("%s", err)
    25  	}
    26  
    27  	a := newIntegrationTestClient(t)
    28  
    29  	// Create a secure credential
    30  	createResp, err := a.SyntheticsCreateSecureCredential(testAccountID, "test secure credential", "TEST", "secure value")
    31  	require.NoError(t, err)
    32  	require.NotNil(t, createResp)
    33  
    34  	// Update secure credential
    35  	updateResp, err := a.SyntheticsUpdateSecureCredential(testAccountID, "test secure credential", "TEST", "new secure value")
    36  	require.NoError(t, err)
    37  	require.NotNil(t, updateResp)
    38  
    39  	// Delete secure credential
    40  	deleteResp, err := a.SyntheticsDeleteSecureCredential(testAccountID, "TEST")
    41  
    42  	require.Nil(t, deleteResp)
    43  }
    44  
    45  //Test simple browser monitor
    46  func TestSyntheticsSimpleBrowserMonitor_Basic(t *testing.T) {
    47  	t.Parallel()
    48  
    49  	testAccountID, err := mock.GetTestAccountID()
    50  	if err != nil {
    51  		t.Skipf("%s", err)
    52  	}
    53  
    54  	a := newIntegrationTestClient(t)
    55  
    56  	monitorName := mock.RandSeq(5)
    57  
    58  	////Simple Browser monitor
    59  	//Input for simple browser monitor
    60  	simpleBrowserMonitorInput := SyntheticsCreateSimpleBrowserMonitorInput{
    61  		Locations: SyntheticsLocationsInput{
    62  			Public: []string{
    63  				"AP_SOUTH_1",
    64  			},
    65  		},
    66  		Name:   monitorName,
    67  		Period: SyntheticsMonitorPeriod(SyntheticsMonitorPeriodTypes.EVERY_5_MINUTES),
    68  		Status: SyntheticsMonitorStatus(SyntheticsMonitorStatusTypes.ENABLED),
    69  		Tags: []SyntheticsTag{
    70  			{
    71  				Key: "pineapple",
    72  				Values: []string{
    73  					"pizza",
    74  				},
    75  			},
    76  		},
    77  		Uri: "https://www.one.newrelic.com",
    78  		Runtime: SyntheticsRuntimeInput{
    79  			RuntimeType:        "CHROME_BROWSER",
    80  			RuntimeTypeVersion: SemVer("100"),
    81  			ScriptLanguage:     "JAVASCRIPT",
    82  		},
    83  		AdvancedOptions: SyntheticsSimpleBrowserMonitorAdvancedOptionsInput{
    84  			EnableScreenshotOnFailureAndScript: &tv,
    85  			ResponseValidationText:             "SUCCESS",
    86  			CustomHeaders: []SyntheticsCustomHeaderInput{
    87  				{
    88  					Name:  "Monitor",
    89  					Value: "synthetics",
    90  				},
    91  			},
    92  			UseTlsValidation: &tv,
    93  		},
    94  	}
    95  
    96  	//Test to create simple browser monitor
    97  	createSimpleBrowserMonitor, err := a.SyntheticsCreateSimpleBrowserMonitor(testAccountID, simpleBrowserMonitorInput)
    98  
    99  	require.NoError(t, err)
   100  	require.NotNil(t, createSimpleBrowserMonitor)
   101  	require.Equal(t, 0, len(createSimpleBrowserMonitor.Errors))
   102  
   103  	//Input for simple browser monitor for updating
   104  	simpleBrowserMonitorInputUpdated := SyntheticsUpdateSimpleBrowserMonitorInput{
   105  		AdvancedOptions: SyntheticsSimpleBrowserMonitorAdvancedOptionsInput{
   106  			CustomHeaders: []SyntheticsCustomHeaderInput{
   107  				{
   108  					Name:  "Monitor",
   109  					Value: "Synthetics",
   110  				},
   111  			},
   112  			EnableScreenshotOnFailureAndScript: &tv,
   113  			ResponseValidationText:             "Success",
   114  			UseTlsValidation:                   &tv,
   115  		},
   116  		Locations: SyntheticsLocationsInput{
   117  			Public: []string{
   118  				"AP_SOUTH_1",
   119  			},
   120  		},
   121  		Name:   monitorName + "-updated",
   122  		Period: SyntheticsMonitorPeriod(SyntheticsMonitorPeriodTypes.EVERY_5_MINUTES),
   123  		Status: SyntheticsMonitorStatus(SyntheticsMonitorStatusTypes.ENABLED),
   124  		Tags: []SyntheticsTag{
   125  			{
   126  				Key: "pineapple",
   127  				Values: []string{
   128  					"pizza",
   129  				},
   130  			},
   131  		},
   132  		Uri: "https://www.one.newrelic.com",
   133  		Runtime: SyntheticsRuntimeInput{
   134  			RuntimeType:        "CHROME_BROWSER",
   135  			RuntimeTypeVersion: SemVer("100"),
   136  			ScriptLanguage:     "JAVASCRIPT",
   137  		},
   138  	}
   139  
   140  	//Test to update simple browser monitor
   141  	updateSimpleBrowserMonitor, err := a.SyntheticsUpdateSimpleBrowserMonitor(createSimpleBrowserMonitor.Monitor.GUID, simpleBrowserMonitorInputUpdated)
   142  	require.NoError(t, err)
   143  	require.NotNil(t, updateSimpleBrowserMonitor)
   144  	require.Equal(t, 0, len(updateSimpleBrowserMonitor.Errors))
   145  
   146  	//Test to delete a simple browser monitor
   147  	deleteSimpleBrowserMonitor, err := a.SyntheticsDeleteMonitor(createSimpleBrowserMonitor.Monitor.GUID)
   148  	require.NotNil(t, deleteSimpleBrowserMonitor)
   149  	require.NoError(t, err)
   150  }
   151  
   152  //TestSyntheticsSimpleMonitor_Basic function to test simple monitor
   153  func TestSyntheticsSimpleMonitor_Basic(t *testing.T) {
   154  	t.Parallel()
   155  	testAccountID, err := mock.GetTestAccountID()
   156  	if err != nil {
   157  		t.Skipf("%s", err)
   158  	}
   159  
   160  	a := newIntegrationTestClient(t)
   161  
   162  	monitorName := mock.RandSeq(5)
   163  
   164  	////simple monitor
   165  	//Input for creating a simple monitor
   166  	simpleMonitorInput := SyntheticsCreateSimpleMonitorInput{
   167  		AdvancedOptions: SyntheticsSimpleMonitorAdvancedOptionsInput{
   168  			CustomHeaders: []SyntheticsCustomHeaderInput{
   169  				{
   170  					Name:  "Monitor",
   171  					Value: "Synthetics",
   172  				},
   173  			},
   174  			ResponseValidationText:  "Success",
   175  			RedirectIsFailure:       &tv,
   176  			ShouldBypassHeadRequest: &tv,
   177  			UseTlsValidation:        &tv,
   178  		},
   179  		Locations: SyntheticsLocationsInput{
   180  			Public: []string{
   181  				"AP_SOUTH_1",
   182  			},
   183  		},
   184  		Name:   monitorName,
   185  		Period: SyntheticsMonitorPeriod(SyntheticsMonitorPeriodTypes.EVERY_5_MINUTES),
   186  		Status: SyntheticsMonitorStatus(SyntheticsMonitorStatusTypes.ENABLED),
   187  		Tags: []SyntheticsTag{
   188  			{
   189  				Key: "pineapple",
   190  				Values: []string{
   191  					"pizza",
   192  				},
   193  			},
   194  		},
   195  		Uri: "https://www.one.newrelic.com",
   196  	}
   197  
   198  	//Test to create simple monitor
   199  	createSimpleMonitor, err := a.SyntheticsCreateSimpleMonitor(testAccountID, simpleMonitorInput)
   200  
   201  	require.NoError(t, err)
   202  	require.NotNil(t, createSimpleMonitor)
   203  	require.Equal(t, 0, len(createSimpleMonitor.Errors))
   204  
   205  	//Input to update simple monitor
   206  	simpleMonitorInputUpdated := SyntheticsUpdateSimpleMonitorInput{
   207  		AdvancedOptions: SyntheticsSimpleMonitorAdvancedOptionsInput{
   208  			CustomHeaders: []SyntheticsCustomHeaderInput{
   209  				{
   210  					Name:  "Monitors",
   211  					Value: "Synthetics",
   212  				},
   213  			},
   214  			ResponseValidationText:  "Success",
   215  			RedirectIsFailure:       &tv,
   216  			ShouldBypassHeadRequest: &tv,
   217  			UseTlsValidation:        &tv,
   218  		},
   219  		Locations: SyntheticsLocationsInput{
   220  			Public: []string{
   221  				"AP_SOUTH_1",
   222  			},
   223  		},
   224  		Name:   monitorName + "-updated",
   225  		Period: SyntheticsMonitorPeriod(SyntheticsMonitorPeriodTypes.EVERY_5_MINUTES),
   226  		Status: SyntheticsMonitorStatus(SyntheticsMonitorStatusTypes.ENABLED),
   227  		Tags: []SyntheticsTag{
   228  			{
   229  				Key: "pineapple",
   230  				Values: []string{
   231  					"pizza",
   232  				},
   233  			},
   234  		},
   235  		Uri: "https://www.one.newrelic.com",
   236  	}
   237  
   238  	//Test to update simple monitor
   239  	updateSimpleMonitor, err := a.SyntheticsUpdateSimpleMonitor(createSimpleMonitor.Monitor.GUID, simpleMonitorInputUpdated)
   240  	require.NoError(t, err)
   241  	require.NotNil(t, updateSimpleMonitor)
   242  	require.Equal(t, 0, len(updateSimpleMonitor.Errors))
   243  
   244  	//Test to delete simple monitor
   245  	deleteSimpleMonitor, err := a.SyntheticsDeleteMonitor(createSimpleMonitor.Monitor.GUID)
   246  	require.NotNil(t, deleteSimpleMonitor)
   247  	require.NoError(t, err)
   248  }
   249  
   250  //TestSyntheticsScriptApiMonitor_Basic to test the script api monitor
   251  func TestSyntheticsScriptApiMonitor_Basic(t *testing.T) {
   252  	t.Parallel()
   253  
   254  	testAccountID, err := mock.GetTestAccountID()
   255  	if err != nil {
   256  		t.Skipf("%s", err)
   257  	}
   258  
   259  	a := newIntegrationTestClient(t)
   260  
   261  	monitorName := mock.RandSeq(5)
   262  
   263  	////Scripted API monitor
   264  	apiScript := fmt.Sprintf(`
   265  		const myAccountId = '%s';
   266  		const myAPIKey = '%s';
   267  		const options = {
   268  		// Define endpoint URI, https://api.eu.newrelic.com/graphql for EU accounts
   269  		uri: 'https://api.newrelic.com/graphql',
   270  		headers: {
   271  		'API-key': myAPIKey,
   272  		'Content-Type': 'application/json',
   273  		},
   274  		body: JSON.stringify({
   275  		query: "
   276  		query getNrqlResults($accountId: Int!, $nrql: Nrql!) {
   277  		actor {
   278  		account(id: $accountId) {
   279  		nrql(query: $nrql) {results}}}}",
   280  		variables: {accountId: Number(myAccountId),nrql: 'SELECT average(duration) FROM Transaction'}})};
   281  
   282  		// Define expected results using callback function
   283  		function callback(err, response, body) {
   284  		// Log JSON results from endpoint to Synthetics console
   285  		console.log(body);
   286  		console.log('Script execution completed');
   287  		}
   288  
   289  		// Make POST request, passing in options and callback
   290  		$http.post(options, callback);
   291  		`, os.Getenv("NEW_RELIC_ACCOUNT_ID"), os.Getenv("NEW_RELIC_API_KEY"))
   292  
   293  	//input for script api monitor
   294  	scriptApiMonitorInput := SyntheticsCreateScriptAPIMonitorInput{
   295  		Locations: SyntheticsScriptedMonitorLocationsInput{
   296  			Public: []string{
   297  				"AP_SOUTH_1",
   298  			},
   299  		},
   300  		Name:   monitorName,
   301  		Period: SyntheticsMonitorPeriod(SyntheticsMonitorPeriodTypes.EVERY_5_MINUTES),
   302  		Status: SyntheticsMonitorStatus(SyntheticsMonitorStatusTypes.ENABLED),
   303  		Script: apiScript,
   304  		Tags: []SyntheticsTag{
   305  			{
   306  				Key: "pineapple",
   307  				Values: []string{
   308  					"pizza",
   309  				},
   310  			},
   311  		},
   312  		Runtime: SyntheticsRuntimeInput{
   313  			RuntimeTypeVersion: SemVer("16.10"),
   314  			RuntimeType:        "NODE_API",
   315  			ScriptLanguage:     "JAVASCRIPT",
   316  		},
   317  	}
   318  
   319  	//Test to Create scripted api monitor
   320  	createScriptApiMonitor, err := a.SyntheticsCreateScriptAPIMonitor(testAccountID, scriptApiMonitorInput)
   321  	require.NoError(t, err)
   322  	require.NotNil(t, createScriptApiMonitor)
   323  	require.Equal(t, 0, len(createScriptApiMonitor.Errors))
   324  
   325  	//input to update script api monitor
   326  	updatedScriptApiMonitorInput := SyntheticsUpdateScriptAPIMonitorInput{
   327  		Locations: SyntheticsScriptedMonitorLocationsInput{
   328  			Public: []string{
   329  				"AP_SOUTH_1",
   330  			},
   331  		},
   332  		Name:   monitorName + "-updated",
   333  		Period: SyntheticsMonitorPeriod(SyntheticsMonitorPeriodTypes.EVERY_5_MINUTES),
   334  		Status: SyntheticsMonitorStatus(SyntheticsMonitorStatusTypes.ENABLED),
   335  		Script: apiScript,
   336  		Tags: []SyntheticsTag{
   337  			{
   338  				Key: "pineapple",
   339  				Values: []string{
   340  					"pizza",
   341  				},
   342  			},
   343  		},
   344  		Runtime: SyntheticsRuntimeInput{
   345  			RuntimeTypeVersion: SemVer("16.10"),
   346  			RuntimeType:        "NODE_API",
   347  			ScriptLanguage:     "JAVASCRIPT",
   348  		},
   349  	}
   350  
   351  	//Test to update scripted api monitor
   352  	updateScriptApiMonitor, err := a.SyntheticsUpdateScriptAPIMonitor(createScriptApiMonitor.Monitor.GUID, updatedScriptApiMonitorInput)
   353  	require.NoError(t, err)
   354  	require.NotNil(t, updateScriptApiMonitor)
   355  	require.Equal(t, 0, len(updateScriptApiMonitor.Errors))
   356  
   357  	//Test to delete scripted api monitor
   358  	deleteScriptApiMonitor, err := a.SyntheticsDeleteMonitor(createScriptApiMonitor.Monitor.GUID)
   359  	require.NoError(t, err)
   360  	require.NotNil(t, deleteScriptApiMonitor)
   361  }
   362  
   363  //TestSyntheticsScriptBrowserMonitor_Basic function to test script browser monitor
   364  func TestSyntheticsScriptBrowserMonitor_Basic(t *testing.T) {
   365  	t.Parallel()
   366  	testAccountID, err := mock.GetTestAccountID()
   367  	if err != nil {
   368  		t.Skipf("%s", err)
   369  	}
   370  
   371  	a := newIntegrationTestClient(t)
   372  
   373  	monitorName := mock.RandSeq(5)
   374  
   375  	//Input to create script browser monitor
   376  	scriptBrowserMonitorInput := SyntheticsCreateScriptBrowserMonitorInput{
   377  		AdvancedOptions: SyntheticsScriptBrowserMonitorAdvancedOptionsInput{
   378  			EnableScreenshotOnFailureAndScript: &tv,
   379  		},
   380  		Locations: SyntheticsScriptedMonitorLocationsInput{
   381  			Public: []string{
   382  				"AP_SOUTH_1",
   383  			},
   384  		},
   385  		Name:   monitorName,
   386  		Period: SyntheticsMonitorPeriod(SyntheticsMonitorPeriodTypes.EVERY_5_MINUTES),
   387  		Status: SyntheticsMonitorStatus(SyntheticsMonitorStatusTypes.ENABLED),
   388  		Runtime: SyntheticsRuntimeInput{
   389  			RuntimeTypeVersion: "100",
   390  			RuntimeType:        "CHROME_BROWSER",
   391  			ScriptLanguage:     "JAVASCRIPT",
   392  		},
   393  		Tags: []SyntheticsTag{
   394  			{
   395  				Key: "pineapple",
   396  				Values: []string{
   397  					"pizza",
   398  				},
   399  			},
   400  		},
   401  		Script: "var assert = require('assert');\n\n$browser.get('https://one.newrelic.com')",
   402  	}
   403  
   404  	//test to create script browser monitor
   405  	createScriptBrowserMonitor, err := a.SyntheticsCreateScriptBrowserMonitor(testAccountID, scriptBrowserMonitorInput)
   406  	require.NoError(t, err)
   407  	require.NotNil(t, createScriptBrowserMonitor)
   408  	require.Equal(t, 0, len(createScriptBrowserMonitor.Errors))
   409  
   410  	//Input to update script browser monitor
   411  	updatedScriptBrowserMonitorInput := SyntheticsUpdateScriptBrowserMonitorInput{
   412  		AdvancedOptions: SyntheticsScriptBrowserMonitorAdvancedOptionsInput{
   413  			EnableScreenshotOnFailureAndScript: &tv,
   414  		},
   415  		Locations: SyntheticsScriptedMonitorLocationsInput{
   416  			Public: []string{
   417  				"AP_SOUTH_1",
   418  			},
   419  		},
   420  		Name:   monitorName + "-updated",
   421  		Period: SyntheticsMonitorPeriod(SyntheticsMonitorPeriodTypes.EVERY_5_MINUTES),
   422  		Status: SyntheticsMonitorStatus(SyntheticsMonitorStatusTypes.ENABLED),
   423  		Runtime: SyntheticsRuntimeInput{
   424  			RuntimeTypeVersion: "100",
   425  			RuntimeType:        "CHROME_BROWSER",
   426  			ScriptLanguage:     "JAVASCRIPT",
   427  		},
   428  		Tags: []SyntheticsTag{
   429  			{
   430  				Key: "pineapple",
   431  				Values: []string{
   432  					"script_browser_pizza",
   433  				},
   434  			},
   435  		},
   436  		Script: "var assert = require('assert');\n\n$browser.get('https://one.newrelic.com')",
   437  	}
   438  
   439  	//test to update script browser monitor
   440  	updateScriptBrowserMonitor, err := a.SyntheticsUpdateScriptBrowserMonitor(createScriptBrowserMonitor.Monitor.GUID, updatedScriptBrowserMonitorInput)
   441  	require.NoError(t, err)
   442  	require.NotNil(t, updateScriptBrowserMonitor)
   443  	require.Equal(t, 0, len(updateScriptBrowserMonitor.Errors))
   444  
   445  	//test to delete script browser monitor
   446  	deleteScriptBrowserMonitor, err := a.SyntheticsDeleteMonitor(createScriptBrowserMonitor.Monitor.GUID)
   447  	require.NoError(t, err)
   448  	require.NotNil(t, deleteScriptBrowserMonitor)
   449  }
   450  
   451  // Integration testing for private location
   452  func TestSyntheticsPrivateLocation_Basic(t *testing.T) {
   453  	t.Parallel()
   454  
   455  	testAccountID, err := mock.GetTestAccountID()
   456  	if err != nil {
   457  		t.Skipf("%s", err)
   458  	}
   459  
   460  	a := newIntegrationTestClient(t)
   461  
   462  	// Test to Create private location
   463  	createResp, err := a.SyntheticsCreatePrivateLocation(testAccountID, "test secure credential", "TEST", true)
   464  	require.NoError(t, err)
   465  	require.NotNil(t, createResp)
   466  
   467  	// Test to update private location
   468  	updateResp, err := a.SyntheticsUpdatePrivateLocation("test secure credential", createResp.GUID, true)
   469  	require.NoError(t, err)
   470  	require.NotNil(t, updateResp)
   471  
   472  	// Test to purge private location queue
   473  	purgeresp, err := a.SyntheticsPurgePrivateLocationQueue(createResp.GUID)
   474  	require.NotNil(t, purgeresp)
   475  
   476  	// Test to delete private location
   477  	deleteResp, err := a.SyntheticsDeletePrivateLocation(createResp.GUID)
   478  	require.NotNil(t, deleteResp)
   479  }
   480  
   481  func TestSyntheticsBrokenLinksMonitor_Basic(t *testing.T) {
   482  	t.Parallel()
   483  	testAccountID, err := mock.GetTestAccountID()
   484  	if err != nil {
   485  		t.Skipf("%s", err)
   486  	}
   487  
   488  	a := newIntegrationTestClient(t)
   489  
   490  	monitorName := fmt.Sprintf("client-integration-test-%s", mock.RandSeq(5))
   491  	monitorInput := SyntheticsCreateBrokenLinksMonitorInput{
   492  		Name:   monitorName,
   493  		Period: SyntheticsMonitorPeriod(SyntheticsMonitorPeriodTypes.EVERY_5_MINUTES),
   494  		Status: SyntheticsMonitorStatus(SyntheticsMonitorStatusTypes.DISABLED),
   495  		Locations: SyntheticsLocationsInput{
   496  			Public: []string{"AP_SOUTH_1"},
   497  		},
   498  		Tags: []SyntheticsTag{
   499  			{
   500  				Key:    "coconut",
   501  				Values: []string{"avocado"},
   502  			},
   503  		},
   504  		Uri: "https://www.google.com",
   505  	}
   506  
   507  	createdMonitor, err := a.SyntheticsCreateBrokenLinksMonitor(testAccountID, monitorInput)
   508  	require.NoError(t, err)
   509  	require.NotNil(t, createdMonitor)
   510  	require.Equal(t, 0, len(createdMonitor.Errors))
   511  
   512  	monitorNameUpdate := fmt.Sprintf("%s-updated", monitorName)
   513  	monitorUpdateInput := SyntheticsUpdateBrokenLinksMonitorInput{
   514  		Name:      fmt.Sprintf("%s-updated", monitorName),
   515  		Period:    monitorInput.Period,
   516  		Status:    monitorInput.Status,
   517  		Locations: monitorInput.Locations,
   518  		Tags:      monitorInput.Tags,
   519  		Uri:       fmt.Sprintf("%s?updated=true", monitorInput.Uri),
   520  	}
   521  
   522  	updatedMonitor, err := a.SyntheticsUpdateBrokenLinksMonitor(createdMonitor.Monitor.GUID, monitorUpdateInput)
   523  	require.NoError(t, err)
   524  	require.NotNil(t, updatedMonitor.Monitor)
   525  	require.Equal(t, 0, len(updatedMonitor.Errors))
   526  	require.Equal(t, monitorNameUpdate, updatedMonitor.Monitor.Name)
   527  	require.Equal(t, "https://www.google.com?updated=true", updatedMonitor.Monitor.Uri)
   528  	require.Equal(t, createdMonitor.Monitor.GUID, updatedMonitor.Monitor.GUID)
   529  
   530  	deletedMonitor, err := a.SyntheticsDeleteMonitor(createdMonitor.Monitor.GUID)
   531  	require.NoError(t, err)
   532  	require.NotNil(t, deletedMonitor)
   533  	require.Equal(t, createdMonitor.Monitor.GUID, deletedMonitor.DeletedGUID)
   534  }
   535  
   536  func TestSyntheticsCertCheckMonitor_Basic(t *testing.T) {
   537  	t.Parallel()
   538  	testAccountID, err := mock.GetTestAccountID()
   539  	if err != nil {
   540  		t.Skipf("%s", err)
   541  	}
   542  
   543  	a := newIntegrationTestClient(t)
   544  
   545  	monitorName := fmt.Sprintf("client-integration-test-%s", mock.RandSeq(5))
   546  	monitorInput := SyntheticsCreateCertCheckMonitorInput{
   547  		Name:   monitorName,
   548  		Period: SyntheticsMonitorPeriod(SyntheticsMonitorPeriodTypes.EVERY_5_MINUTES),
   549  		Status: SyntheticsMonitorStatus(SyntheticsMonitorStatusTypes.DISABLED),
   550  		Locations: SyntheticsLocationsInput{
   551  			Public: []string{"AP_SOUTH_1"},
   552  		},
   553  		Tags: []SyntheticsTag{
   554  			{
   555  				Key:    "coconut",
   556  				Values: []string{"avocado"},
   557  			},
   558  		},
   559  		Domain:                            "https://www.google.com",
   560  		NumberDaysToFailBeforeCertExpires: 1,
   561  	}
   562  
   563  	createdMonitor, err := a.SyntheticsCreateCertCheckMonitor(testAccountID, monitorInput)
   564  	require.NoError(t, err)
   565  	require.NotNil(t, createdMonitor)
   566  	require.Equal(t, 0, len(createdMonitor.Errors))
   567  
   568  	monitorNameUpdate := fmt.Sprintf("%s-updated", monitorName)
   569  	monitorUpdateInput := SyntheticsUpdateCertCheckMonitorInput{
   570  		Name:                              fmt.Sprintf("%s-updated", monitorName),
   571  		Period:                            monitorInput.Period,
   572  		Status:                            monitorInput.Status,
   573  		Locations:                         monitorInput.Locations,
   574  		Tags:                              monitorInput.Tags,
   575  		Domain:                            fmt.Sprintf("%s?updated=true", monitorInput.Domain),
   576  		NumberDaysToFailBeforeCertExpires: 2,
   577  	}
   578  
   579  	updatedMonitor, err := a.SyntheticsUpdateCertCheckMonitor(createdMonitor.Monitor.GUID, monitorUpdateInput)
   580  	require.NoError(t, err)
   581  	require.NotNil(t, updatedMonitor.Monitor)
   582  	require.Equal(t, 0, len(updatedMonitor.Errors))
   583  	require.Equal(t, monitorNameUpdate, updatedMonitor.Monitor.Name)
   584  	require.Equal(t, "https://www.google.com?updated=true", updatedMonitor.Monitor.Domain)
   585  	require.Equal(t, 2, updatedMonitor.Monitor.NumberDaysToFailBeforeCertExpires)
   586  	require.Equal(t, createdMonitor.Monitor.GUID, updatedMonitor.Monitor.GUID)
   587  
   588  	deletedMonitor, err := a.SyntheticsDeleteMonitor(createdMonitor.Monitor.GUID)
   589  	require.NoError(t, err)
   590  	require.NotNil(t, deletedMonitor)
   591  	require.Equal(t, createdMonitor.Monitor.GUID, deletedMonitor.DeletedGUID)
   592  }
   593  
   594  func TestSyntheticsStepMonitor_Basic(t *testing.T) {
   595  	t.Parallel()
   596  	testAccountID, err := mock.GetTestAccountID()
   597  	if err != nil {
   598  		t.Skipf("%s", err)
   599  	}
   600  
   601  	a := newIntegrationTestClient(t)
   602  
   603  	monitorName := fmt.Sprintf("client-integration-test-%s", mock.RandSeq(5))
   604  	enableScreenshotOnFailureAndScript := true
   605  	monitorInput := SyntheticsCreateStepMonitorInput{
   606  		Name:   monitorName,
   607  		Period: SyntheticsMonitorPeriod(SyntheticsMonitorPeriodTypes.EVERY_DAY),
   608  		Status: SyntheticsMonitorStatus(SyntheticsMonitorStatusTypes.DISABLED),
   609  		AdvancedOptions: SyntheticsStepMonitorAdvancedOptionsInput{
   610  			EnableScreenshotOnFailureAndScript: &enableScreenshotOnFailureAndScript,
   611  		},
   612  		Locations: SyntheticsScriptedMonitorLocationsInput{
   613  			Public: []string{"AP_SOUTH_1"},
   614  		},
   615  		Tags: []SyntheticsTag{
   616  			{
   617  				Key:    "step",
   618  				Values: []string{"monitor"},
   619  			},
   620  		},
   621  		Steps: []SyntheticsStepInput{
   622  			{
   623  				Ordinal: 0,
   624  				Type:    SyntheticsStepTypeTypes.NAVIGATE,
   625  				Values:  []string{"https://one.newrelic.com"},
   626  			},
   627  			{
   628  				Ordinal: 1,
   629  				Type:    SyntheticsStepTypeTypes.ASSERT_TITLE,
   630  				Values:  []string{"%=", "New Relic"}, // %= is used for "contains" logic
   631  			},
   632  		},
   633  	}
   634  
   635  	createdMonitor, err := a.SyntheticsCreateStepMonitor(testAccountID, monitorInput)
   636  	require.NoError(t, err)
   637  	require.NotNil(t, createdMonitor)
   638  	require.Equal(t, 0, len(createdMonitor.Errors))
   639  	require.Equal(t, 2, len(createdMonitor.Monitor.Steps))
   640  
   641  	monitorNameUpdate := fmt.Sprintf("%s-updated", monitorName)
   642  	monitorUpdateInput := SyntheticsUpdateStepMonitorInput{
   643  		Name: fmt.Sprintf("%s-updated", monitorName),
   644  		Steps: []SyntheticsStepInput{
   645  			{
   646  				Ordinal: 0,
   647  				Type:    SyntheticsStepTypeTypes.NAVIGATE,
   648  				Values:  []string{"https://one.newrelic.com"},
   649  			},
   650  			{
   651  				Ordinal: 1,
   652  				Type:    SyntheticsStepTypeTypes.ASSERT_TITLE,
   653  				Values:  []string{"%=", "New Relic"}, // %= is used for "contains" logic
   654  			},
   655  			{
   656  				Ordinal: 2,
   657  				Type:    SyntheticsStepTypeTypes.ASSERT_ELEMENT,
   658  				Values:  []string{"h2.NewDesign", "present", "true"},
   659  			},
   660  		},
   661  	}
   662  
   663  	updatedMonitor, err := a.SyntheticsUpdateStepMonitor(createdMonitor.Monitor.GUID, monitorUpdateInput)
   664  	require.NoError(t, err)
   665  	require.NotNil(t, updatedMonitor.Monitor)
   666  	require.Equal(t, 0, len(updatedMonitor.Errors))
   667  	require.Equal(t, monitorNameUpdate, updatedMonitor.Monitor.Name)
   668  	require.Equal(t, 3, len(updatedMonitor.Monitor.Steps))
   669  
   670  	deletedMonitor, err := a.SyntheticsDeleteMonitor(createdMonitor.Monitor.GUID)
   671  	require.NoError(t, err)
   672  	require.NotNil(t, deletedMonitor)
   673  	require.Equal(t, createdMonitor.Monitor.GUID, deletedMonitor.DeletedGUID)
   674  }
   675  
   676  func TestSyntheticsStepMonitor_GetSteps(t *testing.T) {
   677  	t.Parallel()
   678  	testAccountID, err := mock.GetTestAccountID()
   679  	if err != nil {
   680  		t.Skipf("%s", err)
   681  	}
   682  
   683  	a := newIntegrationTestClient(t)
   684  
   685  	monitorName := fmt.Sprintf("client-integration-test-%s", mock.RandSeq(5))
   686  	enableScreenshotOnFailureAndScript := true
   687  	monitorInput := SyntheticsCreateStepMonitorInput{
   688  		Name:   monitorName,
   689  		Period: SyntheticsMonitorPeriod(SyntheticsMonitorPeriodTypes.EVERY_DAY),
   690  		Status: SyntheticsMonitorStatus(SyntheticsMonitorStatusTypes.DISABLED),
   691  		AdvancedOptions: SyntheticsStepMonitorAdvancedOptionsInput{
   692  			EnableScreenshotOnFailureAndScript: &enableScreenshotOnFailureAndScript,
   693  		},
   694  		Locations: SyntheticsScriptedMonitorLocationsInput{
   695  			Public: []string{"AP_SOUTH_1"},
   696  		},
   697  		Tags: []SyntheticsTag{
   698  			{
   699  				Key:    "step",
   700  				Values: []string{"monitor"},
   701  			},
   702  		},
   703  		Steps: []SyntheticsStepInput{
   704  			{
   705  				Ordinal: 0,
   706  				Type:    SyntheticsStepTypeTypes.NAVIGATE,
   707  				Values:  []string{"https://one.newrelic.com"},
   708  			},
   709  			{
   710  				Ordinal: 1,
   711  				Type:    SyntheticsStepTypeTypes.ASSERT_TITLE,
   712  				Values:  []string{"%=", "New Relic"}, // %= is used for "contains" logic
   713  			},
   714  		},
   715  	}
   716  
   717  	createdMonitor, err := a.SyntheticsCreateStepMonitor(testAccountID, monitorInput)
   718  	require.NoError(t, err)
   719  	require.NotNil(t, createdMonitor)
   720  
   721  	// Test the `steps` query endpoint
   722  	steps, err := a.GetSteps(testAccountID, createdMonitor.Monitor.GUID)
   723  	require.NoError(t, err)
   724  	require.NotNil(t, steps)
   725  	require.Equal(t, 2, len(*steps))
   726  
   727  	deletedMonitor, err := a.SyntheticsDeleteMonitor(createdMonitor.Monitor.GUID)
   728  	require.NoError(t, err)
   729  	require.NotNil(t, deletedMonitor)
   730  	require.Equal(t, createdMonitor.Monitor.GUID, deletedMonitor.DeletedGUID)
   731  }
   732  
   733  func TestSyntheticsStepMonitor_GetScript(t *testing.T) {
   734  	t.Parallel()
   735  	testAccountID, err := mock.GetTestAccountID()
   736  	if err != nil {
   737  		t.Skipf("%s", err)
   738  	}
   739  
   740  	a := newIntegrationTestClient(t)
   741  
   742  	monitorName := fmt.Sprintf("client-integration-test-%s", mock.RandSeq(5))
   743  	monitorInput := SyntheticsCreateScriptBrowserMonitorInput{
   744  		Locations: SyntheticsScriptedMonitorLocationsInput{
   745  			Public: []string{"AP_SOUTH_1"},
   746  		},
   747  		Name:   monitorName,
   748  		Period: SyntheticsMonitorPeriod(SyntheticsMonitorPeriodTypes.EVERY_HOUR),
   749  		Status: SyntheticsMonitorStatus(SyntheticsMonitorStatusTypes.ENABLED),
   750  		Runtime: SyntheticsRuntimeInput{
   751  			RuntimeTypeVersion: "100",
   752  			RuntimeType:        "CHROME_BROWSER",
   753  			ScriptLanguage:     "JAVASCRIPT",
   754  		},
   755  		Script: "var assert = require('assert');\n\n$browser.get('https://api.newrelic.com')",
   756  	}
   757  
   758  	createdMonitor, err := a.SyntheticsCreateScriptBrowserMonitor(testAccountID, monitorInput)
   759  	require.NoError(t, err)
   760  	require.NotNil(t, createdMonitor)
   761  
   762  	// Test the `steps` query endpoint
   763  	script, err := a.GetScript(testAccountID, createdMonitor.Monitor.GUID)
   764  	require.NoError(t, err)
   765  	require.NotNil(t, script)
   766  	require.NotEmpty(t, script.Text)
   767  
   768  	deletedMonitor, err := a.SyntheticsDeleteMonitor(createdMonitor.Monitor.GUID)
   769  	require.NoError(t, err)
   770  	require.NotNil(t, deletedMonitor)
   771  	require.Equal(t, createdMonitor.Monitor.GUID, deletedMonitor.DeletedGUID)
   772  }
   773  
   774  func newIntegrationTestClient(t *testing.T) Synthetics {
   775  	tc := mock.NewIntegrationTestConfig(t)
   776  
   777  	return New(tc)
   778  }