Skip to content

Commit 2b35f33

Browse files
authored
Merge pull request #4694 from kersten/chore/test-utils
🐛 (go/v4): wrap test command execution errors with %w in test utils
2 parents b01bdc6 + 5a801c6 commit 2b35f33

File tree

10 files changed

+31
-31
lines changed

10 files changed

+31
-31
lines changed

docs/book/src/cronjob-tutorial/testdata/project/internal/controller/cronjob_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func (r *CronJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
344344
getNextSchedule := func(cronJob *batchv1.CronJob, now time.Time) (lastMissed time.Time, next time.Time, err error) {
345345
sched, err := cron.ParseStandard(cronJob.Spec.Schedule)
346346
if err != nil {
347-
return time.Time{}, time.Time{}, fmt.Errorf("Unparseable schedule %q: %v", cronJob.Spec.Schedule, err)
347+
return time.Time{}, time.Time{}, fmt.Errorf("unparseable schedule %q: %w", cronJob.Spec.Schedule, err)
348348
}
349349

350350
// for optimization purposes, cheat a bit and start from our last observed run time

docs/book/src/cronjob-tutorial/testdata/project/test/utils/utils.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ func Run(cmd *exec.Cmd) (string, error) {
4646
cmd.Dir = dir
4747

4848
if err := os.Chdir(cmd.Dir); err != nil {
49-
_, _ = fmt.Fprintf(GinkgoWriter, "chdir dir: %s\n", err)
49+
_, _ = fmt.Fprintf(GinkgoWriter, "chdir dir: %q\n", err)
5050
}
5151

5252
cmd.Env = append(os.Environ(), "GO111MODULE=on")
5353
command := strings.Join(cmd.Args, " ")
54-
_, _ = fmt.Fprintf(GinkgoWriter, "running: %s\n", command)
54+
_, _ = fmt.Fprintf(GinkgoWriter, "running: %q\n", command)
5555
output, err := cmd.CombinedOutput()
5656
if err != nil {
57-
return string(output), fmt.Errorf("%s failed with error: (%v) %s", command, err, string(output))
57+
return string(output), fmt.Errorf("%q failed with error %q: %w", command, string(output), err)
5858
}
5959

6060
return string(output), nil
@@ -214,7 +214,7 @@ func UncommentCode(filename, target, prefix string) error {
214214

215215
idx := strings.Index(strContent, target)
216216
if idx < 0 {
217-
return fmt.Errorf("unable to find the code %s to be uncomment", target)
217+
return fmt.Errorf("unable to find the code %q to be uncomment", target)
218218
}
219219

220220
out := new(bytes.Buffer)

docs/book/src/getting-started/testdata/project/test/utils/utils.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ func Run(cmd *exec.Cmd) (string, error) {
4646
cmd.Dir = dir
4747

4848
if err := os.Chdir(cmd.Dir); err != nil {
49-
_, _ = fmt.Fprintf(GinkgoWriter, "chdir dir: %s\n", err)
49+
_, _ = fmt.Fprintf(GinkgoWriter, "chdir dir: %q\n", err)
5050
}
5151

5252
cmd.Env = append(os.Environ(), "GO111MODULE=on")
5353
command := strings.Join(cmd.Args, " ")
54-
_, _ = fmt.Fprintf(GinkgoWriter, "running: %s\n", command)
54+
_, _ = fmt.Fprintf(GinkgoWriter, "running: %q\n", command)
5555
output, err := cmd.CombinedOutput()
5656
if err != nil {
57-
return string(output), fmt.Errorf("%s failed with error: (%v) %s", command, err, string(output))
57+
return string(output), fmt.Errorf("%q failed with error %q: %w", command, string(output), err)
5858
}
5959

6060
return string(output), nil
@@ -214,7 +214,7 @@ func UncommentCode(filename, target, prefix string) error {
214214

215215
idx := strings.Index(strContent, target)
216216
if idx < 0 {
217-
return fmt.Errorf("unable to find the code %s to be uncomment", target)
217+
return fmt.Errorf("unable to find the code %q to be uncomment", target)
218218
}
219219

220220
out := new(bytes.Buffer)

docs/book/src/multiversion-tutorial/testdata/project/internal/controller/cronjob_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func (r *CronJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
344344
getNextSchedule := func(cronJob *batchv1.CronJob, now time.Time) (lastMissed time.Time, next time.Time, err error) {
345345
sched, err := cron.ParseStandard(cronJob.Spec.Schedule)
346346
if err != nil {
347-
return time.Time{}, time.Time{}, fmt.Errorf("Unparseable schedule %q: %v", cronJob.Spec.Schedule, err)
347+
return time.Time{}, time.Time{}, fmt.Errorf("unparseable schedule %q: %w", cronJob.Spec.Schedule, err)
348348
}
349349

350350
// for optimization purposes, cheat a bit and start from our last observed run time

docs/book/src/multiversion-tutorial/testdata/project/test/utils/utils.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ func Run(cmd *exec.Cmd) (string, error) {
4646
cmd.Dir = dir
4747

4848
if err := os.Chdir(cmd.Dir); err != nil {
49-
_, _ = fmt.Fprintf(GinkgoWriter, "chdir dir: %s\n", err)
49+
_, _ = fmt.Fprintf(GinkgoWriter, "chdir dir: %q\n", err)
5050
}
5151

5252
cmd.Env = append(os.Environ(), "GO111MODULE=on")
5353
command := strings.Join(cmd.Args, " ")
54-
_, _ = fmt.Fprintf(GinkgoWriter, "running: %s\n", command)
54+
_, _ = fmt.Fprintf(GinkgoWriter, "running: %q\n", command)
5555
output, err := cmd.CombinedOutput()
5656
if err != nil {
57-
return string(output), fmt.Errorf("%s failed with error: (%v) %s", command, err, string(output))
57+
return string(output), fmt.Errorf("%q failed with error %q: %w", command, string(output), err)
5858
}
5959

6060
return string(output), nil
@@ -214,7 +214,7 @@ func UncommentCode(filename, target, prefix string) error {
214214

215215
idx := strings.Index(strContent, target)
216216
if idx < 0 {
217-
return fmt.Errorf("unable to find the code %s to be uncomment", target)
217+
return fmt.Errorf("unable to find the code %q to be uncomment", target)
218218
}
219219

220220
out := new(bytes.Buffer)

hack/docs/internal/cronjob-tutorial/controller_implementation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ const controllerReconcileLogic = `log := logf.FromContext(ctx)
333333
getNextSchedule := func(cronJob *batchv1.CronJob, now time.Time) (lastMissed time.Time, next time.Time, err error) {
334334
sched, err := cron.ParseStandard(cronJob.Spec.Schedule)
335335
if err != nil {
336-
return time.Time{}, time.Time{}, fmt.Errorf("Unparseable schedule %q: %v", cronJob.Spec.Schedule, err)
336+
return time.Time{}, time.Time{}, fmt.Errorf("unparseable schedule %q: %w", cronJob.Spec.Schedule, err)
337337
}
338338
339339
// for optimization purposes, cheat a bit and start from our last observed run time

pkg/plugins/golang/v4/scaffolds/internal/templates/test/utils/utils.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ func Run(cmd *exec.Cmd) (string, error) {
7373
cmd.Dir = dir
7474
7575
if err := os.Chdir(cmd.Dir); err != nil {
76-
_, _ = fmt.Fprintf(GinkgoWriter, "chdir dir: %s\n", err)
76+
_, _ = fmt.Fprintf(GinkgoWriter, "chdir dir: %q\n", err)
7777
}
7878
7979
cmd.Env = append(os.Environ(), "GO111MODULE=on")
8080
command := strings.Join(cmd.Args, " ")
81-
_, _ = fmt.Fprintf(GinkgoWriter, "running: %s\n", command)
81+
_, _ = fmt.Fprintf(GinkgoWriter, "running: %q\n", command)
8282
output, err := cmd.CombinedOutput()
8383
if err != nil {
84-
return string(output), fmt.Errorf("%s failed with error: (%v) %s", command, err, string(output))
84+
return string(output), fmt.Errorf("%q failed with error %q: %w", command, string(output), err)
8585
}
8686
8787
return string(output), nil
@@ -242,7 +242,7 @@ func UncommentCode(filename, target, prefix string) error {
242242
243243
idx := strings.Index(strContent, target)
244244
if idx < 0 {
245-
return fmt.Errorf("unable to find the code %s to be uncomment", target)
245+
return fmt.Errorf("unable to find the code %q to be uncomment", target)
246246
}
247247
248248
out := new(bytes.Buffer)

testdata/project-v4-multigroup/test/utils/utils.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ func Run(cmd *exec.Cmd) (string, error) {
4646
cmd.Dir = dir
4747

4848
if err := os.Chdir(cmd.Dir); err != nil {
49-
_, _ = fmt.Fprintf(GinkgoWriter, "chdir dir: %s\n", err)
49+
_, _ = fmt.Fprintf(GinkgoWriter, "chdir dir: %q\n", err)
5050
}
5151

5252
cmd.Env = append(os.Environ(), "GO111MODULE=on")
5353
command := strings.Join(cmd.Args, " ")
54-
_, _ = fmt.Fprintf(GinkgoWriter, "running: %s\n", command)
54+
_, _ = fmt.Fprintf(GinkgoWriter, "running: %q\n", command)
5555
output, err := cmd.CombinedOutput()
5656
if err != nil {
57-
return string(output), fmt.Errorf("%s failed with error: (%v) %s", command, err, string(output))
57+
return string(output), fmt.Errorf("%q failed with error %q: %w", command, string(output), err)
5858
}
5959

6060
return string(output), nil
@@ -214,7 +214,7 @@ func UncommentCode(filename, target, prefix string) error {
214214

215215
idx := strings.Index(strContent, target)
216216
if idx < 0 {
217-
return fmt.Errorf("unable to find the code %s to be uncomment", target)
217+
return fmt.Errorf("unable to find the code %q to be uncomment", target)
218218
}
219219

220220
out := new(bytes.Buffer)

testdata/project-v4-with-plugins/test/utils/utils.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ func Run(cmd *exec.Cmd) (string, error) {
4646
cmd.Dir = dir
4747

4848
if err := os.Chdir(cmd.Dir); err != nil {
49-
_, _ = fmt.Fprintf(GinkgoWriter, "chdir dir: %s\n", err)
49+
_, _ = fmt.Fprintf(GinkgoWriter, "chdir dir: %q\n", err)
5050
}
5151

5252
cmd.Env = append(os.Environ(), "GO111MODULE=on")
5353
command := strings.Join(cmd.Args, " ")
54-
_, _ = fmt.Fprintf(GinkgoWriter, "running: %s\n", command)
54+
_, _ = fmt.Fprintf(GinkgoWriter, "running: %q\n", command)
5555
output, err := cmd.CombinedOutput()
5656
if err != nil {
57-
return string(output), fmt.Errorf("%s failed with error: (%v) %s", command, err, string(output))
57+
return string(output), fmt.Errorf("%q failed with error %q: %w", command, string(output), err)
5858
}
5959

6060
return string(output), nil
@@ -214,7 +214,7 @@ func UncommentCode(filename, target, prefix string) error {
214214

215215
idx := strings.Index(strContent, target)
216216
if idx < 0 {
217-
return fmt.Errorf("unable to find the code %s to be uncomment", target)
217+
return fmt.Errorf("unable to find the code %q to be uncomment", target)
218218
}
219219

220220
out := new(bytes.Buffer)

testdata/project-v4/test/utils/utils.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ func Run(cmd *exec.Cmd) (string, error) {
4646
cmd.Dir = dir
4747

4848
if err := os.Chdir(cmd.Dir); err != nil {
49-
_, _ = fmt.Fprintf(GinkgoWriter, "chdir dir: %s\n", err)
49+
_, _ = fmt.Fprintf(GinkgoWriter, "chdir dir: %q\n", err)
5050
}
5151

5252
cmd.Env = append(os.Environ(), "GO111MODULE=on")
5353
command := strings.Join(cmd.Args, " ")
54-
_, _ = fmt.Fprintf(GinkgoWriter, "running: %s\n", command)
54+
_, _ = fmt.Fprintf(GinkgoWriter, "running: %q\n", command)
5555
output, err := cmd.CombinedOutput()
5656
if err != nil {
57-
return string(output), fmt.Errorf("%s failed with error: (%v) %s", command, err, string(output))
57+
return string(output), fmt.Errorf("%q failed with error %q: %w", command, string(output), err)
5858
}
5959

6060
return string(output), nil
@@ -214,7 +214,7 @@ func UncommentCode(filename, target, prefix string) error {
214214

215215
idx := strings.Index(strContent, target)
216216
if idx < 0 {
217-
return fmt.Errorf("unable to find the code %s to be uncomment", target)
217+
return fmt.Errorf("unable to find the code %q to be uncomment", target)
218218
}
219219

220220
out := new(bytes.Buffer)

0 commit comments

Comments
 (0)