-
Notifications
You must be signed in to change notification settings - Fork 178
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
improve tester implementation #146
Conversation
b52bed6
to
a5c5a35
Compare
examples/4-tests/example_test.go
Outdated
} | ||
|
||
// Scenario (2) | ||
// |
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.
Silly comment. You have this unused comment line :)
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.
man.. how was this ever supposed to work :D
de56feb
to
2fbdf6d
Compare
|
||
// MessageTracker tracks message offsets for each topic for convenient | ||
// 'expect message x to be in topic y' in unit tests | ||
type MessageTracker struct { |
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 would suggest bind the MessageTracker to a topic. That will simplify the interface.
tester/messagetracker.go
Outdated
|
||
// NextMessage returns the next message from the topic since the last time this | ||
// function was called (or MoveToEnd) | ||
func (mt *MessageTracker) NextMessage(topic string) (string, interface{}, bool) { |
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.
suggestion: use Next()
instead
tester/messagetracker.go
Outdated
} | ||
|
||
// NextMessageRaw returns the next message in passed topic | ||
func (mt *MessageTracker) NextMessageRaw(topic string) (string, []byte, bool) { |
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.
suggestion: use NextRaw()
instead
tester/messagetracker.go
Outdated
} | ||
|
||
// ExpectEmpty ensures the topic does not contain more messages | ||
func (mt *MessageTracker) ExpectEmpty(topic string) { |
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.
This is not necessary since once can call Next()
until it returns false
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.
actually I'd leave the function, as it does more than just checking we're at the end. Also having a shortcut for the alternative loop that we would have to replae in all projects would be helpful.
but I'd rename it to ExpectAtEnd
to have it consistend with MoveToEnd
.
What do you think?
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.
What about replacing ExpectAtEnd()
with something like mt.Offset() == mt.HWM()
?
and MoveToEnd()
replacing with mt.Seek(mt.HWM())
?
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.
agreed
tester/messagetracker.go
Outdated
// ExpectEmit ensures a message exists in passed topic and key. The message may be | ||
// inspected/unmarshalled by a passed expecter function. | ||
// DEPRECATED: This function is only to get some compatibility and should be removed in future | ||
func (mt *MessageTracker) ExpectEmit(topic string, key string, expecter func(value []byte)) { |
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'd remove this method.
tester/tester.go
Outdated
|
||
// CreateMessageTracker creates a message tracker that starts tracking | ||
// the messages from the end of the current queues | ||
func (km *Tester) NewMessageTrackerFromEnd() *MessageTracker { |
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.
suggestion: NewMessageTracker(topic string)
26671ea
to
50abe07
Compare
Reimplementation of the tester to fix all issues (see issue #145)