From 7c8b175258b6696c9ebb5407f96c004f23aee69d Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Mon, 25 Apr 2022 14:20:45 +0200 Subject: [PATCH 1/2] tests: Set GIT_CONFIG_GLOBAL=/dev/null for tests run via make test This ensures that no host specific git configuration is pulled in while testing. One such example would be "init.defaultBranch" which is set to "main" on some hosts, which then causes tests to fail as they keep looking for "master" branches. Signed-off-by: Alexander Block --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index fa6d8d271..549bf7f62 100644 --- a/Makefile +++ b/Makefile @@ -96,6 +96,7 @@ build: check-deps $(LIBGIT2) ## Build manager binary KUBEBUILDER_ASSETS?="$(shell $(ENVTEST) --arch=$(ENVTEST_ARCH) use -i $(ENVTEST_KUBERNETES_VERSION) --bin-dir=$(ENVTEST_ASSETS_DIR) -p path)" test: $(LIBGIT2) install-envtest test-api check-deps ## Run tests KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) \ + GIT_CONFIG_GLOBAL=/dev/null \ go test $(GO_STATIC_FLAGS) ./... -coverprofile cover.out check-deps: @@ -268,3 +269,4 @@ env: $(LIBGIT2) echo 'CGO_CFLAGS="$(CGO_CFLAGS)"' >> $(BUILD_DIR)/.env echo 'CGO_LDFLAGS="$(CGO_LDFLAGS)"' >> $(BUILD_DIR)/.env echo 'KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS)' >> $(BUILD_DIR)/.env + echo 'GIT_CONFIG_GLOBAL=/dev/null' >> $(BUILD_DIR)/.env From fa09aa2a39da8ee9aa27b1d58e4582ed6ddfdf67 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Mon, 25 Apr 2022 14:28:10 +0200 Subject: [PATCH 2/2] tests: Use proper timeouts in gitrepository and helmrepository tests I assume using "interval" for timeouts was an accident and "timeout" was actually meant to be used. This also fixes flakiness of tests. Signed-off-by: Alexander Block --- controllers/gitrepository_controller_test.go | 6 +++--- controllers/helmrepository_controller_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/controllers/gitrepository_controller_test.go b/controllers/gitrepository_controller_test.go index c0ac46068..fb020d7ca 100644 --- a/controllers/gitrepository_controller_test.go +++ b/controllers/gitrepository_controller_test.go @@ -434,7 +434,7 @@ func TestGitRepositoryReconciler_reconcileSource_authStrategy(t *testing.T) { }, Spec: sourcev1.GitRepositorySpec{ Interval: metav1.Duration{Duration: interval}, - Timeout: &metav1.Duration{Duration: interval}, + Timeout: &metav1.Duration{Duration: timeout}, }, } @@ -653,7 +653,7 @@ func TestGitRepositoryReconciler_reconcileSource_checkoutStrategy(t *testing.T) }, Spec: sourcev1.GitRepositorySpec{ Interval: metav1.Duration{Duration: interval}, - Timeout: &metav1.Duration{Duration: interval}, + Timeout: &metav1.Duration{Duration: timeout}, URL: server.HTTPAddress() + repoPath, Reference: tt.reference, }, @@ -1517,7 +1517,7 @@ func TestGitRepositoryReconciler_ConditionsUpdate(t *testing.T) { URL: server.HTTPAddress() + repoPath, GitImplementation: sourcev1.GoGitImplementation, Interval: metav1.Duration{Duration: interval}, - Timeout: &metav1.Duration{Duration: interval}, + Timeout: &metav1.Duration{Duration: timeout}, }, } diff --git a/controllers/helmrepository_controller_test.go b/controllers/helmrepository_controller_test.go index 7a1e5d593..97934d509 100644 --- a/controllers/helmrepository_controller_test.go +++ b/controllers/helmrepository_controller_test.go @@ -440,7 +440,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) { }, Spec: sourcev1.HelmRepositorySpec{ Interval: metav1.Duration{Duration: interval}, - Timeout: &metav1.Duration{Duration: interval}, + Timeout: &metav1.Duration{Duration: timeout}, }, }