-
Notifications
You must be signed in to change notification settings - Fork 90
feat: tests for cli.go SignReq #1346
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&rdqu 8000 o;, 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
Conversation
b40757a
to
678031d
Compare
Codecov ReportAttention: Patch coverage is
@@ Coverage Diff @@
## devel #1346 +/- ##
========================================
Coverage ? 47.97%
========================================
Files ? 62
Lines ? 10360
Branches ? 0
========================================
Hits ? 4970
Misses ? 5071
Partials ? 319
🚀 New features to boost your workflow:
|
239a187
to
7ddd0a6
Compare
7ddd0a6
to
0e44a67
Compare
|
@@ -314,10 +409,14 @@ func TestSignReq(t *testing.T) { | |||
EXPECT(). | |||
ReadFile(gomock.Eq(positiveCaCrtPath)). | |||
Return(setupGoodCaCertificatePEMData(), nil). | |||
Times(1) | |||
AnyTimes() |
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.
Can I ask, why the move to AnyTimes()
?
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.
Because in certain test scenarios, the path is not even reached. Example:
{
name: "Error in CA Path",
args: args{
opts: &positiveCertOptions,
caCrtPath: invalidPath,
caKeyPath: positiveCaKeyPath,
reqPath: positiveReqPath,
certOut: positiveCertOut,
verify: true,
},
wantErr: true,
},
In this scenario, we don't get to read from caKeyPath
or reqPath
, because we already failed at caCrtPath
. We could mock conditionally based on the scenario, but it adds complexity to the test and makes it really hard to read and extend it with new test cases, I tried it before ending up using AnyTimes()
.
The trade-off between being strict vs having an easy to read and maintain tests, is not worth it imho.
Overall looking good, |
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.
LGTM
Thanks for this 🎉
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.
YES! Came to the same conclusion on the AnyTimes()
Changes:
SignReq
mockableSignReqConfig.Run()
into a separate method namedValidateAndSign
New coverage can be seen here:
https://app.codecov.io/gh/ansible/receptor/pull/1346/blob/pkg/certificates/cli.go?dropdown=coverage
Run is 0% but does not contain any logic.