From 3082e1e0431f524db9652e3bd979ac011cac37e5 Mon Sep 17 00:00:00 2001 From: Jure Skelin Date: Fri, 3 Jan 2025 15:08:54 +0100 Subject: [PATCH] test(segment): rename stubClient to segmentStubClient --- pkg/delete/internal/segment/delete_test.go | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pkg/delete/internal/segment/delete_test.go b/pkg/delete/internal/segment/delete_test.go index de5be1a64..f1593195a 100644 --- a/pkg/delete/internal/segment/delete_test.go +++ b/pkg/delete/internal/segment/delete_test.go @@ -32,17 +32,17 @@ import ( "github.com/dynatrace/dynatrace-configuration-as-code/v2/pkg/delete/pointer" ) -type stubClient struct { +type segmentStubClient struct { called bool delete func(id string) (libSegment.Response, error) list func() (libSegment.Response, error) } -func (s *stubClient) List(_ context.Context) (libSegment.Response, error) { +func (s *segmentStubClient) List(_ context.Context) (libSegment.Response, error) { return s.list() } -func (s *stubClient) Delete(_ context.Context, id string) (libSegment.Response, error) { +func (s *segmentStubClient) Delete(_ context.Context, id string) (libSegment.Response, error) { s.called = true return s.delete(id) } @@ -57,7 +57,7 @@ func TestDeleteByCoordinate(t *testing.T) { } externalID, _ := idutils.GenerateExternalIDForDocument(given.AsCoordinate()) - c := stubClient{ + c := segmentStubClient{ list: func() (libSegment.Response, error) { return libSegment.Response{Data: []byte(fmt.Sprintf(`[{"uid": "uid_1", "externalId":"%s"},{"uid": "uid_2", "externalId":"wrong"}]`, externalID))}, nil }, @@ -79,7 +79,7 @@ func TestDeleteByCoordinate(t *testing.T) { Project: "project", } - c := stubClient{ + c := segmentStubClient{ list: func() (libSegment.Response, error) { return libSegment.Response{Data: []byte(`[{"uid": "uid_2", "externalId":"wrong"}]`)}, nil }, @@ -97,7 +97,7 @@ func TestDeleteByCoordinate(t *testing.T) { } externalID, _ := idutils.GenerateExternalIDForDocument(given.AsCoordinate()) - c := stubClient{ + c := segmentStubClient{ list: func() (libSegment.Response, error) { return libSegment.Response{Data: []byte(fmt.Sprintf(`[{"uid": "uid_1", "externalId":"%s"},{"uid": "uid_2", "externalId":"%s"}]`, externalID, externalID))}, nil }, @@ -115,7 +115,7 @@ func TestDeleteByCoordinate(t *testing.T) { Project: "project", } - c := stubClient{ + c := segmentStubClient{ list: func() (libSegment.Response, error) { return libSegment.Response{}, errors.New("some unpredictable error") }, @@ -134,7 +134,7 @@ func TestDeleteByObjectId(t *testing.T) { OriginObjectId: "originObjectID", } - c := stubClient{ + c := segmentStubClient{ delete: func(id string) (libSegment.Response, error) { assert.Equal(t, given.OriginObjectId, id) return libSegment.Response{}, nil @@ -152,7 +152,7 @@ func TestDeleteByObjectId(t *testing.T) { OriginObjectId: "originObjectID", } - c := stubClient{ + c := segmentStubClient{ delete: func(id string) (libSegment.Response, error) { assert.Equal(t, given.OriginObjectId, id) return libAPI.Response{}, libAPI.APIError{StatusCode: http.StatusNotFound} @@ -170,7 +170,7 @@ func TestDeleteByObjectId(t *testing.T) { Project: "project", } - c := stubClient{ + c := segmentStubClient{ delete: func(_ string) (libSegment.Response, error) { return libSegment.Response{}, errors.New("some unpredictable error") }, @@ -187,7 +187,7 @@ func TestDeleteByObjectId(t *testing.T) { Project: "project", } - c := stubClient{ + c := segmentStubClient{ delete: func(_ string) (libSegment.Response, error) { return libAPI.Response{}, libAPI.APIError{StatusCode: http.StatusInternalServerError} }, @@ -204,7 +204,7 @@ func TestDeleteByObjectId(t *testing.T) { Project: "project", } - c := stubClient{ + c := segmentStubClient{ delete: func(uid string) (libSegment.Response, error) { if uid == given.OriginObjectId { return libSegment.Response{}, nil @@ -220,7 +220,7 @@ func TestDeleteByObjectId(t *testing.T) { func TestDeleteAll(t *testing.T) { t.Run("simple case", func(t *testing.T) { - c := stubClient{ + c := segmentStubClient{ list: func() (libSegment.Response, error) { return libSegment.Response{Data: []byte(`[{"uid": "uid_1"},{"uid": "uid_2"},{"uid": "uid_3"}]`)}, nil }, @@ -235,7 +235,7 @@ func TestDeleteAll(t *testing.T) { }) t.Run("deletion continues even if error occurs during delete", func(t *testing.T) { - c := stubClient{ + c := segmentStubClient{ list: func() (libSegment.Response, error) { return libSegment.Response{Data: []byte(`[{"uid": "uid_1"},{"uid": "uid_2"},{"uid": "uid_3"}]`)}, nil },