@@ -5,6 +5,7 @@ package test
5
5
import (
6
6
"os"
7
7
"path/filepath"
8
+ "strings"
8
9
"testing"
9
10
10
11
"github.com/gkampitakis/go-snaps/snaps"
@@ -130,8 +131,8 @@ func TestHelmNICTemplate(t *testing.T) {
130
131
releaseName : "app-protect-waf-agentv2" ,
131
132
namespace : "default" ,
132
133
},
133
- "startupStatus " : {
134
- valuesFile : "testdata/startupstatus.yaml" ,
134
+ "startupStatusValid " : {
135
+ valuesFile : "testdata/startupstatus-valid .yaml" ,
135
136
releaseName : "startupstatus" ,
136
137
namespace : "default" ,
137
138
},
@@ -160,3 +161,51 @@ func TestHelmNICTemplate(t *testing.T) {
160
161
})
161
162
}
162
163
}
164
+
165
+ // Test for negative cases where helm template rendering should fail
166
+ func TestHelmNICTemplateNegative (t * testing.T ) {
167
+ t .Parallel ()
168
+
169
+ negativeTests := map [string ]struct {
170
+ valuesFile string
171
+ releaseName string
172
+ namespace string
173
+ expectedErrorMsg string
174
+ }{
175
+ "startupStatusInvalid" : {
176
+ valuesFile : "testdata/startupstatus-invalid.yaml" ,
177
+ releaseName : "startupstatus-invalid" ,
178
+ namespace : "default" ,
179
+ expectedErrorMsg : "port is required" ,
180
+ },
181
+ }
182
+
183
+ // Path to the helm chart we will test
184
+ helmChartPath , err := filepath .Abs ("../nginx-ingress" )
185
+ if err != nil {
186
+ t .Fatal ("Failed to open helm chart path ../nginx-ingress" )
187
+ }
188
+
189
+ for testName , tc := range negativeTests {
190
+ t .Run (testName , func (t * testing.T ) {
191
+ options := & helm.Options {
192
+ KubectlOptions : k8s .NewKubectlOptions ("" , "" , tc .namespace ),
193
+ }
194
+
195
+ if tc .valuesFile != "" {
196
+ options .ValuesFiles = []string {tc .valuesFile }
197
+ }
198
+ _ , err := helm .RenderTemplateE (t , options , helmChartPath , tc .releaseName , make ([]string , 0 ))
199
+
200
+ if err == nil {
201
+ t .Fatalf ("Expected helm template to fail for invalid configuration, but it succeeded" )
202
+ }
203
+
204
+ if tc .expectedErrorMsg != "" && ! strings .Contains (err .Error (), tc .expectedErrorMsg ) {
205
+ t .Fatalf ("Expected error to contain '%s', but got: %s" , tc .expectedErrorMsg , err .Error ())
206
+ }
207
+
208
+ t .Logf ("Expected failure occurred: %s" , err .Error ())
209
+ })
210
+ }
211
+ }
0 commit comments