-
Notifications
You must be signed in to change notification settings - Fork 95
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
feat(segments): deploy support for segments
API
#1660
Open
tomazpu
wants to merge
20
commits into
main
Choose a base branch
from
feat/GFF/deploy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+732
−71
Open
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d3c2f79
chore: wip commit
tomazpu 12544b2
feat: wip core implementation working
tomazpu bc6835f
feat: Refactor and improve error handling of segments deploy
tomazpu 8c3364e
feat: Fix issue with originObject id being wrong and matching over ex…
tomazpu 71214a7
chore: Fix issue after rebase, remove duplicated code
tomazpu 9a908a5
chore: Fix issue after merge of `delete`, where wrong client is used …
tomazpu f3686e5
feat: Add tests for segments.go
tomazpu 942131a
feat: Add tests for segments.go
tomazpu 1f6fbde
feat: Add tests for segment feature flag in deploy.go
tomazpu c432857
chore: update segments deploy after core lib update
tomazpu 5c26976
chore: fix tests
tomazpu 91837cd
chore: fix unused variable
tomazpu 4aa32ff
chore: fix unused variable
tomazpu 5b46a35
refactor: Split up DummyClient & fakeClient for testing
Laubi 2bb6076
chore: move `TestSegmentsClient` into separate file and reuse it in d…
tomazpu 25a2958
chore: fix dry-run for `segments` and introduce unit test for it
tomazpu 55a8234
chore: switch externalId generator
tomazpu b52f10c
chore: fix deploySegmentClient interface to not be exported
tomazpu 150f36a
fix: introduce a `get` call before upsert for deployment strategy in …
tomazpu 2d7baa2
fix: fix typo in comment
tomazpu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* @license | ||
* Copyright 2025 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 client | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/dynatrace/dynatrace-configuration-as-code-core/clients/segments" | ||
) | ||
|
||
type TestSegmentsClient struct{} | ||
|
||
func (TestSegmentsClient) List(ctx context.Context) (segments.Response, error) { | ||
return segments.Response{}, fmt.Errorf("unimplemented") | ||
} | ||
|
||
func (TestSegmentsClient) GetAll(ctx context.Context) ([]segments.Response, error) { | ||
return []segments.Response{}, fmt.Errorf("unimplemented") | ||
} | ||
|
||
func (TestSegmentsClient) Delete(ctx context.Context, id string) (segments.Response, error) { | ||
return segments.Response{}, fmt.Errorf("unimplemented") | ||
} | ||
|
||
func (TestSegmentsClient) Upsert(ctx context.Context, id string, data []byte) (segments.Response, error) { | ||
return segments.Response{}, fmt.Errorf("unimplemented") | ||
} | ||
|
||
func (TestSegmentsClient) Get(ctx context.Context, id string) (segments.Response, error) { | ||
return segments.Response{}, fmt.Errorf("unimplemented") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -37,7 +37,6 @@ import ( | |||||
"github.com/dynatrace/dynatrace-configuration-as-code-core/clients/automation" | ||||||
"github.com/dynatrace/dynatrace-configuration-as-code-core/clients/buckets" | ||||||
"github.com/dynatrace/dynatrace-configuration-as-code-core/clients/documents" | ||||||
"github.com/dynatrace/dynatrace-configuration-as-code-core/clients/segments" | ||||||
"github.com/dynatrace/dynatrace-configuration-as-code/v2/internal/featureflags" | ||||||
"github.com/dynatrace/dynatrace-configuration-as-code/v2/internal/idutils" | ||||||
"github.com/dynatrace/dynatrace-configuration-as-code/v2/internal/testutils/matcher" | ||||||
|
@@ -1149,93 +1148,48 @@ func TestDelete_Documents(t *testing.T) { | |||||
}) | ||||||
} | ||||||
|
||||||
type segmentStubClient struct { | ||||||
called bool | ||||||
list func() (segments.Response, error) | ||||||
getAll func() ([]segments.Response, error) | ||||||
delete func() (segments.Response, error) | ||||||
} | ||||||
|
||||||
func (c *segmentStubClient) List(_ context.Context) (segments.Response, error) { | ||||||
return c.list() | ||||||
} | ||||||
|
||||||
func (c *segmentStubClient) GetAll(_ context.Context) ([]segments.Response, error) { | ||||||
return c.getAll() | ||||||
} | ||||||
|
||||||
func (c *segmentStubClient) Delete(_ context.Context, _ string) (segments.Response, error) { | ||||||
c.called = true | ||||||
return c.delete() | ||||||
} | ||||||
|
||||||
func TestDelete_Segments(t *testing.T) { | ||||||
t.Run("simple case", func(t *testing.T) { | ||||||
t.Setenv(featureflags.Segments.EnvName(), "true") | ||||||
|
||||||
c := segmentStubClient{ | ||||||
delete: func() (segments.Response, error) { | ||||||
return segments.Response{StatusCode: http.StatusOK}, nil | ||||||
c := client.TestSegmentsClient{} | ||||||
given := delete.DeleteEntries{ | ||||||
"segment": { | ||||||
{ | ||||||
Type: "segment", | ||||||
OriginObjectId: "originObjectID", | ||||||
}, | ||||||
} | ||||||
}, | ||||||
} | ||||||
|
||||||
t.Run("With Enabled Segment FF", func(t *testing.T) { | ||||||
t.Setenv(featureflags.Segments.EnvName(), "true") | ||||||
|
||||||
given := delete.DeleteEntries{ | ||||||
"segment": { | ||||||
{ | ||||||
Type: "segment", | ||||||
OriginObjectId: "originObjectID", | ||||||
}, | ||||||
}, | ||||||
} | ||||||
err := delete.Configs(context.TODO(), client.ClientSet{SegmentClient: &c}, given) | ||||||
assert.NoError(t, err) | ||||||
assert.True(t, c.called, "delete should have been called") | ||||||
//DummyClient returns unimplemented error on every execution of any method | ||||||
assert.Error(t, err, "unimplemented") | ||||||
}) | ||||||
|
||||||
t.Run("simple case with FF turned off", func(t *testing.T) { | ||||||
t.Run("With Disabled Segment FF", func(t *testing.T) { | ||||||
t.Setenv(featureflags.Segments.EnvName(), "false") | ||||||
|
||||||
c := segmentStubClient{} | ||||||
|
||||||
given := delete.DeleteEntries{ | ||||||
"segment": { | ||||||
{ | ||||||
Type: "segment", | ||||||
OriginObjectId: "originObjectID", | ||||||
}, | ||||||
}, | ||||||
} | ||||||
err := delete.Configs(context.TODO(), client.ClientSet{SegmentClient: &c}, given) | ||||||
assert.NoError(t, err) | ||||||
assert.False(t, c.called, "delete should not have been called") | ||||||
}) | ||||||
} | ||||||
|
||||||
func TestDeleteAll_Segments(t *testing.T) { | ||||||
t.Run("simple case", func(t *testing.T) { | ||||||
t.Setenv(featureflags.Segments.EnvName(), "true") | ||||||
c := client.TestSegmentsClient{} | ||||||
|
||||||
c := segmentStubClient{ | ||||||
list: func() (segments.Response, error) { | ||||||
return segments.Response{StatusCode: http.StatusOK, Data: []byte(`[{"uid": "uid_1"},{"uid": "uid_2"},{"uid": "uid_3"}]`)}, nil | ||||||
}, | ||||||
delete: func() (segments.Response, error) { | ||||||
return segments.Response{StatusCode: http.StatusOK}, nil | ||||||
}, | ||||||
} | ||||||
t.Run("With Enabled Segment FF", func(t *testing.T) { | ||||||
t.Setenv(featureflags.Segments.EnvName(), "true") | ||||||
|
||||||
err := delete.All(context.TODO(), client.ClientSet{SegmentClient: &c}, api.APIs{}) | ||||||
assert.NoError(t, err) | ||||||
assert.True(t, c.called, "delete should have been called") | ||||||
//Dummy client returns unimplemented error on every execution of any method | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
assert.Error(t, err, "unimplemented") | ||||||
}) | ||||||
|
||||||
t.Run("FF is turned off", func(t *testing.T) { | ||||||
t.Run("With Disabled Segment FF", func(t *testing.T) { | ||||||
t.Setenv(featureflags.Segments.EnvName(), "false") | ||||||
|
||||||
c := segmentStubClient{} | ||||||
|
||||||
err := delete.All(context.TODO(), client.ClientSet{SegmentClient: &c}, api.APIs{}) | ||||||
assert.NoError(t, err) | ||||||
assert.False(t, c.called, "delete should not have been called") | ||||||
}) | ||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to update this too: