-
Notifications
You must be signed in to change notification settings - Fork 84
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
adding unit tests for broker package #983
adding unit tests for broker package #983
Conversation
dao: new(mocks.Dao), | ||
config: Config{}, | ||
addExpectations: func(d *mocks.Dao) { | ||
d.On("GetServiceInstance", u.String()).Return(nil, unknownError) |
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.
just trying to understand. Is this specifying the behavior when the GetServiceInstance is called or is it the expected result?
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 think the answer is both.
https://github.com/stretchr/testify#mock-package
// TestSomething is an example of how to use our test object to
// make assertions about some target code we are testing.
func TestSomething(t *testing.T) {
// create an instance of our test object
testObj := new(MyMockedObject)
// setup expectations
testObj.On("DoSomething", 123).Return(true, nil)
// call the code we are testing
targetFuncThatDoesSomethingWithObj(testObj)
// assert that the expectations were met
testObj.AssertExpectations(t)
pkg/broker/jobs_test.go
Outdated
} | ||
|
||
second := messages[1] | ||
log.Infof("second: %#v", second) |
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.
do we want to keep the log message?
pkg/broker/jobs_test.go
Outdated
} | ||
|
||
second := messages[1] | ||
log.Infof("second: %#v", second) |
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.
same might want to remove
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.
broker test coverage increased from 27.9% to 32.5%
Describe what this PR does and why we need it:
Example of how to implement tests for the broker package.
Changes proposed in this pull request