diff --git a/cmd/monaco/integrationtest/v2/all_configs_integration_test.go b/cmd/monaco/integrationtest/v2/all_configs_integration_test.go index 928aeb28f..01497ade8 100644 --- a/cmd/monaco/integrationtest/v2/all_configs_integration_test.go +++ b/cmd/monaco/integrationtest/v2/all_configs_integration_test.go @@ -19,13 +19,13 @@ package v2 import ( - "github.com/dynatrace/dynatrace-configuration-as-code/v2/internal/featureflags" - "github.com/dynatrace/dynatrace-configuration-as-code/v2/internal/testutils" - "github.com/stretchr/testify/assert" "testing" "github.com/dynatrace/dynatrace-configuration-as-code/v2/cmd/monaco/runner" + "github.com/dynatrace/dynatrace-configuration-as-code/v2/internal/featureflags" + "github.com/dynatrace/dynatrace-configuration-as-code/v2/internal/testutils" "github.com/spf13/afero" + "github.com/stretchr/testify/assert" ) // tests all configs for a single environment @@ -46,7 +46,9 @@ func runAllConfigsTest(t *testing.T, specificEnvironment string) { manifest := configFolder + "manifest.yaml" envVars := map[string]string{ - featureflags.Temporary[featureflags.OpenPipeline].EnvName(): "true"} + featureflags.Temporary[featureflags.OpenPipeline].EnvName(): "true", + featureflags.Temporary[featureflags.Documents].EnvName(): "true", + } RunIntegrationWithCleanupGivenEnvs(t, configFolder, manifest, specificEnvironment, "AllConfigs", envVars, func(fs afero.Fs, _ TestContext) { diff --git a/cmd/monaco/integrationtest/v2/dry-run_test.go b/cmd/monaco/integrationtest/v2/dry-run_test.go new file mode 100644 index 000000000..e8cb60fe2 --- /dev/null +++ b/cmd/monaco/integrationtest/v2/dry-run_test.go @@ -0,0 +1,49 @@ +//go:build integration + +/* + * @license + * Copyright 2024 Dynatrace LLC + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v2 + +import ( + "testing" + + "github.com/dynatrace/dynatrace-configuration-as-code/v2/cmd/monaco/integrationtest/utils/monaco" + "github.com/dynatrace/dynatrace-configuration-as-code/v2/internal/featureflags" + "github.com/spf13/afero" + "github.com/stretchr/testify/assert" +) + +func TestDryRun(t *testing.T) { + specificEnvironment := "platform_env" + configFolder := "test-resources/integration-all-configs/" + manifest := configFolder + "manifest.yaml" + + envVars := map[string]string{ + featureflags.Temporary[featureflags.OpenPipeline].EnvName(): "true", + featureflags.Temporary[featureflags.Documents].EnvName(): "true", + } + + RunIntegrationWithCleanupGivenEnvs(t, configFolder, manifest, specificEnvironment, "AllConfigs", envVars, func(fs afero.Fs, _ TestContext) { + // This causes a POST for all configs: + err := monaco.RunWithFsf(fs, "monaco deploy %s --environment=%s --verbose --dry-run", manifest, specificEnvironment) + assert.NoError(t, err) + + // This causes a PUT for all configs: + err = monaco.RunWithFsf(fs, "monaco deploy %s --environment=%s --verbose --dry-run", manifest, specificEnvironment) + assert.NoError(t, err) + }) +} diff --git a/cmd/monaco/integrationtest/v2/test-resources/integration-all-configs/project/document-dashboard/a913d0e0-0349-4f00-8849-076305e31808.json b/cmd/monaco/integrationtest/v2/test-resources/integration-all-configs/project/document-dashboard/a913d0e0-0349-4f00-8849-076305e31808.json new file mode 100644 index 000000000..94a9555fc --- /dev/null +++ b/cmd/monaco/integrationtest/v2/test-resources/integration-all-configs/project/document-dashboard/a913d0e0-0349-4f00-8849-076305e31808.json @@ -0,0 +1,7 @@ +{ + "importedWithCode": false, + "layouts": {}, + "tiles": {}, + "variables": [], + "version": 14 +} diff --git a/cmd/monaco/integrationtest/v2/test-resources/integration-all-configs/project/document-dashboard/config.yaml b/cmd/monaco/integrationtest/v2/test-resources/integration-all-configs/project/document-dashboard/config.yaml new file mode 100644 index 000000000..86df8c314 --- /dev/null +++ b/cmd/monaco/integrationtest/v2/test-resources/integration-all-configs/project/document-dashboard/config.yaml @@ -0,0 +1,14 @@ +configs: +- id: a913d0e0-0349-4f00-8849-076305e31808 + config: + name: my-dashboard + template: a913d0e0-0349-4f00-8849-076305e31808.json + skip: false + type: + document: + kind: dashboard + private: true + environmentOverrides: + - environment: classic_env + override: + skip: true diff --git a/cmd/monaco/integrationtest/v2/test-resources/integration-all-configs/project/document-notebook/cb6f0c1b-90f0-4819-b822-ae1f2b10df40.json b/cmd/monaco/integrationtest/v2/test-resources/integration-all-configs/project/document-notebook/cb6f0c1b-90f0-4819-b822-ae1f2b10df40.json new file mode 100644 index 000000000..7c683018f --- /dev/null +++ b/cmd/monaco/integrationtest/v2/test-resources/integration-all-configs/project/document-notebook/cb6f0c1b-90f0-4819-b822-ae1f2b10df40.json @@ -0,0 +1,8 @@ +{ + "defaultTimeframe": { + "from": "now-2h", + "to": "now" + }, + "sections": [], + "version": "5" +} diff --git a/cmd/monaco/integrationtest/v2/test-resources/integration-all-configs/project/document-notebook/config.yaml b/cmd/monaco/integrationtest/v2/test-resources/integration-all-configs/project/document-notebook/config.yaml new file mode 100644 index 000000000..766df4137 --- /dev/null +++ b/cmd/monaco/integrationtest/v2/test-resources/integration-all-configs/project/document-notebook/config.yaml @@ -0,0 +1,14 @@ +configs: +- id: cb6f0c1b-90f0-4819-b822-ae1f2b10df40 + config: + name: my-notebook + template: cb6f0c1b-90f0-4819-b822-ae1f2b10df40.json + skip: false + type: + document: + kind: notebook + private: false + environmentOverrides: + - environment: classic_env + override: + skip: true diff --git a/pkg/deploy/internal/document/document.go b/pkg/deploy/internal/document/document.go index 8f11db3b5..096ea1f34 100644 --- a/pkg/deploy/internal/document/document.go +++ b/pkg/deploy/internal/document/document.go @@ -49,7 +49,7 @@ type DummyClient struct{} // Create implements Client. func (c *DummyClient) Create(ctx context.Context, name string, isPrivate bool, externalId string, data []byte, documentType documents.DocumentType) (libAPI.Response, error) { - return libAPI.Response{}, nil + return libAPI.Response{Data: []byte(`{}`)}, nil } // Get implements Client. @@ -64,7 +64,7 @@ func (c *DummyClient) List(ctx context.Context, filter string) (documents.ListRe // Update implements Client. func (c *DummyClient) Update(ctx context.Context, id string, name string, isPrivate bool, data []byte, documentType documents.DocumentType) (libAPI.Response, error) { - return libAPI.Response{}, nil + return libAPI.Response{Data: []byte(`{}`)}, nil } func Deploy(ctx context.Context, client Client, properties parameter.Properties, renderedConfig string, c *config.Config) (entities.ResolvedEntity, error) {