Skip to content

Commit

Permalink
fix: fix dummy client for documents
Browse files Browse the repository at this point in the history
  • Loading branch information
jskelin authored and warber committed Jul 24, 2024
1 parent 6f07deb commit ecab468
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 6 deletions.
10 changes: 6 additions & 4 deletions cmd/monaco/integrationtest/v2/all_configs_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {

Expand Down
49 changes: 49 additions & 0 deletions cmd/monaco/integrationtest/v2/dry-run_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"importedWithCode": false,
"layouts": {},
"tiles": {},
"variables": [],
"version": 14
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"defaultTimeframe": {
"from": "now-2h",
"to": "now"
},
"sections": [],
"version": "5"
}
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions pkg/deploy/internal/document/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down

0 comments on commit ecab468

Please sign in to comment.