@@ -21,6 +21,7 @@ import (
2121 "os"
2222 "path/filepath"
2323 "runtime"
24+ "strings"
2425 "time"
2526
2627 . "github.com/onsi/ginkgo/v2"
@@ -35,9 +36,48 @@ import (
3536var _ = Describe ("All CSIs Stress Tests" , Ordered , func () {
3637 var (
3738 testClusterResources * cluster.TestClusterResources
39+ testDir string
40+ crFiles []string
41+ crFilesDir string
42+ storageClassNames []string
3843 )
3944
4045 BeforeAll (func () {
46+ By ("Setting up test variables" , func () {
47+ _ , callerFile , _ , ok := runtime .Caller (0 )
48+ Expect (ok ).To (BeTrue (), "Failed to determine test file path" )
49+ testDir = filepath .Dir (callerFile )
50+
51+ crFiles = []string {"csi-huawei-cr.yml" , "csi-hpe-cr.yml" , "csi-netapp-cr.yml" }
52+ crFilesDir = filepath .Join (testDir , "files" )
53+
54+ storageClassNames = []string {"hsclass-200" , "hpe-iscsi" , "csi-netapp-sc1" }
55+ })
56+
57+ By ("Validating environment variables in CR files" , func () {
58+ var allUnsetVars []string
59+
60+ for _ , fileName := range crFiles {
61+ filePath := filepath .Join (crFilesDir , fileName )
62+
63+ // Skip if file doesn't exist
64+ if _ , err := os .Stat (filePath ); os .IsNotExist (err ) {
65+ continue
66+ }
67+
68+ content , err := os .ReadFile (filePath )
69+ Expect (err ).NotTo (HaveOccurred (), "Failed to read file: " + fileName )
70+
71+ unsetVars := kubernetes .FindUnsetEnvVars (string (content ))
72+ if len (unsetVars ) > 0 {
73+ GinkgoWriter .Printf (" ❌ %s requires env vars: %v\n " , fileName , unsetVars )
74+ allUnsetVars = append (allUnsetVars , unsetVars ... )
75+ }
76+ }
77+
78+ Expect (allUnsetVars ).To (BeEmpty (), "Environment variables for custom resources are not set: " + strings .Join (allUnsetVars , ", " ))
79+ })
80+
4181 By ("Outputting environment variables" , func () {
4282 GinkgoWriter .Printf (" 📋 Environment variables (without default values):\n " )
4383
@@ -154,12 +194,6 @@ var _ = Describe("All CSIs Stress Tests", Ordered, func() {
154194 It ("should create NGCs" , func () {
155195 ctx := context .Background ()
156196
157- // Resolve file path relative to test directory (same approach as CreateTestCluster)
158- // runtime.Caller(0) gets this test file's location
159- _ , callerFile , _ , ok := runtime .Caller (0 )
160- Expect (ok ).To (BeTrue (), "Failed to determine test file path" )
161- testDir := filepath .Dir (callerFile )
162-
163197 yamlFilePathNGCs := filepath .Join (testDir , "files" , "ngc.yml" )
164198
165199 By ("Applying NGCs" , func () {
@@ -180,48 +214,31 @@ var _ = Describe("All CSIs Stress Tests", Ordered, func() {
180214
181215 It ("should create modules' custom resources" , func () {
182216 ctx := context .Background ()
183- crFiles := []string {"csi-huawei-cr.yml" , "csi-hpe-cr.yml" , "csi-netapp-cr.yml" }
184-
185- // Resolve file path relative to test directory
186- _ , callerFile , _ , ok := runtime .Caller (0 )
187- Expect (ok ).To (BeTrue (), "Failed to determine test file path" )
188- testDir := filepath .Dir (callerFile )
189- filesDir := filepath .Join (testDir , "files" )
190217
191218 By ("Applying all storage custom resources" , func () {
192219 GinkgoWriter .Printf (" ▶️ Creating storage resources from %d files...\n " , len (crFiles ))
193220
194- var combinedContent string
221+ applyClient , err := kubernetes .NewApplyClient (testClusterResources .Kubeconfig )
222+ Expect (err ).NotTo (HaveOccurred (), "Failed to create apply client" )
223+
195224 for _ , fileName := range crFiles {
196- filePath := filepath .Join (filesDir , fileName )
225+ filePath := filepath .Join (crFilesDir , fileName )
197226
198227 // Skip if file doesn't exist
199228 if _ , err := os .Stat (filePath ); os .IsNotExist (err ) {
200229 GinkgoWriter .Printf (" ⏭️ Skipping %s (file not found)\n " , fileName )
201230 continue
202231 }
203232
204- content , err := os .ReadFile (filePath )
205- Expect (err ).NotTo (HaveOccurred (), "Failed to read file: " + fileName )
206-
207- // Add document separator if not first file
208- if combinedContent != "" {
209- combinedContent += "\n ---\n "
210- }
211- combinedContent += string (content )
233+ GinkgoWriter .Printf (" 📄 Applying %s...\n " , fileName )
234+ err = applyClient .CreateYAMLFromFileWithEnvvars (ctx , filePath , "" )
235+ Expect (err ).NotTo (HaveOccurred (), "Failed to apply " + fileName )
212236 }
213237
214- applyClient , err := kubernetes .NewApplyClient (testClusterResources .Kubeconfig )
215- Expect (err ).NotTo (HaveOccurred (), "Failed to create apply client" )
216-
217- err = applyClient .CreateYAML (ctx , combinedContent , "" )
218- Expect (err ).NotTo (HaveOccurred (), "Failed to apply YAML resources" )
219-
220238 GinkgoWriter .Printf (" ✅ Resources created successfully\n " )
221239 })
222240
223241 By ("Waiting for StorageClasses to become available" , func () {
224- storageClassNames := []string {"hsclass-200" , "hpe" , "netapp" }
225242
226243 GinkgoWriter .Printf (" ▶️ Waiting for %d StorageClasses...\n " , len (storageClassNames ))
227244
0 commit comments