From 5a5533768f36c99f6b9360f562e91b3174afb4e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Nussbaumer?= Date: Tue, 23 Nov 2021 11:33:46 +0100 Subject: [PATCH] build: fix the build action --- .github/workflows/build.yaml | 19 ++++++++++++++----- controller/csr_controller_test.go | 12 ++++++------ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index f2912d1..e710c95 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,11 +1,11 @@ -name: Build +name: Build and test on: - push: - branches: ['*'] + push: + branches: ["*"] + pull_request: jobs: - build: name: Build runs-on: ubuntu-latest @@ -18,4 +18,13 @@ jobs: - run: | go build ./... - go test -run=^$ ./... \ No newline at end of file + + - run: | + go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest + mkdir -p local/envtest-bin/ + setup-envtest use -p env 1.21.x --bin-dir local/envtest-bin > local/envtest-bin/env + - run: | + source local/envtest-bin/env + export KUBEBUILDER_ASSETS=$(pwd)/$KUBEBUILDER_ASSETS + go test -run=^$ ./... + diff --git a/controller/csr_controller_test.go b/controller/csr_controller_test.go index ba95ad4..299245b 100644 --- a/controller/csr_controller_test.go +++ b/controller/csr_controller_test.go @@ -34,7 +34,7 @@ func TestValidCsrApproved(t *testing.T) { validCsr := createCsr(t, csrParams) _, nodeClientSet, _ := createControlPlaneUser(t, validCsr.Spec.Username, []string{"system:masters"}) - _, err = nodeClientSet.CertificatesV1().CertificateSigningRequests().Create(testContext, &validCsr, metav1.CreateOptions{}) + _, err := nodeClientSet.CertificatesV1().CertificateSigningRequests().Create(testContext, &validCsr, metav1.CreateOptions{}) require.Nil(t, err, "Could not create the CSR.") approved, denied, err := waitCsrApprovalStatus(validCsr.Name) @@ -53,7 +53,7 @@ func TestWrongSignerCsr(t *testing.T) { csr.Spec.SignerName = "example.com/not-kubelet-serving" _, nodeClientSet, _ := createControlPlaneUser(t, csr.Spec.Username, []string{"system:masters"}) - _, err = nodeClientSet.CertificatesV1().CertificateSigningRequests().Create(testContext, &csr, metav1.CreateOptions{}) + _, err := nodeClientSet.CertificatesV1().CertificateSigningRequests().Create(testContext, &csr, metav1.CreateOptions{}) require.Nil(t, err, "Could not create the CSR.") approved, denied, err := waitCsrApprovalStatus(csr.Name) @@ -71,7 +71,7 @@ func TestNonMatchingCommonNameUsername(t *testing.T) { csr := createCsr(t, csrParams) _, nodeClientSet, _ := createControlPlaneUser(t, csr.Spec.Username, []string{"system:masters"}) - _, err = nodeClientSet.CertificatesV1().CertificateSigningRequests().Create(testContext, &csr, metav1.CreateOptions{}) + _, err := nodeClientSet.CertificatesV1().CertificateSigningRequests().Create(testContext, &csr, metav1.CreateOptions{}) require.Nil(t, err, "Could not create the CSR.") approved, denied, err := waitCsrApprovalStatus(csr.Name) @@ -92,7 +92,7 @@ func TestInvalidDNSName(t *testing.T) { csr := createCsr(t, csrParams) _, nodeClientSet, _ := createControlPlaneUser(t, csr.Spec.Username, []string{"system:masters"}) - _, err = nodeClientSet.CertificatesV1().CertificateSigningRequests().Create(testContext, &csr, metav1.CreateOptions{}) + _, err := nodeClientSet.CertificatesV1().CertificateSigningRequests().Create(testContext, &csr, metav1.CreateOptions{}) require.Nil(t, err, "Could not create the CSR.") approved, denied, err := waitCsrApprovalStatus(csr.Name) @@ -110,7 +110,7 @@ func TestUnresolvedDNSName(t *testing.T) { csr := createCsr(t, csrParams) _, nodeClientSet, _ := createControlPlaneUser(t, csr.Spec.Username, []string{"system:masters"}) - _, err = nodeClientSet.CertificatesV1().CertificateSigningRequests().Create(testContext, &csr, metav1.CreateOptions{}) + _, err := nodeClientSet.CertificatesV1().CertificateSigningRequests().Create(testContext, &csr, metav1.CreateOptions{}) require.Nil(t, err, "Could not create the CSR.") approved, denied, err := waitCsrApprovalStatus(csr.Name) @@ -128,7 +128,7 @@ func TestMismatchedResolvedIpsSANIps(t *testing.T) { csr := createCsr(t, csrParams) _, nodeClientSet, _ := createControlPlaneUser(t, csr.Spec.Username, []string{"system:masters"}) - _, err = nodeClientSet.CertificatesV1().CertificateSigningRequests().Create(testContext, &csr, metav1.CreateOptions{}) + _, err := nodeClientSet.CertificatesV1().CertificateSigningRequests().Create(testContext, &csr, metav1.CreateOptions{}) require.Nil(t, err, "Could not create the CSR.") approved, denied, err := waitCsrApprovalStatus(csr.Name)