Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
samirtahir91 committed Nov 14, 2024
1 parent 615cf0c commit 831135f
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 5 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
cd scripts
chmod +x install_and_setup_vault_k8s.sh
./install_and_setup_vault_k8s.sh
- name: Perform the test
- name: Perform the controller integration tests
if: matrix.os != 'macos-latest'
run: |
export "GITHUB_PRIVATE_KEY=${{ secrets.GH_TEST_APP_PK }}"
Expand All @@ -54,12 +54,21 @@ jobs:
export "VAULT_ADDR=http://localhost:8200"
export "VAULT_ROLE_AUDIENCE=githubapp"
export "VAULT_ROLE=githubapp"
export ENABLE_WEBHOOKS=false
# Run vault port forward in background
kubectl port-forward vault-0 8200:8200 &
# Run tests
USE_EXISTING_CLUSTER=true make test
- name: Perform the webhook tests
if: matrix.os != 'macos-latest'
run: |
export "GH_APP_ID=${{ secrets.GH_APP_ID }}"
export "GH_INSTALL_ID=${{ secrets.GH_INSTALL_ID }}"
# Run webhook tests
make test
- name: Report failure
uses: nashmaniac/[email protected]
# Only report failures of pushes (PRs have are visible through the Checks section) to the default branch
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ vet: ## Run go vet against code.

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v -E '/e2e|utils|cmd|test_helpers|vault') -v -ginkgo.v -coverprofile cover.out
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v -E '/e2e|v1|utils|cmd|test_helpers|vault') -v -ginkgo.v -coverprofile cover.out

.PHONY: test-webhooks
test-webhooks: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./api/v1/ -v -ginkgo.v -coverprofile cover.out

# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
Expand Down
1 change: 1 addition & 0 deletions api/v1/githubapp_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1

import (
"fmt"

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
Expand Down
1 change: 0 additions & 1 deletion api/v1/githubapp_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const (
)

var (
privateKey = os.Getenv("GITHUB_PRIVATE_KEY")
appId int
installId int
acessTokenSecretName string
Expand Down
4 changes: 3 additions & 1 deletion internal/controller/githubapp_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/golang-jwt/jwt/v4"
"math/rand"
"net/http"
"os"
Expand All @@ -29,7 +28,10 @@ import (
"sync"
"time"

"github.com/golang-jwt/jwt/v4"

githubappv1 "github-app-operator/api/v1"

vault "github.com/hashicorp/vault/api" // vault client
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down
1 change: 1 addition & 0 deletions internal/controller/githubapp_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
test_helpers "github-app-operator/internal/controller/test_helpers"

githubappv1 "github-app-operator/api/v1"

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
Expand Down
4 changes: 3 additions & 1 deletion internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"net/http" // http client
"os"

//"os/exec"
"path/filepath"
"runtime"
Expand All @@ -37,6 +38,7 @@ import (
. "github.com/onsi/gomega"

test_helpers "github-app-operator/internal/controller/test_helpers"

"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -155,7 +157,7 @@ var _ = BeforeSuite(func() {
// Verify if reconciliation was successful
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Token request failed: %v", err))
} else {
// Set a dummy token just to satisfy the SetupWithManager fucntion
// Set a dummy token just to satisfy the SetupWithManager function
// which will read the token and get the service account and and namespace.
// This token is for 'default' service account in the 'namespace0' namespace
token = `eyJhbGciOiJSUzI1NiIsImtpZCI6Ik5ieTJyVUk2ZzlQZ0k0anNGclRvTkJDM0FsUjJjLUJDVUhzNU9mVG9lcEUifQ.
Expand Down
1 change: 1 addition & 0 deletions internal/controller/test_helpers/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
gomega "github.com/onsi/gomega"

githubappv1 "github-app-operator/api/v1"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down
1 change: 1 addition & 0 deletions internal/controller/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"encoding/base64"
"fmt"

"k8s.io/utils/ptr"

auth "github.com/hashicorp/vault/api/auth/kubernetes" // vault k8s auth
Expand Down
1 change: 1 addition & 0 deletions test/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os/exec"
"strings"
"time"

//lint:ignore ST1001 this is boilerplate code from kubebuilder
. "github.com/onsi/ginkgo/v2" //nolint:golint,revive
)
Expand Down

0 comments on commit 831135f

Please sign in to comment.