Skip to content

Commit

Permalink
Merge pull request #26 from changsheng1239/feat/delete-topic
Browse files Browse the repository at this point in the history
feat: adds DELETE method for topic endpoint
  • Loading branch information
unicodeveloper authored Sep 5, 2023
2 parents 9fc2a94 + 42746a3 commit a9b72a0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type ITopic interface {
RemoveSubscribers(ctx context.Context, key string, subscribers []string) error
Get(ctx context.Context, key string) (*GetTopicResponse, error)
Rename(ctx context.Context, key string, name string) (*GetTopicResponse, error)
Delete(ctx context.Context, key string) error
}

type TopicService service
Expand Down Expand Up @@ -150,3 +151,20 @@ func (t *TopicService) Rename(ctx context.Context, key string, name string) (*Ge

return &resp, nil
}

func (t *TopicService) Delete(ctx context.Context, key string) error {
var resp interface{}
URL := t.client.config.BackendURL.JoinPath("topics", key)

req, err := http.NewRequestWithContext(ctx, http.MethodDelete, URL.String(), http.NoBody)
if err != nil {
return err
}

_, err = t.client.sendRequest(req, &resp)
if err != nil {
return err
}

return nil
}
19 changes: 19 additions & 0 deletions lib/topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,22 @@ func TestRenameTopic_Success(t *testing.T) {
require.NoError(t, err)
require.Equal(t, resp, expectedResponse)
}

func TestDeleteTopic_Success(t *testing.T) {
key := "topicKey"
body := map[string]string{}

httpServer := createTestServer(t, TestServerOptions[map[string]string, map[string]string]{
expectedURLPath: fmt.Sprintf("/v1/topics/%s", key),
expectedSentMethod: http.MethodDelete,
expectedSentBody: body,
responseStatusCode: http.StatusNoContent,
responseBody: body,
})

ctx := context.Background()
c := lib.NewAPIClient(novuApiKey, &lib.Config{BackendURL: lib.MustParseURL(httpServer.URL)})
err := c.TopicsApi.Delete(ctx, key)

require.NoError(t, err)
}

0 comments on commit a9b72a0

Please sign in to comment.