Skip to content

Commit

Permalink
fix: Add e2e test to validate cross-project insertAfter references
Browse files Browse the repository at this point in the history
To ensure that corss-project insertAfter references work fine, this new e2e test is added to verify that.
  • Loading branch information
Laubi committed Dec 19, 2024
1 parent 7815785 commit 0c9386f
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 0 deletions.
31 changes: 31 additions & 0 deletions cmd/monaco/integrationtest/v2/settings_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,37 @@ func TestOrderedSettings(t *testing.T) {

}

// TestOrderedSettingsCrossProjects tries to deploy two setting objects A and B, while both are in different projects.
// After each of the two deployment the actual order is asserted.
func TestOrderedSettingsCrossProjects(t *testing.T) {
configFolder := "test-resources/settings-ordered/cross-project-reference"
manifestPath := configFolder + "/manifest.yaml"

RunIntegrationWithCleanup(t, configFolder, manifestPath, "", "SettingsOrdered", func(fs afero.Fs, _ TestContext) {
err := monaco.RunWithFSf(fs, "monaco deploy %s --environment=platform_env --project=source", manifestPath)
assert.NoError(t, err)
integrationtest.AssertAllConfigsAvailability(t, fs, manifestPath, []string{"source"}, "platform_env", true)

loadedManifest := integrationtest.LoadManifest(t, fs, manifestPath, "platform_env")
environment := loadedManifest.Environments["platform_env"]
settingsClient := createSettingsClient(t, environment)
results, err := settingsClient.List(context.TODO(), "builtin:container.monitoring-rule", dtclient.ListSettingsOptions{})
assert.NoError(t, err)

assert.Len(t, results, 2)

// target is first, as source 'insertsAfter' target
targetConfigExternalId, err := idutils.GenerateExternalIDForSettingsObject(coordinate.Coordinate{Project: "target", Type: "builtin:container.monitoring-rule", ConfigId: "target-id"})
assert.NoError(t, err)
assert.Equal(t, targetConfigExternalId, results[0].ExternalId)

sourceConfigExternalId, err := idutils.GenerateExternalIDForSettingsObject(coordinate.Coordinate{Project: "source", Type: "builtin:container.monitoring-rule", ConfigId: "source-id"})
assert.NoError(t, err)
assert.Equal(t, sourceConfigExternalId, results[1].ExternalId)
})

}

func createSettingsClient(t *testing.T, env manifest.EnvironmentDefinition, opts ...func(dynatraceClient *dtclient.SettingsClient)) client.SettingsClient {

clientFactory := clients.Factory().
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
manifestVersion: 1.0

projects:
- name: source
- name: target

environmentGroups:
- name: default
environments:
- name: classic_env
url:
type: environment
value: URL_ENVIRONMENT_1
auth:
token:
name: TOKEN_ENVIRONMENT_1
- name: platform_env
url:
type: environment
value: PLATFORM_URL_ENVIRONMENT_2
auth:
token:
name: TOKEN_ENVIRONMENT_2
oAuth:
clientId:
name: OAUTH_CLIENT_ID
clientSecret:
name: OAUTH_CLIENT_SECRET
tokenEndpoint:
type: environment
value: OAUTH_TOKEN_ENDPOINT
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
configs:
- id: source-id #monaco-test:no-replace
config:
template: template.json
skip: false
type:
settings:
schema: builtin:container.monitoring-rule
schemaVersion: 0.0.1
scope: environment
insertAfter:
configId: target-id #monaco-test:no-replace
project: target
configType: builtin:container.monitoring-rule
property: id
type: reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"enabled": true,
"mode": "MONITORING_OFF",
"property": "CONTAINER_NAME",
"operator": "STARTS",
"value": "aaaa"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
configs:
- id: target-id #monaco-test:no-replace
config:
template: template.json
skip: false
type:
settings:
schema: builtin:container.monitoring-rule
schemaVersion: 0.0.1
scope: environment
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"enabled": true,
"mode": "MONITORING_OFF",
"property": "CONTAINER_NAME",
"operator": "STARTS",
"value": "bbb"
}

0 comments on commit 0c9386f

Please sign in to comment.