@@ -55,15 +55,21 @@ secretName: nutanix-ccm-credentials
55
55
`
56
56
)
57
57
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
+ }()
67
73
68
74
func Test_templateValues (t * testing.T ) {
69
75
t .Parallel ()
@@ -194,20 +200,18 @@ func readCCMValuesTemplateFromProjectHelmChart(t *testing.T) string {
194
200
return string (bs )
195
201
}
196
202
197
- func moduleRootDir () string {
203
+ func moduleRootDir () ( string , error ) {
198
204
cmd := exec .Command ("go" , "list" , "-m" , "-f" , "{{ .Dir }}" )
199
205
out , err := cmd .CombinedOutput ()
200
- if err != nil {
206
+ if err != nil || len ( out ) == 0 {
201
207
// We include the combined output because the error is usually
202
208
// 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 )
211
215
}
212
216
// The first line is the module root directory. When go workspaces are used,
213
217
// the first line is the "root" module root directory.
0 commit comments