Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove getters in ClientSet #1646

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cmd/monaco/download/download_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func downloadConfigs(clientSet *client.ClientSet, apisToDownload api.APIs, opts
if opts.auth.Token == nil {
return nil, errors.New("classic client config requires token")
}
classicCfgs, err := fn.classicDownload(clientSet.Config(), opts.projectName, prepareAPIs(apisToDownload, opts), classic.ApiContentFilters)
classicCfgs, err := fn.classicDownload(clientSet.ConfigClient, opts.projectName, prepareAPIs(apisToDownload, opts), classic.ApiContentFilters)
if err != nil {
return nil, err
}
Expand All @@ -264,7 +264,7 @@ func downloadConfigs(clientSet *client.ClientSet, apisToDownload api.APIs, opts

if shouldDownloadSettings(opts) {
log.Info("Downloading settings objects")
settingCfgs, err := fn.settingsDownload(clientSet.Settings(), opts.projectName, settings.DefaultSettingsFilters, makeSettingTypes(opts.specificSchemas)...)
settingCfgs, err := fn.settingsDownload(clientSet.SettingsClient, opts.projectName, settings.DefaultSettingsFilters, makeSettingTypes(opts.specificSchemas)...)
if err != nil {
return nil, err
}
Expand All @@ -274,7 +274,7 @@ func downloadConfigs(clientSet *client.ClientSet, apisToDownload api.APIs, opts
if shouldDownloadAutomationResources(opts) {
if opts.auth.OAuth != nil {
log.Info("Downloading automation resources")
automationCfgs, err := fn.automationDownload(clientSet.Automation(), opts.projectName)
automationCfgs, err := fn.automationDownload(clientSet.AutClient, opts.projectName)
if err != nil {
return nil, err
}
Expand All @@ -286,7 +286,7 @@ func downloadConfigs(clientSet *client.ClientSet, apisToDownload api.APIs, opts

if shouldDownloadBuckets(opts) && opts.auth.OAuth != nil {
log.Info("Downloading Grail buckets")
bucketCfgs, err := fn.bucketDownload(clientSet.Bucket(), opts.projectName)
bucketCfgs, err := fn.bucketDownload(clientSet.BucketClient, opts.projectName)
if err != nil {
return nil, err
}
Expand All @@ -297,7 +297,7 @@ func downloadConfigs(clientSet *client.ClientSet, apisToDownload api.APIs, opts
if shouldDownloadDocuments(opts) {
if opts.auth.OAuth != nil {
log.Info("Downloading documents")
documentCfgs, err := fn.documentDownload(clientSet.Document(), opts.projectName)
documentCfgs, err := fn.documentDownload(clientSet.DocumentClient, opts.projectName)
if err != nil {
return nil, err
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/monaco/integrationtest/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func AssertAllConfigsAvailability(t *testing.T, fs afero.Fs, manifestPath string
var foundID string
switch typ := theConfig.Type.(type) {
case config.SettingsType:
foundID = AssertSetting(t, ctx, clients.Settings(), typ, env.Name, available, theConfig)
foundID = AssertSetting(t, ctx, clients.SettingsClient, typ, env.Name, available, theConfig)
case config.ClassicApiType:
assert.NotEmpty(t, configName, "classic API config %v is missing name, can not assert if it exists", theConfig.Coordinate)

Expand All @@ -155,21 +155,21 @@ func AssertAllConfigsAvailability(t *testing.T, fs afero.Fs, manifestPath string
theApi = theApi.ApplyParentObjectID(scope)
}

foundID = AssertConfig(t, ctx, clients.Config(), theApi, env, available, theConfig, configName)
foundID = AssertConfig(t, ctx, clients.ConfigClient, theApi, env, available, theConfig, configName)
case config.AutomationType:
if clients.Automation() == nil {
if clients.AutClient == nil {
t.Errorf("can not assert existience of Automtation config %q (%s) because no AutomationClient exists - was the test env not configured as Platform?", theConfig.Coordinate, typ.Resource)
return
}
foundID = AssertAutomation(t, clients.Automation(), env, available, typ.Resource, theConfig)
foundID = AssertAutomation(t, clients.AutClient, env, available, typ.Resource, theConfig)
case config.BucketType:
if clients.Bucket() == nil {
if clients.BucketClient == nil {
t.Errorf("can not assert existience of Bucket config %q) because no BucketClient exists - was the test env not configured as Platform?", theConfig.Coordinate)
return
}
foundID = AssertBucket(t, clients.Bucket(), env, available, theConfig)
foundID = AssertBucket(t, clients.BucketClient, env, available, theConfig)
case config.DocumentType:
if clients.Document() == nil {
if clients.DocumentClient == nil {
t.Errorf("can not assert existience of Document config %q) because no DocumentClient exists - was the test env not configured as Platform?", theConfig.Coordinate)
return
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/monaco/integrationtest/v1/integration_test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func AssertConfigAvailability(t *testing.T, fs afero.Fs, manifestFile string, co
ctx := context.WithValue(context.TODO(), log.CtxKeyCoord{}, coord)
ctx = context.WithValue(ctx, log.CtxKeyEnv{}, log.CtxValEnv{Name: conf.Environment, Group: conf.Group})

assertConfigAvailable(t, ctx, clients.Config(), envDefinition, available, *conf)
assertConfigAvailable(t, ctx, clients.ConfigClient, envDefinition, available, *conf)
}

func getConfigsForEnv(t *testing.T, project project.Project, env manifest.EnvironmentDefinition) project.ConfigsPerType {
Expand Down
10 changes: 5 additions & 5 deletions cmd/monaco/integrationtest/v2/delete_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ environmentGroups:
clientSet := integrationtest.CreateDynatraceClients(t, env)

// check the setting was deleted
integrationtest.AssertSetting(t, context.TODO(), clientSet.Settings(), config.SettingsType{SchemaId: "builtin:tags.auto-tagging"}, envName, false, config.Config{
integrationtest.AssertSetting(t, context.TODO(), clientSet.SettingsClient, config.SettingsType{SchemaId: "builtin:tags.auto-tagging"}, envName, false, config.Config{
Coordinate: coordinate.Coordinate{
Project: "project",
Type: "builtin:tags.auto-tagging",
Expand All @@ -267,7 +267,7 @@ environmentGroups:
})

// check the workflow still exists after deletion was skipped without error
integrationtest.AssertAutomation(t, clientSet.Automation(), env, true, config.Workflow, config.Config{
integrationtest.AssertAutomation(t, clientSet.AutClient, env, true, config.Workflow, config.Config{
Coordinate: coordinate.Coordinate{
Project: "project",
Type: "workflow",
Expand All @@ -276,7 +276,7 @@ environmentGroups:
})

// check the bucket still exists after deletion was skipped without error
integrationtest.AssertBucket(t, clientSet.Bucket(), env, true, config.Config{
integrationtest.AssertBucket(t, clientSet.BucketClient, env, true, config.Config{
Coordinate: coordinate.Coordinate{
Project: "project",
Type: "bucket",
Expand Down Expand Up @@ -343,7 +343,7 @@ configs:
integrationtest.AssertAllConfigsAvailability(t, fs, deployManifestPath, []string{}, "", true)

// get application ID
v, err := clientSet.Config().List(context.TODO(), apis["application-mobile"])
v, err := clientSet.ConfigClient.List(context.TODO(), apis["application-mobile"])
assert.NoError(t, err)

var appID string
Expand All @@ -370,7 +370,7 @@ configs:
require.NoError(t, err)

// Assert key-user-action is deleted
integrationtest.AssertConfig(t, context.TODO(), clientSet.Config(), apis["key-user-actions-mobile"].ApplyParentObjectID(appID), env, false, config.Config{
integrationtest.AssertConfig(t, context.TODO(), clientSet.ConfigClient, apis["key-user-actions-mobile"].ApplyParentObjectID(appID), env, false, config.Config{
Coordinate: coordinate.Coordinate{
Project: "project",
Type: "key-user-actions-mobile",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestSettingsInDifferentProjectsGetDifferentExternalIDs(t *testing.T) {

clientSet, err := client.CreateClientSet(context.TODO(), environment.URL.Value, environment.Auth, client.ClientOptions{SupportArchive: support.SupportArchive})
assert.NoError(t, err)
c := clientSet.Settings()
c := clientSet.SettingsClient
settings, _ := c.List(context.TODO(), "builtin:anomaly-detection.metric-events", dtclient.ListSettingsOptions{DiscardValue: true, Filter: func(object dtclient.DownloadSettingsObject) bool {
return object.ExternalId == extIDProject1 || object.ExternalId == extIDProject2
}})
Expand Down
20 changes: 11 additions & 9 deletions cmd/monaco/integrationtest/v2/documents_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ package v2
import (
"context"
"fmt"
"path/filepath"
"strings"
"testing"

"github.com/spf13/afero"
"github.com/stretchr/testify/assert"

"github.com/dynatrace/dynatrace-configuration-as-code/v2/cmd/monaco/integrationtest"
"github.com/dynatrace/dynatrace-configuration-as-code/v2/cmd/monaco/integrationtest/utils/monaco"
"github.com/dynatrace/dynatrace-configuration-as-code/v2/internal/featureflags"
manifestloader "github.com/dynatrace/dynatrace-configuration-as-code/v2/pkg/manifest/loader"
"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
"path/filepath"
"strings"
"testing"
)

// TestDocuments verifies that the "private" field of a document config definition in the config.yaml file
Expand Down Expand Up @@ -63,13 +65,13 @@ func TestDocuments(t *testing.T) {

// check isPrivate == false
clientSet := integrationtest.CreateDynatraceClients(t, man.Environments[environment])
result, err := clientSet.Document().List(context.TODO(), fmt.Sprintf("name='my-notebook_%s'", testContext.suffix))
result, err := clientSet.DocumentClient.List(context.TODO(), fmt.Sprintf("name='my-notebook_%s'", testContext.suffix))
assert.NoError(t, err)
assert.Len(t, result.Responses, 1)
assert.False(t, result.Responses[0].IsPrivate)

// check isPrivate == true
result, err = clientSet.Document().List(context.TODO(), fmt.Sprintf("name='my-dashboard_%s'", testContext.suffix))
result, err = clientSet.DocumentClient.List(context.TODO(), fmt.Sprintf("name='my-dashboard_%s'", testContext.suffix))
assert.NoError(t, err)
assert.Len(t, result.Responses, 1)
assert.True(t, result.Responses[0].IsPrivate)
Expand Down Expand Up @@ -101,13 +103,13 @@ func TestDocuments(t *testing.T) {
assert.NoError(t, err)

// check if isPrivate was changed to true
result, err = clientSet.Document().List(context.TODO(), fmt.Sprintf("name='my-notebook_%s'", testContext.suffix))
result, err = clientSet.DocumentClient.List(context.TODO(), fmt.Sprintf("name='my-notebook_%s'", testContext.suffix))
assert.NoError(t, err)
assert.Len(t, result.Responses, 1)
assert.True(t, result.Responses[0].IsPrivate)

// check if isPrivate was changed to false
result, err = clientSet.Document().List(context.TODO(), fmt.Sprintf("name='my-dashboard_%s'", testContext.suffix))
result, err = clientSet.DocumentClient.List(context.TODO(), fmt.Sprintf("name='my-dashboard_%s'", testContext.suffix))
assert.NoError(t, err)
assert.Len(t, result.Responses, 1)
assert.False(t, result.Responses[0].IsPrivate)
Expand Down
6 changes: 3 additions & 3 deletions cmd/monaco/integrationtest/v2/scoped_configs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ func assertOverallDashboardSharedState(t *testing.T, fs afero.Fs, testContext Te

dashboardAPI := apis[api.Dashboard]
dashboardName := integrationtest.AddSuffix("Application monitoring", testContext.suffix)
exists, dashboardID, err := clientSet.Config().ExistsWithName(context.TODO(), dashboardAPI, dashboardName)
exists, dashboardID, err := clientSet.ConfigClient.ExistsWithName(context.TODO(), dashboardAPI, dashboardName)

require.NoError(t, err, "expect to be able to get dashboard by name")
require.True(t, exists, "dashboard must exist")

dashboardJSONBytes, err := clientSet.Config().Get(context.TODO(), dashboardAPI, dashboardID)
dashboardJSONBytes, err := clientSet.ConfigClient.Get(context.TODO(), dashboardAPI, dashboardID)
require.NoError(t, err, "expect to be able to get dashboard by ID")
assertDashboardSharedState(t, dashboardJSONBytes, expectShared)

dashboardShareSettingsAPI := apis[api.DashboardShareSettings].ApplyParentObjectID(dashboardID)
dashboardShareSettingsJSONBytes, err := clientSet.Config().Get(context.TODO(), dashboardShareSettingsAPI, "")
dashboardShareSettingsJSONBytes, err := clientSet.ConfigClient.Get(context.TODO(), dashboardShareSettingsAPI, "")
require.NoError(t, err, "expect to be able to get dashboard shared settings by ID")
assertDashboardShareSettingsEnabledState(t, dashboardShareSettingsJSONBytes, expectShared)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/monaco/integrationtest/v2/skip_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestSkip(t *testing.T) {

for name, def := range loadedManifest.Environments {
set := integrationtest.CreateDynatraceClients(t, def)
clients[name] = set.Settings()
clients[name] = set.SettingsClient
}

for _, tt := range tests {
Expand Down
24 changes: 0 additions & 24 deletions pkg/client/clientset.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,30 +192,6 @@ type ClientSet struct {
OpenPipelineClient OpenPipelineClient
}

func (s ClientSet) Config() ConfigClient {
return s.ConfigClient
}

func (s ClientSet) Settings() SettingsClient {
return s.SettingsClient
}

func (s ClientSet) Automation() AutomationClient {
return s.AutClient
}

func (s ClientSet) Bucket() BucketClient {
return s.BucketClient
}

func (s ClientSet) Document() DocumentClient {
return s.DocumentClient
}

func (s ClientSet) OpenPipeline() OpenPipelineClient {
return s.OpenPipelineClient
}

type ClientOptions struct {
CustomUserAgent string
SupportArchive bool
Expand Down
Loading