@@ -55,15 +55,21 @@ secretName: nutanix-ccm-credentials
5555`
5656)
5757
58- var valuesTemplateFile = filepath .Join (
59- moduleRootDir (),
60- "charts" ,
61- "cluster-api-runtime-extensions-nutanix" ,
62- "addons" ,
63- "ccm" ,
64- "nutanix" ,
65- "values-template.yaml" ,
66- )
58+ var valuesTemplateFile = func () string {
59+ dir , err := moduleRootDir ()
60+ if err != nil {
61+ panic (err )
62+ }
63+ return filepath .Join (
64+ dir ,
65+ "charts" ,
66+ "cluster-api-runtime-extensions-nutanix" ,
67+ "addons" ,
68+ "ccm" ,
69+ "nutanix" ,
70+ "values-template.yaml" ,
71+ )
72+ }()
6773
6874func Test_templateValues (t * testing.T ) {
6975 t .Parallel ()
@@ -194,20 +200,18 @@ func readCCMValuesTemplateFromProjectHelmChart(t *testing.T) string {
194200 return string (bs )
195201}
196202
197- func moduleRootDir () string {
203+ func moduleRootDir () ( string , error ) {
198204 cmd := exec .Command ("go" , "list" , "-m" , "-f" , "{{ .Dir }}" )
199205 out , err := cmd .CombinedOutput ()
200- if err != nil {
206+ if err != nil || len ( out ) == 0 {
201207 // We include the combined output because the error is usually
202208 // an exit code, which does not explain why the command failed.
203- panic (
204- fmt .Sprintf ("cmd.Dir=%q, cmd.Env=%q, cmd.Args=%q, err=%q, output=%q" ,
205- cmd .Dir ,
206- cmd .Env ,
207- cmd .Args ,
208- err ,
209- out ),
210- )
209+ return "" , fmt .Errorf ("cmd.Dir=%q, cmd.Env=%q, cmd.Args=%q, err=%q, output=%q" ,
210+ cmd .Dir ,
211+ cmd .Env ,
212+ cmd .Args ,
213+ err ,
214+ out )
211215 }
212216 // The first line is the module root directory. When go workspaces are used,
213217 // the first line is the "root" module root directory.
0 commit comments