Skip to content

Commit a07364f

Browse files
author
Eric Stroczynski
authored
testdata: remove unnecessary newlines (#4622)
Signed-off-by: Eric Stroczynski <[email protected]>
1 parent aa51fda commit a07364f

File tree

5 files changed

+14
-17
lines changed

5 files changed

+14
-17
lines changed

internal/testutils/utils.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package testutils
1616

1717
import (
18+
"bufio"
1819
"bytes"
1920
"errors"
2021
"fmt"
@@ -193,12 +194,22 @@ func UncommentCode(filename, target, prefix string) error {
193194
return err
194195
}
195196

196-
strs := strings.Split(target, "\n")
197-
for _, str := range strs {
198-
_, err := out.WriteString(strings.TrimPrefix(str, prefix) + "\n")
197+
scanner := bufio.NewScanner(bytes.NewBufferString(target))
198+
if !scanner.Scan() {
199+
return nil
200+
}
201+
for {
202+
_, err := out.WriteString(strings.TrimPrefix(scanner.Text(), prefix))
199203
if err != nil {
200204
return err
201205
}
206+
// Avoid writing a newline in case the previous line was the last in target.
207+
if !scanner.Scan() {
208+
break
209+
}
210+
if _, err := out.WriteString("\n"); err != nil {
211+
return err
212+
}
202213
}
203214

204215
_, err = out.Write(content[idx+len(target):])

testdata/ansible/memcached-operator/config/default/kustomization.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ bases:
1919
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
2020
- ../prometheus
2121

22-
2322
patchesStrategicMerge:
2423
# Protect the /metrics endpoint by putting it behind auth.
2524
# If you want your controller-manager to expose the /metrics

testdata/go/v2/memcached-operator/config/default/kustomization.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@ bases:
1919
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
2020
# crd/kustomization.yaml
2121
- ../webhook
22-
2322
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
2423
- ../certmanager
25-
2624
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
2725
- ../prometheus
2826

29-
3027
patchesStrategicMerge:
3128
# Protect the /metrics endpoint by putting it behind auth.
3229
# If you want your controller-manager to expose the /metrics
@@ -37,13 +34,11 @@ patchesStrategicMerge:
3734
# crd/kustomization.yaml
3835
- manager_webhook_patch.yaml
3936

40-
4137
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'.
4238
# Uncomment 'CERTMANAGER' sections in crd/kustomization.yaml to enable the CA injection in the admission webhooks.
4339
# 'CERTMANAGER' needs to be enabled to use ca injection
4440
- webhookcainjection_patch.yaml
4541

46-
4742
# the following config is for teaching kustomize how to do var substitution
4843
vars:
4944
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
@@ -73,4 +68,3 @@ vars:
7368
kind: Service
7469
version: v1
7570
name: webhook-service
76-

testdata/go/v3/memcached-operator/config/default/kustomization.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@ bases:
1919
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
2020
# crd/kustomization.yaml
2121
- ../webhook
22-
2322
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
2423
- ../certmanager
25-
2624
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
2725
- ../prometheus
2826

29-
3027
patchesStrategicMerge:
3128
# Protect the /metrics endpoint by putting it behind auth.
3229
# If you want your controller-manager to expose the /metrics
@@ -41,13 +38,11 @@ patchesStrategicMerge:
4138
# crd/kustomization.yaml
4239
- manager_webhook_patch.yaml
4340

44-
4541
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'.
4642
# Uncomment 'CERTMANAGER' sections in crd/kustomization.yaml to enable the CA injection in the admission webhooks.
4743
# 'CERTMANAGER' needs to be enabled to use ca injection
4844
- webhookcainjection_patch.yaml
4945

50-
5146
# the following config is for teaching kustomize how to do var substitution
5247
vars:
5348
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
@@ -77,4 +72,3 @@ vars:
7772
kind: Service
7873
version: v1
7974
name: webhook-service
80-

testdata/helm/memcached-operator/config/default/kustomization.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ bases:
1919
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
2020
- ../prometheus
2121

22-
2322
patchesStrategicMerge:
2423
# Protect the /metrics endpoint by putting it behind auth.
2524
# If you want your controller-manager to expose the /metrics

0 commit comments

Comments
 (0)