Skip to content

Commit a62cc85

Browse files
committed
test: add full e2e tests
1 parent 1abd633 commit a62cc85

File tree

12 files changed

+755
-236
lines changed

12 files changed

+755
-236
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
bin/*
99
Dockerfile.cross
1010

11+
# Secrets
12+
test/e2e/values.yaml
13+
1114
# Test binary, built with `go test -c`
1215
*.test
1316

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ cleanup-test-e2e:
150150

151151
# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
152152
.PHONY: test-e2e
153-
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
154-
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
153+
test-e2e: fmt vet setup-test-e2e ## Run the e2e tests. Expected an isolated environment using Kind.
154+
KUBE_CONTEXT=kind-$(KIND_CLUSTER) go test ./test/e2e/ -tags=e2e -v -ginkgo.v
155155
$(MAKE) cleanup-test-e2e
156156

157157
.PHONY: lint
@@ -213,7 +213,7 @@ build-installer: manifests generate kustomize ## Generate a consolidated YAML wi
213213
.PHONY: ko-build
214214
ko-build: ## Build the manager image using ko.
215215
KO_DOCKER_REPO=$(IMAGE_TAG_BASE) \
216-
ko build --bare --platform=$(PLATFORMS) --image-label org.opencontainers.image.source=$(IMAGE_SOURCE) --tags "latest,$(VERSION)" --push ./cmd/manager
216+
$(KO) build --bare --platform=$(PLATFORMS) --image-label org.opencontainers.image.source=$(IMAGE_SOURCE) --tags "latest,$(VERSION)" --push ./cmd/manager
217217

218218

219219
##@ Deployment
@@ -249,6 +249,7 @@ $(LOCALBIN):
249249
## Tool Binaries
250250
KUBECTL ?= kubectl
251251
KIND ?= kind
252+
KO ?= ko
252253
KUSTOMIZE ?= $(LOCALBIN)/kustomize
253254
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
254255
ENVTEST ?= $(LOCALBIN)/setup-envtest

go.mod

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module github.com/isometry/github-token-manager
22

3-
go 1.24.0
4-
5-
toolchain go1.24.5
3+
go 1.24.5
64

75
require (
86
github.com/go-logr/logr v1.4.3
@@ -12,10 +10,12 @@ require (
1210
github.com/onsi/gomega v1.37.0
1311
github.com/spf13/viper v1.20.1
1412
go.uber.org/automaxprocs v1.6.0
13+
golang.org/x/oauth2 v0.30.0
1514
k8s.io/api v0.33.2
1615
k8s.io/apimachinery v0.33.2
1716
k8s.io/client-go v0.33.2
1817
sigs.k8s.io/controller-runtime v0.21.0
18+
sigs.k8s.io/yaml v1.4.0
1919
)
2020

2121
require (
@@ -127,7 +127,6 @@ require (
127127
golang.org/x/crypto v0.40.0 // indirect
128128
golang.org/x/exp v0.0.0-20250606033433-dcc06ee1d476 // indirect
129129
golang.org/x/net v0.42.0 // indirect
130-
golang.org/x/oauth2 v0.30.0 // indirect
131130
golang.org/x/sync v0.16.0 // indirect
132131
golang.org/x/sys v0.34.0 // indirect
133132
golang.org/x/term v0.33.0 // indirect
@@ -154,5 +153,4 @@ require (
154153
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
155154
sigs.k8s.io/randfill v1.0.0 // indirect
156155
sigs.k8s.io/structured-merge-diff/v4 v4.7.0 // indirect
157-
sigs.k8s.io/yaml v1.4.0 // indirect
158156
)

internal/controller/clustertoken_controller.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ type ClusterTokenReconciler struct {
5555
// For more details, check Reconcile and its Result here:
5656
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
5757
func (r *ClusterTokenReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, err error) {
58-
log := log.FromContext(ctx)
58+
logger := log.FromContext(ctx)
5959

6060
if app == nil {
6161
app, err = ghapp.NewGHApp(ctx)
6262
if err != nil {
63-
log.Error(err, "failed to load GitHub App credentials")
63+
logger.Error(err, "failed to load GitHub App credentials")
6464
return ctrl.Result{RequeueAfter: time.Minute}, err
6565
}
6666
}
@@ -70,26 +70,26 @@ func (r *ClusterTokenReconciler) Reconcile(ctx context.Context, req ctrl.Request
7070
options := []tm.Option{
7171
tm.WithReconciler(r),
7272
tm.WithGHApp(app),
73-
tm.WithLogger(log),
73+
tm.WithLogger(logger),
7474
}
7575

7676
tokenSecret, err := tm.NewTokenSecret(ctx, req.NamespacedName, token, options...)
7777
if err != nil {
78-
log.Error(err, "failed to create ClusterToken reconciler")
78+
logger.Error(err, "failed to create ClusterToken reconciler")
7979
return ctrl.Result{}, err
8080
}
8181

8282
if tokenSecret == nil {
83-
log.Info("ClusterToken not found, skipping reconciliation")
83+
logger.Info("ClusterToken not found, skipping reconciliation")
8484
return ctrl.Result{}, nil
8585
}
8686

8787
result, err = tokenSecret.Reconcile()
8888
if err != nil {
89-
log.Error(err, "failed to reconcile ClusterToken")
89+
logger.Error(err, "failed to reconcile ClusterToken")
9090
return result, err
9191
}
92-
log.Info("reconciled", "requeueAfter", result.RequeueAfter)
92+
logger.Info("reconciled", "requeueAfter", result.RequeueAfter)
9393
return result, nil
9494
}
9595

internal/controller/token_controller.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ type TokenReconciler struct {
5555
// For more details, check Reconcile and its Result here:
5656
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
5757
func (r *TokenReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, err error) {
58-
log := log.FromContext(ctx)
58+
logger := log.FromContext(ctx)
5959

6060
if app == nil {
6161
app, err = ghapp.NewGHApp(ctx)
6262
if err != nil {
63-
log.Error(err, "failed to load GitHub App credentials")
63+
logger.Error(err, "failed to load GitHub App credentials")
6464
return ctrl.Result{RequeueAfter: time.Minute}, err
6565
}
6666
}
@@ -69,26 +69,26 @@ func (r *TokenReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resu
6969
options := []tm.Option{
7070
tm.WithReconciler(r),
7171
tm.WithGHApp(app),
72-
tm.WithLogger(log),
72+
tm.WithLogger(logger),
7373
}
7474

7575
tokenSecret, err := tm.NewTokenSecret(ctx, req.NamespacedName, token, options...)
7676
if err != nil {
77-
log.Error(err, "failed to create Token reconciler")
77+
logger.Error(err, "failed to create Token reconciler")
7878
return ctrl.Result{}, err
7979
}
8080

8181
if tokenSecret == nil {
82-
log.Info("Token not found, skipping reconciliation")
82+
logger.Info("Token not found, skipping reconciliation")
8383
return ctrl.Result{}, nil
8484
}
8585

8686
result, err = tokenSecret.Reconcile()
8787
if err != nil {
88-
log.Error(err, "failed to reconcile Token")
88+
logger.Error(err, "failed to reconcile Token")
8989
return result, err
9090
}
91-
log.Info("reconciled", "requeueAfter", result.RequeueAfter)
91+
logger.Info("reconciled", "requeueAfter", result.RequeueAfter)
9292
return result, nil
9393
}
9494

internal/ghapp/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (c *OperatorConfig) GetKey() string {
4141
const TokenValidity = time.Hour
4242

4343
func LoadConfig(ctx context.Context) (*OperatorConfig, error) {
44-
log := log.FromContext(ctx)
44+
logger := log.FromContext(ctx)
4545

4646
viper.AutomaticEnv()
4747
viper.SetEnvPrefix("GTM")
@@ -60,7 +60,7 @@ func LoadConfig(ctx context.Context) (*OperatorConfig, error) {
6060
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
6161
return nil, fmt.Errorf("error reading configuration file: %w", err)
6262
} else {
63-
log.Info("no configuration file found, continuing with environment variables only")
63+
logger.Info("no configuration file found, continuing with environment variables only")
6464
}
6565
}
6666

internal/ghapp/ghapp.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import (
99
)
1010

1111
func NewGHApp(ctx context.Context) (ghait.GHAIT, error) {
12-
log := log.FromContext(ctx)
12+
logger := log.FromContext(ctx)
1313

1414
cfg, err := LoadConfig(ctx)
1515
if err != nil {
1616
return nil, fmt.Errorf("configuration: %w", err)
1717
}
1818

19-
log.Info("loaded configuration", "config", cfg)
19+
logger.Info("loaded configuration", "config", cfg)
2020

2121
ghapp, err := ghait.NewGHAIT(ctx, cfg)
2222
if err != nil {

internal/tokenmanager/token_secret.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ func WithReconciler(reconciler tokenReconciler) Option {
4343
}
4444
}
4545

46-
func WithGHApp(ghait ghait.GHAIT) Option {
46+
func WithGHApp(g ghait.GHAIT) Option {
4747
return func(s *tokenSecret) {
48-
s.ghait = ghait
48+
s.ghait = g
4949
}
5050
}
5151

0 commit comments

Comments
 (0)