@@ -46,27 +46,23 @@ import (
4646)
4747
4848const (
49- // clusterStopTimeout bounds the wait for cluster.Start to return after the
50- // context is canceled, so a runnable that will not stop is named rather
51- // than running the binary out of its -timeout.
49+ // Names a runnable that will not stop, rather than letting it run the
50+ // binary out of its -timeout.
5251 clusterStopTimeout = time .Minute
5352
5453 clusterLogLimit = 100 * 1000
55-
56- // receiverLogTail is the tail length the suites read from the test receiver.
5754 receiverLogTail = 30
5855
5956 // waitBudget and waitInterval are what the suites spend by hand today.
6057 waitBudget = 5 * time .Minute
6158 waitInterval = 3 * time .Second
6259
63- // teardownMargin is held back from the budget so a wait that runs to the
64- // end still leaves time to dump logs and delete the cluster.
60+ // Leaves a wait that runs to the end time to tear down.
6561 teardownMargin = 90 * time .Second
6662)
6763
68- // defaultSchemeBuilders covers every type the suites register today except the
69- // prometheus-operator ones, which only logging_metrics_monitoring needs.
64+ // Everything the suites register except the prometheus-operator types, which
65+ // only logging_metrics_monitoring needs.
7066var defaultSchemeBuilders = []func (* runtime.Scheme ) error {
7167 v1beta1 .AddToScheme ,
7268 apiextensionsv1 .AddToScheme ,
@@ -94,27 +90,24 @@ func New(t *testing.T) *Builder {
9490 return & Builder {t : t }
9591}
9692
97- // WithCluster names the kind cluster. Named rather than derived from t.Name():
98- // kind accepts only [a-z0-9.-] and none of the test names match.
93+ // WithCluster is named rather than derived from t.Name(): kind accepts only
94+ // [a-z0-9.-] and none of the test names match.
9995func (b * Builder ) WithCluster (name string ) * Builder {
10096 b .cfg .cluster = name
10197 return b
10298}
10399
104- // WithRelease names the helm release, and the operator's nameOverride with it.
105100func (b * Builder ) WithRelease (name string ) * Builder {
106101 b .cfg .release = name
107102 return b
108103}
109104
110- // WithControlNamespace sets where the operator and the test receiver run.
111105func (b * Builder ) WithControlNamespace (namespace string ) * Builder {
112106 b .cfg .controlNamespace = namespace
113107 return b
114108}
115109
116- // WithNamespaces are created before the test body and dumped at teardown
117- // alongside the control namespace and default.
110+ // WithNamespaces are also dumped at teardown.
118111func (b * Builder ) WithNamespaces (namespaces ... string ) * Builder {
119112 b .cfg .namespaces = append (b .cfg .namespaces , namespaces ... )
120113 return b
@@ -125,7 +118,6 @@ func (b *Builder) WithOperatorArgs(args ...string) *Builder {
125118 return b
126119}
127120
128- // WithScheme registers types on top of the shared set.
129121func (b * Builder ) WithScheme (add ... func (* runtime.Scheme ) error ) * Builder {
130122 b .cfg .schemeBuilders = append (b .cfg .schemeBuilders , add ... )
131123 return b
@@ -144,8 +136,7 @@ type Env struct {
144136 dumpNamespaces []string
145137}
146138
147- // Start brings up the cluster, installs the operator and registers teardown.
148- // It marks the test parallel, so it has to be the first call in the test.
139+ // Start marks the test parallel, so it has to be the first call in the test.
149140func (b * Builder ) Start () * Env {
150141 t := b .t
151142 common .Initialize (t )
@@ -204,8 +195,7 @@ func (e *Env) Create(objects ...client.Object) {
204195 }
205196}
206197
207- // StartLogProducer runs on the test goroutine: the create errors reach it
208- // through RequireNoError, which needs FailNow to be defined.
198+ // StartLogProducer runs on the test goroutine, where FailNow is defined.
209199func (e * Env ) StartLogProducer (namespace string , labels map [string ]string ) {
210200 e .T .Helper ()
211201 setup .LogProducer (e .T , e .Client , setup .LogProducerOptionFunc (func (o * setup.LogProducerOptions ) {
@@ -214,8 +204,6 @@ func (e *Env) StartLogProducer(namespace string, labels map[string]string) {
214204 }))
215205}
216206
217- // WaitForRunning blocks until every condition holds, and names the one that
218- // did not if it runs out of budget.
219207func (e * Env ) WaitForRunning (conditions ... wait.Condition ) {
220208 e .T .Helper ()
221209
@@ -235,9 +223,8 @@ func (e *Env) WaitForRunning(conditions ...wait.Condition) {
235223 }, e .waitBudget (), waitInterval , "still waiting for %s" , & outstanding )
236224}
237225
238- // WaitForReceiverLogs blocks until the test receiver has logged every tag, and
239- // names the one still missing if it runs out of budget. The tail itself is not
240- // echoed each poll: the archived cluster dump already has the receiver's log.
226+ // WaitForReceiverLogs does not echo the tail each poll: the archived cluster
227+ // dump already carries the receiver's log.
241228func (e * Env ) WaitForReceiverLogs (tags ... string ) {
242229 e .T .Helper ()
243230
@@ -258,8 +245,6 @@ func (e *Env) WaitForReceiverLogs(tags ...string) {
258245 }, e .waitBudget (), waitInterval , "the test receiver never logged %s" , & outstanding )
259246}
260247
261- // ReceiverLogs returns the tail of the chart's test receiver, which is where a
262- // suite looks to see that its logs arrived.
263248func (e * Env ) ReceiverLogs (tail int ) (string , error ) {
264249 out , err := common .CmdEnv (exec .Command ("kubectl" ,
265250 "logs" ,
@@ -269,8 +254,8 @@ func (e *Env) ReceiverLogs(tail int) (string, error) {
269254 return string (out ), err
270255}
271256
272- // waitBudget is what the suites spend today, held under what is left of the
273- // binary's deadline so one wait cannot take the package's whole budget with it.
257+ // waitBudget holds a wait under what is left of the binary's deadline, so one
258+ // cannot take the package's whole budget with it.
274259func (e * Env ) waitBudget () time.Duration {
275260 deadline , ok := e .T .Deadline ()
276261 if ! ok {
@@ -308,7 +293,6 @@ type step struct {
308293
309294type teardown []step
310295
311- // cleanupT is the part of testing.T register needs.
312296type cleanupT interface {
313297 Cleanup (func ())
314298 Errorf (format string , args ... any )
@@ -356,7 +340,7 @@ func (e *Env) collectArtifacts() {
356340 operator := "logging-operator-" + e .Release
357341 e .T .Logf ("Collecting coverage files from logging-operator: %s/%s" , e .ControlNamespace , operator )
358342 if err := e .Cluster .CollectTestCoverageFiles (e .ControlNamespace , operator ); err != nil {
359- // Logged, never fatal: the run's coverage is not the suite's verdict.
343+ // Logged, never fatal: coverage is not the suite's verdict.
360344 e .T .Logf ("Failed collecting coverage files: %s" , err )
361345 }
362346}
@@ -371,11 +355,11 @@ func buildScheme(extra []func(*runtime.Scheme) error) (*runtime.Scheme, error) {
371355 return scheme , nil
372356}
373357
374- // dumpNamespaces is the control namespace, the configured ones and default,
375- // without repeats, so a suite that names one does not dump it twice.
376358func dumpNamespaces (cfg config ) []string {
377359 out := make ([]string , 0 , len (cfg .namespaces )+ 2 )
378360 seen := map [string ]bool {}
361+ // Concat, not append: appending to cfg.namespaces could write into the
362+ // caller's backing array.
379363 for _ , ns := range slices .Concat ([]string {cfg .controlNamespace }, cfg .namespaces , []string {"default" }) {
380364 if ns != "" && ! seen [ns ] {
381365 seen [ns ] = true
@@ -385,8 +369,6 @@ func dumpNamespaces(cfg config) []string {
385369 return out
386370}
387371
388- // artifactPath is build/_test under PROJECT_DIR, the directory every suite
389- // used to build for itself in an init().
390372func artifactPath (name string ) (string , error ) {
391373 root , ok := os .LookupEnv ("PROJECT_DIR" )
392374 if ! ok {
0 commit comments