Skip to content

Commit

Permalink
Fixing TestController_RotateCertificates
Browse files Browse the repository at this point in the history
Signed-off-by: Antonin Bas <[email protected]>
  • Loading branch information
antoninbas committed Jul 20, 2023
1 parent f96efa2 commit 29b7063
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/test-go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Go Test
on:
push:
branches:
- test-rotate-certificate

jobs:
test-unit:
runs-on: [ubuntu-latest]
steps:
- name: Check-out code
uses: actions/checkout@v3
- name: Set up Go using version from go.mod
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- name: Run unit tests
run: go test -count=30 -run=TestController_RotateCertificates ./pkg/agent/controller/ipseccertificate/...
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,11 @@ func TestController_RotateCertificates(t *testing.T) {
// It is important to truncate to the second, because the accuracy of notAfter in the
// certificate is at the second level. If we don't, the certificate may actually be rotated
// before 7s.
// We use a time in the future (1 hour), because newFakeController will create self-signed
// root certificates using the wall-clock time. We want to make sure that the root
// certificates are valid for this virtual time.
now := time.Now().Truncate(time.Second)
// now := time.Now().Add(1 * time.Hour).Truncate(time.Second)
fakeClock := testingclock.NewFakeClock(now)
fakeController := newFakeController(t, fakeClock)
defer fakeController.mockController.Finish()
Expand Down Expand Up @@ -307,7 +311,9 @@ func TestController_RotateCertificates(t *testing.T) {
stopCh := make(chan struct{})
defer close(stopCh)
go fakeController.Run(stopCh)
fmt.Println("A")
<-signCh
fmt.Println("B")
// the rotation interval is determined by nextRotationDeadline as notBefore + (notAfter -
// notBefore) * k, where k is >= 0.7 and <= 0.9. We would therefore expect the rotation
// interval to be between [7, 9] seconds.
Expand All @@ -319,7 +325,9 @@ func TestController_RotateCertificates(t *testing.T) {
}
fakeClock.SetTime(now.Add(time.Second * 9))
// wait for the signer to finish signing two CSRs.
fmt.Println("C")
<-signCh
fmt.Println("D")
list, err := fakeController.kubeClient.CertificatesV1().CertificateSigningRequests().List(context.TODO(), metav1.ListOptions{})
assert.NoError(t, err)
assert.Len(t, list.Items, 2)
Expand Down

0 comments on commit 29b7063

Please sign in to comment.