Skip to content

Commit

Permalink
test(segment): rename stubClient to segmentStubClient
Browse files Browse the repository at this point in the history
  • Loading branch information
jskelin committed Jan 3, 2025
1 parent 3c07df7 commit 3082e1e
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions pkg/delete/internal/segment/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
},
Expand All @@ -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
},
Expand All @@ -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
},
Expand All @@ -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")
},
Expand All @@ -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
Expand All @@ -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}
Expand All @@ -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")
},
Expand All @@ -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}
},
Expand All @@ -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
Expand All @@ -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
},
Expand All @@ -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
},
Expand Down

0 comments on commit 3082e1e

Please sign in to comment.