Commit Graph

50 Commits

Author SHA1 Message Date
jetstack-bot
7946df1da7
Merge pull request #3788 from maelvls/refactor-trigger-unit-tests
Refactor trigger-controller unit tests
2021-03-25 11:41:36 +00:00
Maël Valais
7e21f730cc PR comment: typo: "the following are" instead of "is"
Signed-off-by: Maël Valais <mael@vls.dev>
Co-authored-by: Jake Sanders <i@am.so-aweso.me>
2021-03-25 09:07:45 +01:00
Maël Valais
fe3617a41c PR comment: a sentence starts with a capital letter and ends with a dot
Signed-off-by: Maël Valais <mael@vls.dev>
Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2021-03-24 19:19:34 +01:00
joshvanl
dd0b2bf510 Standardise the name of controllers so there is consistency across the
project

Signed-off-by: joshvanl <vleeuwenjoshua@gmail.com>
2021-03-23 16:08:59 +00:00
Maël Valais
71e707387a trigger-controller: refactor test, inject gatherer and policychain
Injecting the whole Gatherer struct was not necessary for testing
since DataForCertificate is now fully unit-tested. With that, we
can mock the Gatherer.Evaluate function. Since there is no reason
to inject a full Gatherer object into the trigger controller, I chose
to inject a simple policies.Func. I named the function "shouldReissue"
since this is exactly what this function does.

I also refactored the test cases to use the same gen.Certificate
that we use in the rest of the codebase.

Signed-off-by: Maël Valais <mael@vls.dev>
2021-03-23 13:55:11 +01:00
Maël Valais
cdb6c16c6d trigger-controller: log a msg when cert must be reissued
Signed-off-by: Maël Valais <mael@vls.dev>
2021-03-21 16:45:58 +01:00
irbekrm
0047174891 Update PR after rebase
Signed-off-by: irbekrm <irbekrm@gmail.com>
2021-03-15 09:00:07 +00:00
irbekrm
a89133b637 Better wording and wrap long comment lines.
Co-authored-by: Maël Valais <mael@vls.dev>
Signed-off-by: irbekrm <irbekrm@gmail.com>
2021-03-15 08:48:23 +00:00
irbekrm
245d0f5c27 Pass DefaultRenewBefore into trigger controller
Signed-off-by: irbekrm <irbekrm@gmail.com>
2021-03-15 08:48:02 +00:00
irbekrm
8d5059b13e Updates Trigger controller integration tests
Signed-off-by: irbekrm <irbekrm@gmail.com>
2021-03-15 08:47:42 +00:00
irbekrm
9e7cd99ea8 CurrentCertificateNearingExpiry looks at x509 cert to determine renewal time
Signed-off-by: irbekrm <irbekrm@gmail.com>
2021-03-15 08:44:14 +00:00
jetstack-bot
9f343ec581
Merge pull request #3475 from maelvls/unit-test-dataforcertificate
DataForCertificate: add unit tests
2021-03-09 18:13:51 +00:00
joshvanl
39a50a1903 Updates unit certificate controller tests to include ObservedGeneration
Signed-off-by: joshvanl <vleeuwenjoshua@gmail.com>
2021-03-04 17:04:09 +00:00
Maël Valais
34c07a71ce DataForCertificate: force core/v1 informer to create the indexer
Signed-off-by: Maël Valais <mael@vls.dev>
2021-03-04 17:20:50 +01:00
Maël Valais
ac325bf4e0 PR comment: spelling
Signed-off-by: Maël Valais <mael@vls.dev>
2021-03-04 17:20:50 +01:00
Maël Valais
680c7b75f6 DataForCertificate: use fake clientset instead of fake lister
Signed-off-by: Maël Valais <mael@vls.dev>
2021-03-04 17:20:45 +01:00
Maël Valais
46e9cb6c5b DataForCertificates: remove unused "name" field
Signed-off-by: Maël Valais <mael@vls.dev>
2021-03-04 17:19:02 +01:00
Maël Valais
3af2cb6650 DataForCertificate: expand comments around expectCalled
Signed-off-by: Maël Valais <mael@vls.dev>
2021-03-04 17:19:02 +01:00
Maël Valais
e0ca10ef2d DataForCertificate: detail why "whereAmI" is used
Signed-off-by: Maël Valais <mael@vls.dev>
2021-03-04 17:19:02 +01:00
Maël Valais
65701e04ab DataForCertificate: check fake is called with correct input
Signed-off-by: Maël Valais <mael@vls.dev>
2021-03-04 17:19:01 +01:00
Maël Valais
8b3bec3c9c DataForCertificate: implement Josh's fake idea
Co-Authored-By: JoshVanL <vleeuwenjoshua@gmail.com>
Signed-off-by: Maël Valais <mael@vls.dev>
2021-03-04 17:18:56 +01:00
Maël Valais
38919b7eb2 DataForCertificate: move certRef to test/unit/gen
Signed-off-by: Maël Valais <mael@vls.dev>
2021-03-04 17:16:16 +01:00
Maël Valais
92bf3c59a0 DataForCertificate: fix tests
Signed-off-by: Maël Valais <mael@vls.dev>
2021-03-04 17:16:16 +01:00
Maël Valais
5c1fba52a5 Mock lister: fix the wrong stack frames for certificaterequests
The stack frames displayed using assert.Fail was not very informative.
That is due to t.Cleanup being called "outside" of the test case
context. There was no mention of the test file itself, gatherer_test.go
in the following example:

 certificaterequest.go:205:
         Error Trace:    certificaterequest.go:205
                                                 testing.go:872
                                                 testing.go:866
                                                 testing.go:873
                                                 testing.go:949
                                                 testing.go:1121
         Error:          lister.CertificateRequests was expected to be called but was not called
         Test:           TestDataForCertificate/should_return_error_when_the_list_func_returns_an_error

With this patch that vendors a simple version of assert.Fail, we get the
correct stack frames that the user needs in order to locate where this
failure happened:

 certificaterequest.go:254:
         Error Trace:    gatherer_test.go:230
                         gatherer_test.go:240
         Error:          lister.CertificateRequests was expected to be called but was not called
         Test:           TestDataForCertificate/should_return_error_when_the_list_func_returns_an_error

Signed-off-by: Maël Valais <mael@vls.dev>
2021-03-04 17:16:16 +01:00
Maël Valais
9eb43bbb96 DataForCertificate: document the behavior and explain "current"
Signed-off-by: Maël Valais <mael@vls.dev>
2021-03-04 17:16:15 +01:00
Maël Valais
754035de7d DataForCertificate: tests: chained funcs pattern for CR mock
Signed-off-by: Maël Valais <mael@vls.dev>
2021-03-04 17:16:15 +01:00
Maël Valais
20ec95e91e DataForCertificate test: v1 -> corev1
Signed-off-by: Maël Valais <mael@vls.dev>
2021-03-04 17:16:15 +01:00
Maël Valais
acc3a19b62 DataForCertificate tests: use generators in test/unit/gen
Signed-off-by: Maël Valais <mael@vls.dev>
2021-03-04 17:16:09 +01:00
Maël Valais
20ee363366 DataForCertificate: add mock listers for certificaterequests
At first, I tried to follow the "generator" pattern that had already
been implemented for the order and secret objects. These generators look
like:

  import (
      "github.com/jetstack/cert-manager/test/unit/listers"
  )

  fake := listers.FakeSecretListerFrom(listers.NewFakeSecretLister(),
      listers.SetFakeSecretNamespaceListerGet(nil, errors.New("not found")),
  )

The major issue I was finding with this approach is that you cannot
enforce any behavior with these fakes: no way to check (or prevent)
unwanted called, no way to check that the correct namespace was used for
the call:

  fake.Secrets("default").Get("secret-1")

which is annoying; I want to be able to check every input, output and
call numbers made to the mocked function.

So I propose a gomock-like approach. I could not use mockgen due to the
fact that (again) client-go is overly nested, which means I would have
to use quite a lot of glue code in order to use mockgen-generated mocks.

Signed-off-by: Maël Valais <mael@vls.dev>
2021-03-04 17:15:32 +01:00
Maël Valais
b937eefbd7 DataForCertificate: unit test it
I initially thought about using the fake clientset like anywhere else,
but this time I thought: what about trying out the hard way, i.e.,
writing all the mocking code myself?

Result: not that hard, but requires more time than just using the fake
clientset.

Signed-off-by: Maël Valais <mael@vls.dev>
2021-03-04 17:13:19 +01:00
irbekrm
17b7749621 Add extra test case + better naming and comments
joshvanl <vleeuwenjoshua@gmail.com>

Signed-off-by: irbekrm <irbekrm@gmail.com>
2021-03-03 18:39:01 +00:00
irbekrm
ff2e2f6d87 Fixes typo + runs ./hack/update-all.sh
Signed-off-by: irbekrm <irbekrm@gmail.com>
2021-02-25 10:05:08 +00:00
irbekrm
5dc63bb2e6 Refactor readiness controller for easier testing
Signed-off-by: irbekrm <irbekrm@gmail.com>
2021-02-25 09:45:04 +00:00
irbekrm
9a306e73e1 Move certificate test util functions to common location so they can be reused
Signed-off-by: irbekrm <irbekrm@gmail.com>
2021-02-25 09:40:50 +00:00
irbekrm
ad53be3138 Small refactor around policies
Make reason values constants, rename some functions for clarity

Signed-off-by: irbekrm <irbekrm@gmail.com>
2021-02-25 09:38:17 +00:00
jetstack-bot
cdc53b65cb
Merge pull request #3500 from meyskens/update-copy
Update copyright to cert-manager project
2020-12-15 10:12:31 +00:00
Maartje Eyskens
ab0cd57dc5 Use The cert-manager Authors.
Signed-off-by: Maartje Eyskens <maartje@eyskens.me>
2020-12-11 19:04:13 +01:00
Maartje Eyskens
1788a9d758 Update copyright to cert-manager project
Signed-off-by: Maartje Eyskens <maartje@eyskens.me>
2020-12-08 19:04:49 +01:00
Maël Valais
07fd8754f5 refactor(trigger): add test case when failure just happened
Signed-off-by: Maël Valais <mael.valais@gmail.com>
2020-12-06 13:51:12 +01:00
Maël Valais
769303c5f8 refactor(trigger): don't backoff when exactly 60min
As Maartje mentioned, it doesn't make sense to return backoff = true
while returning a delay of 0. Also, use time.UTC instead of time.Local.

Signed-off-by: Maël Valais <mael.valais@gmail.com>
2020-12-06 13:44:06 +01:00
Maël Valais
27d4924b5a refactor(trigger): move backoff logic to a unit-tested func
The trigger_controller_test.go has many unrelated test cases and I
thought it would be good to have more tightly scoped functions that are
easy to review (and most importantly, the unit tests are easy to
review).

Signed-off-by: Maël Valais <mael.valais@gmail.com>
2020-12-06 13:40:01 +01:00
Richard Wall
81eb53f597 ./hack/update-all.sh
Signed-off-by: Richard Wall <richard.wall@jetstack.io>
2020-08-20 14:28:06 +01:00
Richard Wall
a70298180a Run a script to update v1alpha2 usage to v1
Script is available at https://github.com/jetstack/cert-manager/pull/3201

Signed-off-by: Richard Wall <richard.wall@jetstack.io>
2020-08-20 14:26:51 +01:00
Maartje Eyskens
3259fdfe9b Implement feedback
Signed-off-by: Maartje Eyskens <maartje@eyskens.me>
2020-08-12 10:59:42 +02:00
Maartje Eyskens
827ce9c5ad Revert log levels on errors
Signed-off-by: Maartje Eyskens <maartje@eyskens.me>
2020-08-12 10:59:42 +02:00
Maartje Eyskens
86dee5ed41 Set error log levels
Signed-off-by: Maartje Eyskens <maartje@eyskens.me>
2020-08-12 10:59:41 +02:00
Maartje Eyskens
fecd0b3518 Set all log levels for info
Signed-off-by: Maartje Eyskens <maartje@eyskens.me>
2020-08-12 10:59:41 +02:00
James Munnelly
fdc0960d27 Schedule a 'resync' of Certificates that have been marked as failed and are to be retried later
Signed-off-by: James Munnelly <james@munnelly.eu>
2020-07-20 09:19:11 +01:00
Haoxiang Zhou
fe80b7d760 Moved predicate package to pkg/util
Signed-off-by: Haoxiang Zhou <haoxiang.zhou@jetstack.io>
2020-07-02 12:23:15 +01:00
James Munnelly
9e2d6a514b Move expcertificates into certificates package
Signed-off-by: James Munnelly <james@munnelly.eu>
2020-07-01 12:16:25 +01:00