@@ -143,6 +143,32 @@ func TestBuildPodSpec_CodeVolumeImage(t *testing.T) {
143143 t .Error ("code volume not found" )
144144}
145145
146+ // TestBuildPodSpec_CodeVolumeDefaultsMountPath is a regression test for #463:
147+ // when spec.code is set but spec.puppet.environmentPath is empty (e.g. a
148+ // hand-written Config that omits the whole spec.puppet block, so the CRD default
149+ // is never applied), the code volume must still render a valid mountPath rather
150+ // than "", which the Kubernetes API rejects.
151+ func TestBuildPodSpec_CodeVolumeDefaultsMountPath (t * testing.T ) {
152+ cfg := newConfig ("production" , withCodeImage ("ghcr.io/slauger/puppet-code:v1.0" ))
153+ cfg .Spec .Puppet .EnvironmentPath = ""
154+ server := newServer ("test-server" , withServerRole (true ))
155+
156+ podSpec := testBuildPodSpec (server , cfg )
157+
158+ found := false
159+ for _ , vm := range podSpec .Containers [0 ].VolumeMounts {
160+ if vm .Name == "code" {
161+ found = true
162+ if vm .MountPath != defaultEnvironmentPath {
163+ t .Errorf ("expected code mountPath %q, got %q" , defaultEnvironmentPath , vm .MountPath )
164+ }
165+ }
166+ }
167+ if ! found {
168+ t .Fatal ("code volume mount not found" )
169+ }
170+ }
171+
146172func TestBuildPodSpec_CodeVolumePVC (t * testing.T ) {
147173 cfg := newConfig ("production" , withCodePVC ("puppet-code-pvc" ))
148174 server := newServer ("test-server" , withServerRole (true ))
0 commit comments