@@ -20,8 +20,6 @@ limitations under the License.
2020package e2e
2121
2222import (
23- "fmt"
24- "os"
2523 "os/exec"
2624 "testing"
2725
@@ -31,74 +29,50 @@ import (
3129 "github.com/syscode-labs/imp/test/utils"
3230)
3331
34- var (
35- // managerImage is the manager image to be built and loaded for testing.
36- managerImage = "imp-operator:dev"
37- // shouldCleanupCertManager tracks whether CertManager was installed by this suite.
38- shouldCleanupCertManager = false
32+ const (
33+ namespace = "imp-system"
34+ helmRelease = "imp"
35+ helmCRDRelease = "imp-crds"
3936)
4037
41- // TestE2E runs the e2e test suite to validate the solution in an isolated environment.
42- // The default setup requires Kind and CertManager.
43- //
44- // To skip CertManager installation, set: CERT_MANAGER_INSTALL_SKIP=true
45- func TestE2E (t * testing.T ) {
46- RegisterFailHandler (Fail )
47- _ , _ = fmt .Fprintf (GinkgoWriter , "Starting imp e2e test suite\n " )
48- RunSpecs (t , "e2e suite" )
49- }
50-
5138var _ = BeforeSuite (func () {
52- By ("building the manager image" )
53- cmd := exec .Command ("make" , "docker-build" , fmt .Sprintf ("IMG=%s" , managerImage )) //nolint:gosec
54- _ , err := utils .Run (cmd )
55- ExpectWithOffset (1 , err ).NotTo (HaveOccurred (), "Failed to build the manager image" )
56-
57- By ("loading the manager image on Kind" )
58- err = utils .LoadImageToKindClusterWithName (managerImage )
59- ExpectWithOffset (1 , err ).NotTo (HaveOccurred (), "Failed to load the manager image into Kind" )
60-
61- // CertManager is only needed for webhooks. Skip unless CERT_MANAGER_INSTALL_SKIP=false.
62- if os .Getenv ("CERT_MANAGER_INSTALL_SKIP" ) != "false" {
63- _ , _ = fmt .Fprintf (GinkgoWriter , "Skipping CertManager (no webhooks in this build)\n " )
64- return
65- }
66- setupCertManager ()
39+ By ("creating namespace" )
40+ nsCmd := exec .Command ("kubectl" , "create" , "ns" , namespace )
41+ _ , _ = utils .Run (nsCmd ) // ignore if already exists
42+
43+ By ("installing cert-manager" )
44+ Expect (utils .InstallCertManager ()).To (Succeed (), "helm install cert-manager failed" )
45+
46+ By ("installing imp-crds chart" )
47+ crdsCmd := exec .Command ("helm" , "install" , helmCRDRelease , "charts/imp-crds" ,
48+ "--namespace" , namespace , "--wait" , "--create-namespace" )
49+ _ , err := utils .Run (crdsCmd )
50+ Expect (err ).NotTo (HaveOccurred (), "helm install imp-crds failed" )
51+
52+ By ("installing imp chart" )
53+ impCmd := exec .Command ("helm" , "install" , helmRelease , "charts/imp" ,
54+ "--namespace" , namespace ,
55+ "--set" , "metrics.serviceMonitor.enabled=false" ,
56+ "--set" , "metrics.podMonitor.enabled=false" ,
57+ "--wait" , "--timeout" , "2m" )
58+ _ , err = utils .Run (impCmd )
59+ Expect (err ).NotTo (HaveOccurred (), "helm install imp failed" )
6760})
6861
6962var _ = AfterSuite (func () {
70- teardownCertManager ()
71- })
63+ By ("uninstalling imp chart" )
64+ unimpCmd := exec .Command ("helm" , "uninstall" , helmRelease , "--namespace" , namespace )
65+ _ , _ = utils .Run (unimpCmd )
7266
73- // setupCertManager installs CertManager if needed for webhook tests.
74- // Skips installation if CERT_MANAGER_INSTALL_SKIP=true or if already present.
75- func setupCertManager () {
76- if os .Getenv ("CERT_MANAGER_INSTALL_SKIP" ) == "true" {
77- _ , _ = fmt .Fprintf (GinkgoWriter , "Skipping CertManager installation (CERT_MANAGER_INSTALL_SKIP=true)\n " )
78- return
79- }
80-
81- By ("checking if CertManager is already installed" )
82- if utils .IsCertManagerCRDsInstalled () {
83- _ , _ = fmt .Fprintf (GinkgoWriter , "CertManager is already installed. Skipping installation.\n " )
84- return
85- }
86-
87- // Mark for cleanup before installation to handle interruptions and partial installs.
88- shouldCleanupCertManager = true
89-
90- By ("installing CertManager" )
91- Expect (utils .InstallCertManager ()).To (Succeed (), "Failed to install CertManager" )
92- }
67+ By ("uninstalling imp-crds chart" )
68+ uncrdsCmd := exec .Command ("helm" , "uninstall" , helmCRDRelease , "--namespace" , namespace )
69+ _ , _ = utils .Run (uncrdsCmd )
9370
94- // teardownCertManager uninstalls CertManager if it was installed by setupCertManager.
95- // This ensures we only remove what we installed.
96- func teardownCertManager () {
97- if ! shouldCleanupCertManager {
98- _ , _ = fmt .Fprintf (GinkgoWriter , "Skipping CertManager cleanup (not installed by this suite)\n " )
99- return
100- }
101-
102- By ("uninstalling CertManager" )
71+ By ("uninstalling cert-manager" )
10372 utils .UninstallCertManager ()
73+ })
74+
75+ func TestE2E (t * testing.T ) {
76+ RegisterFailHandler (Fail )
77+ RunSpecs (t , "Imp E2E Suite" )
10478}
0 commit comments