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

test: unsubscribe #36

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

MelloTonio
Copy link

@MelloTonio MelloTonio commented Oct 5, 2021

TODO:

  • Fix async tests

@matheusmosca matheusmosca linked an issue Oct 5, 2021 that may be closed by this pull request
Copy link
Owner

@matheusmosca matheusmosca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @MelloTonio, sorry for taking too long to review your PR.

return nil, ErrSubscriberNotFound
}

func (t Topic) UpdateTopic(topic Topic) (Topic, error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove this method?

Comment on lines +61 to +63
subsInterface := value.(Subscriber)

return &subsInterface, nil
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
subsInterface := value.(Subscriber)
return &subsInterface, nil
subscriber := value.(Subscriber)
return subscriber, nil

func (t *Topic) listenForSubscriptions() {
for newSubCh := range t.newSubCh {
t.subscribers.Store(newSubCh.GetID(), newSubCh)
func (t Topic) GetSubscriber(subscriberID vos.SubscriberID) (*Subscriber, error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change this method to not return a pointer?

Comment on lines +19 to +20

//u.storage.UpdateTopic(ctx, topic)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove these lines?

},
beforeRun: func(topic entities.Topic) (chan vos.Message, vos.SubscriberID) {
subscriber := entities.NewSubscriber(topic)
ch, ID := subscriber.Subscribe()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you write id in lowercase? I think variables should not start with capitalized letters.

Suggested change
ch, ID := subscriber.Subscribe()
ch, id := subscriber.Subscribe()

"github.com/matheusmosca/walrus/domain/entities"
)

func (r *repository) UpdateTopic(ctx context.Context, topicName entities.Topic) (entities.Topic, error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove this file?

subsCh, subsID := tt.beforeRun(topic)
defer close(subsCh)

tt.fields.storage = &RepositoryMock{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know there are some tests doing this, but could you define the RepositoryMock on each test case (I mean in the slice). You can turn fields into a function that receives a t *testing.T and an entities.Topic to prepare the repository.

Comment on lines +107 to +110
if tt.wantErr != nil {
assert.ErrorIs(t, err, tt.wantErr)
return
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are not asserting this error on successful scenarios.

Suggested change
if tt.wantErr != nil {
assert.ErrorIs(t, err, tt.wantErr)
return
}
assert.ErrorIs(t, err, tt.wantErr)
if tt.wantErr != nil {
return
}

fields fields
beforeRun func(topic entities.Topic) (chan vos.Message, vos.SubscriberID)
wantErr error
wantSubscriber bool
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this field is not being used, could you remove it?


type args struct {
ctx context.Context
message vos.Message
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unsubscribe use case does not have any relation with messages, could you remove this field? It makes more sense to add the topic name here (if you want to)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add unit tests for unsubscribe use case
2 participants