-
Notifications
You must be signed in to change notification settings - Fork 301
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
Add test for DescribeInstances #277
Add test for DescribeInstances #277
Conversation
|
cab10f6
to
48ee6f8
Compare
pkg/providers/v1/aws_test.go
Outdated
tests := []struct { | ||
name string | ||
input *ec2.DescribeInstancesInput | ||
expect func(interface{}) |
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.
why is it interface{}? what is expect supposed to do? what would a failure look like? if in every test case I tell DescribeInstances what to take as input and what to return, what is being tested?
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 I'm missing an AssertExpectations
call in the test (I was a little confused as to whether I needed it while writing the test, because the test does fail if DescribeInstances is not called as expected). Let me see if I can determine if its needed and clear up the logic.
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.
Documentation for On: https://pkg.go.dev/github.com/stretchr/testify/mock#Call.On
so I am telling it what to return when given so and so input. And I think ultimately I have to assert that this call happened at all by doing https://pkg.go.dev/github.com/stretchr/testify/mock#Mock.AssertExpectations
(new to this package, slightly more familiar with gomock)
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.
we dont need Assert since Called basically does it for us . https://pkg.go.dev/github.com/stretchr/testify/mock?utm_source=godoc#Mock.Called
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.
Right, that's the reason that I didn't have an explicit call to AssertExpectations
-- because I was seeing tests fail if I called the expected functions with unexpected arguments. That being said, I think we do want an explicit call to AssertExpectations
because of the missing case. If there is an assert, and a missing call, it will only be caught by the explicit AssertExpectations
, whereas Called
will catch calls with improper arguments.
48ee6f8
to
8648d49
Compare
* Add test for DescribeInstances * Use interface in awsSdkEC2 to allow for mock
8648d49
to
903ae46
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: nckturner, wongma7 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
len(request.InstanceIds) == 0
to account for both empty structs and nil pointers.See #274 for the change and #269 for some context.
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
Add a test and make a comparison more resilient.
Does this PR introduce a user-facing change?: