Skip to content

Commit

Permalink
fix: Add e2e test that is deleting classic api resource with OAuth (#…
Browse files Browse the repository at this point in the history
…1626)

* fix: Add e2e test that is deleting classic API resource with OAuth only manifest

Co-authored-by: Arthur Pitman <[email protected]>
  • Loading branch information
tomazpu and arthurpitman authored Nov 13, 2024
1 parent b5dc2de commit 5cd8e2c
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
40 changes: 40 additions & 0 deletions cmd/monaco/integrationtest/v2/delete_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package v2

import (
"fmt"
"github.com/dynatrace/dynatrace-configuration-as-code/v2/internal/log"
"path/filepath"
"testing"

Expand Down Expand Up @@ -396,3 +397,42 @@ configs:
// Assert expected deletions
integrationtest.AssertAllConfigsAvailability(t, fs, deployManifestPath, []string{}, "", false)
}

func TestDeleteWithOAuthOrTokenOnlyManifest(t *testing.T) {
configFolder := "test-resources/delete-test-configs/"
fs := testutils.CreateTestFileSystem()

t.Run("OAuth only should not throw error but skip delete for Classic API", func(t *testing.T) {
// DELETE Config
deleteFileName := configFolder + "oauth-delete.yaml"
cmdFlag := "--manifest=" + configFolder + "oauth-only-manifest.yaml --file=" + deleteFileName
err := monaco.RunWithFSf(fs, "monaco delete %s --verbose", cmdFlag)
assert.NoError(t, err)

logFile := log.LogFilePath()
_, err = afero.Exists(fs, logFile)
assert.NoError(t, err)

// assert log for skipped deletion
log, err := afero.ReadFile(fs, logFile)
assert.NoError(t, err)
assert.Contains(t, string(log), "Skipped deletion of 1 Classic configuration(s) as API client was unavailable")
})

t.Run("Token only should not throw error but skip delete for Automation API", func(t *testing.T) {
// DELETE Config
deleteFileName := configFolder + "token-delete.yaml"
cmdFlag := "--manifest=" + configFolder + "token-only-manifest.yaml --file=" + deleteFileName
err := monaco.RunWithFSf(fs, "monaco delete %s --verbose", cmdFlag)
assert.NoError(t, err)

logFile := log.LogFilePath()
_, err = afero.Exists(fs, logFile)
assert.NoError(t, err)

// assert log for skipped deletion
log, err := afero.ReadFile(fs, logFile)
assert.NoError(t, err)
assert.Contains(t, string(log), "Skipped deletion of 1 Automation configuration(s)")
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
delete:
- type: aws-credentials
name: sample-aws-id
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
manifestVersion: 1.0
projects:
- name: project
environmentGroups:
- name: default
environments:
- name: environment
url:
type: environment
value: PLATFORM_URL_ENVIRONMENT_1
auth:
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,4 @@
delete:
- type: workflow
project: project
id: sample-id
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
manifestVersion: 1.0
projects:
- name: project
environmentGroups:
- name: default
environments:
- name: environment
url:
type: environment
value: PLATFORM_URL_ENVIRONMENT_1
auth:
token:
name: TOKEN_ENVIRONMENT_1

0 comments on commit 5cd8e2c

Please sign in to comment.