-
Notifications
You must be signed in to change notification settings - Fork 27
/
basictests.go
583 lines (553 loc) · 20.4 KB
/
basictests.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
package e2e
import (
"archive/tar"
"compress/gzip"
"context"
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
"sigs.k8s.io/yaml"
"strings"
"testing"
"time"
cdx "github.com/CycloneDX/cyclonedx-go"
"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/redhat-appstudio/jvm-build-service/pkg/apis/jvmbuildservice/v1alpha1"
"github.com/redhat-appstudio/jvm-build-service/pkg/reconciler/artifactbuild"
tektonpipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
corev1 "k8s.io/api/core/v1"
v12 "k8s.io/api/events/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
v1 "k8s.io/client-go/kubernetes/typed/events/v1"
"knative.dev/pkg/apis"
)
func runBasicTests(t *testing.T, doSetup func(t *testing.T, namespace string) *testArgs, namespace string) {
runPipelineTests(t, doSetup, "run-e2e-shaded-app.yaml", namespace)
}
func runPipelineTests(t *testing.T, doSetup func(t *testing.T, namespace string) *testArgs, pipeline string, namespace string) {
ta := doSetup(t, namespace)
//TODO, for now at least, keeping our test project to allow for analyzing the various CRD instances both for failure
// and successful runs (in case a run succeeds, but we find something amiss if we look at passing runs; our in repo
// tests do now run in conjunction with say the full suite of e2e's in the e2e-tests runs, so no contention there.
//defer projectCleanup(ta)
path, err := os.Getwd()
if err != nil {
debugAndFailTest(ta, err.Error())
}
ta.Logf(fmt.Sprintf("current working dir: %s", path))
runYamlPath := filepath.Join(path, "..", "..", "hack", "examples", pipeline)
ta.run = &tektonpipeline.PipelineRun{}
var ok bool
obj := streamFileYamlToTektonObj(runYamlPath, ta.run, ta)
ta.run, ok = obj.(*tektonpipeline.PipelineRun)
if !ok {
debugAndFailTest(ta, fmt.Sprintf("file %s did not produce a pipelinerun: %#v", runYamlPath, obj))
}
set := os.Getenv("TESTSET")
//if the GAVS env var is set then we just create pre-defined GAVS
//otherwise we do a full build of a sample project
if len(set) > 0 {
bytes, err := os.ReadFile(filepath.Clean(filepath.Join(path, "minikube.yaml")))
if err != nil {
debugAndFailTest(ta, err.Error())
return
}
testData := map[string][]string{}
err = yaml.Unmarshal(bytes, &testData)
if err != nil {
debugAndFailTest(ta, err.Error())
return
}
parts := testData[set]
if len(parts) == 0 {
debugAndFailTest(ta, "No test data for "+set)
return
}
for _, s := range parts {
ta.Logf(fmt.Sprintf("Creating ArtifactBuild for GAV: %s", s))
ab := v1alpha1.ArtifactBuild{}
ab.Name = artifactbuild.CreateABRName(s)
ab.Namespace = ta.ns
ab.Spec.GAV = s
_, err := jvmClient.JvmbuildserviceV1alpha1().ArtifactBuilds(ta.ns).Create(context.TODO(), &ab, metav1.CreateOptions{})
if err != nil {
return
}
}
} else {
ta.run, err = tektonClient.TektonV1().PipelineRuns(ta.ns).Create(context.TODO(), ta.run, metav1.CreateOptions{})
if err != nil {
debugAndFailTest(ta, err.Error())
}
ta.t.Run("pipelinerun completes successfully", func(t *testing.T) {
err = wait.PollUntilContextTimeout(context.TODO(), ta.interval, ta.timeout, true, func(ctx context.Context) (done bool, err error) {
pr, err := tektonClient.TektonV1().PipelineRuns(ta.ns).Get(context.TODO(), ta.run.Name, metav1.GetOptions{})
if err != nil {
ta.Logf(fmt.Sprintf("get pr %s produced err: %s", ta.run.Name, err.Error()))
return false, nil
}
if !pr.IsDone() {
if err != nil {
ta.Logf(fmt.Sprintf("problem marshalling in progress pipelinerun to bytes: %s", err.Error()))
return false, nil
}
ta.Logf(fmt.Sprintf("in flight pipeline run: %s", pr.Name))
return false, nil
}
if !pr.GetStatusCondition().GetCondition(apis.ConditionSucceeded).IsTrue() {
prBytes, err := json.MarshalIndent(pr, "", " ")
if err != nil {
ta.Logf(fmt.Sprintf("problem marshalling failed pipelinerun to bytes: %s", err.Error()))
return false, nil
}
debugAndFailTest(ta, fmt.Sprintf("unsuccessful pipeline run: %s", string(prBytes)))
}
return true, nil
})
if err != nil {
debugAndFailTest(ta, fmt.Sprintf("failure occured when waiting for the pipeline run to complete: %v", err))
}
})
}
ta.t.Run("artifactbuilds and dependencybuilds generated", func(t *testing.T) {
err = wait.PollUntilContextTimeout(context.TODO(), ta.interval, ta.timeout, true, func(ctx context.Context) (done bool, err error) {
return bothABsAndDBsGenerated(ta)
})
if err != nil {
debugAndFailTest(ta, "timed out waiting for generation of artifactbuilds and dependencybuilds")
}
})
ta.t.Run("all artfactbuilds and dependencybuilds complete", func(t *testing.T) {
defer GenerateStatusReport(ta.ns, jvmClient, kubeClient, tektonClient)
err = wait.PollUntilContextTimeout(context.TODO(), ta.interval, time.Hour, true, func(ctx context.Context) (done bool, err error) {
abList, err := jvmClient.JvmbuildserviceV1alpha1().ArtifactBuilds(ta.ns).List(context.TODO(), metav1.ListOptions{})
if err != nil {
ta.Logf(fmt.Sprintf("error list artifactbuilds: %s", err.Error()))
return false, err
}
//we want to make sure there is more than one ab, and that they are all complete
abComplete := len(abList.Items) > 0
ta.Logf(fmt.Sprintf("number of artifactbuilds: %d", len(abList.Items)))
for _, ab := range abList.Items {
if ab.Status.State != v1alpha1.ArtifactBuildStateComplete {
ta.Logf(fmt.Sprintf("artifactbuild %s not complete", ab.Spec.GAV))
abComplete = false
break
}
}
dbList, err := jvmClient.JvmbuildserviceV1alpha1().DependencyBuilds(ta.ns).List(context.TODO(), metav1.ListOptions{})
if err != nil {
ta.Logf(fmt.Sprintf("error list dependencybuilds: %s", err.Error()))
return false, err
}
dbComplete := len(dbList.Items) > 0
ta.Logf(fmt.Sprintf("number of dependencybuilds: %d", len(dbList.Items)))
dbCompleteCount := 0
for _, db := range dbList.Items {
if db.Status.State == v1alpha1.DependencyBuildStateFailed {
ta.Logf(fmt.Sprintf("depedencybuild %s FAILED", db.Spec.ScmInfo.SCMURL))
return false, fmt.Errorf("depedencybuild %s for repo %s FAILED", db.Name, db.Spec.ScmInfo.SCMURL)
} else if db.Status.State != v1alpha1.DependencyBuildStateComplete {
if dbComplete {
//only print the first one
ta.Logf(fmt.Sprintf("depedencybuild %s not complete", db.Spec.ScmInfo.SCMURL))
}
dbComplete = false
} else if db.Status.State == v1alpha1.DependencyBuildStateComplete {
dbCompleteCount++
}
}
if abComplete && dbComplete {
return true, nil
}
ta.Logf(fmt.Sprintf("completed %d/%d DependencyBuilds", dbCompleteCount, len(dbList.Items)))
return false, nil
})
if err != nil {
debugAndFailTest(ta, "timed out waiting for some artifactbuilds and dependencybuilds to complete")
}
})
if len(set) > 0 {
//no futher checks required here
//we are just checking that the GAVs in question actually build
return
}
ta.t.Run("contaminated build is resolved", func(t *testing.T) {
//our sample repo has shaded-jdk11 which is contaminated by simple-jdk8
var contaminated string
var simpleJDK8 string
err = wait.PollUntilContextTimeout(context.TODO(), ta.interval, 3*ta.timeout, true, func(ctx context.Context) (done bool, err error) {
dbContaminated := false
shadedComplete := false
contaminantBuild := false
dbList, err := jvmClient.JvmbuildserviceV1alpha1().DependencyBuilds(ta.ns).List(context.TODO(), metav1.ListOptions{})
if err != nil {
ta.Logf(fmt.Sprintf("error list dependencybuilds: %s", err.Error()))
return false, err
}
ta.Logf(fmt.Sprintf("number of dependencybuilds: %d", len(dbList.Items)))
for _, db := range dbList.Items {
if db.Status.State == v1alpha1.DependencyBuildStateContaminated {
dbContaminated = true
contaminated = db.Name
break
} else if strings.Contains(db.Spec.ScmInfo.SCMURL, "shaded-jdk11") && db.Status.State == v1alpha1.DependencyBuildStateComplete {
//its also possible that the build has already resolved itself
contaminated = db.Name
shadedComplete = true
} else if strings.Contains(db.Spec.ScmInfo.SCMURL, "simple-jdk8") {
contaminantBuild = true
}
}
if dbContaminated || (shadedComplete && contaminantBuild) {
return true, nil
}
return false, nil
})
if err != nil {
debugAndFailTest(ta, "timed out waiting for contaminated build to appear")
}
ta.Logf(fmt.Sprintf("contaminated dependencybuild: %s", contaminated))
//make sure simple-jdk8 was requested as a result
err = wait.PollUntilContextTimeout(context.TODO(), ta.interval, 2*ta.timeout, true, func(ctx context.Context) (done bool, err error) {
abList, err := jvmClient.JvmbuildserviceV1alpha1().ArtifactBuilds(ta.ns).List(context.TODO(), metav1.ListOptions{})
if err != nil {
ta.Logf(fmt.Sprintf("error list artifactbuilds: %s", err.Error()))
return false, err
}
found := false
ta.Logf(fmt.Sprintf("number of artifactbuilds: %d", len(abList.Items)))
for _, ab := range abList.Items {
if strings.Contains(ab.Spec.GAV, "simple-jdk8") {
simpleJDK8 = ab.Name
found = true
break
}
}
return found, nil
})
if err != nil {
debugAndFailTest(ta, "timed out waiting for simple-jdk8 to appear as an artifactbuild")
}
//now make sure simple-jdk8 eventually completes
err = wait.PollUntilContextTimeout(context.TODO(), ta.interval, 2*ta.timeout, true, func(ctx context.Context) (done bool, err error) {
ab, err := jvmClient.JvmbuildserviceV1alpha1().ArtifactBuilds(ta.ns).Get(context.TODO(), simpleJDK8, metav1.GetOptions{})
if err != nil {
ta.Logf(fmt.Sprintf("error getting simple-jdk8 ArtifactBuild: %s", err.Error()))
return false, err
}
ta.Logf(fmt.Sprintf("simple-jdk8 State: %s", ab.Status.State))
return ab.Status.State == v1alpha1.ArtifactBuildStateComplete, nil
})
if err != nil {
debugAndFailTest(ta, "timed out waiting for simple-jdk8 to complete")
}
//now make sure shaded-jdk11 eventually completes
err = wait.PollUntilContextTimeout(context.TODO(), ta.interval, 2*ta.timeout, true, func(ctx context.Context) (done bool, err error) {
db, err := jvmClient.JvmbuildserviceV1alpha1().DependencyBuilds(ta.ns).Get(context.TODO(), contaminated, metav1.GetOptions{})
if err != nil {
ta.Logf(fmt.Sprintf("error getting shaded-jdk11 DependencyBuild: %s", err.Error()))
return false, err
}
ta.Logf(fmt.Sprintf("shaded-jdk11 State: %s", db.Status.State))
if db.Status.State == v1alpha1.DependencyBuildStateFailed {
msg := fmt.Sprintf("contaminated db %s failed, exitting wait", contaminated)
ta.Logf(msg)
return false, fmt.Errorf(msg)
}
return db.Status.State == v1alpha1.DependencyBuildStateComplete, err
})
if err != nil {
debugAndFailTest(ta, "timed out waiting for shaded-jdk11 to complete")
}
})
ta.t.Run("make sure second build access cached dependencies", func(t *testing.T) {
//first delete all existing PipelineRuns to free up resources
//mostly for minikube
runs, lerr := tektonClient.TektonV1().PipelineRuns(ta.ns).List(context.TODO(), metav1.ListOptions{})
if lerr != nil {
debugAndFailTest(ta, fmt.Sprintf("error listing runs %s", lerr.Error()))
}
for _, r := range runs.Items {
err := tektonClient.TektonV1().PipelineRuns(ta.ns).Delete(context.TODO(), r.Name, metav1.DeleteOptions{})
if err != nil {
debugAndFailTest(ta, fmt.Sprintf("error deleting runs %s", err.Error()))
}
}
ta.run = &tektonpipeline.PipelineRun{}
obj = streamFileYamlToTektonObj(runYamlPath, ta.run, ta)
ta.run, ok = obj.(*tektonpipeline.PipelineRun)
if !ok {
debugAndFailTest(ta, fmt.Sprintf("file %s did not produce a pipelinerun: %#v", runYamlPath, obj))
}
ta.run, err = tektonClient.TektonV1().PipelineRuns(ta.ns).Create(context.TODO(), ta.run, metav1.CreateOptions{})
if err != nil {
debugAndFailTest(ta, err.Error())
}
ctx := context.TODO()
watch, werr := tektonClient.TektonV1().PipelineRuns(ta.ns).Watch(ctx, metav1.ListOptions{})
if werr != nil {
debugAndFailTest(ta, fmt.Sprintf("error creating watch %s", werr.Error()))
}
defer watch.Stop()
exitForLoop := false
podClient := kubeClient.CoreV1().Pods(ta.ns)
for {
select {
// technically this is not needed, since we just created the context above; but if go testing changes
// such that it carries a context, we'll want to use that here
case <-ctx.Done():
ta.Logf("context done")
exitForLoop = true
break
case <-time.After(15 * time.Minute):
msg := "timed out waiting for second build to complete"
ta.Logf(msg)
// call stop here in case the defer is bypass by a call to t.Fatal
watch.Stop()
debugAndFailTest(ta, msg)
case event := <-watch.ResultChan():
if event.Object == nil {
continue
}
pr, ok := event.Object.(*tektonpipeline.PipelineRun)
if !ok {
continue
}
if pr.Name != ta.run.Name {
if pr.IsDone() {
ta.Logf(fmt.Sprintf("got event for pipelinerun %s in a terminal state", pr.Name))
continue
}
debugAndFailTest(ta, fmt.Sprintf("another non-completed pipeline run %s was generated when it should not", pr.Name))
}
ta.Logf(fmt.Sprintf("done processing event for pr %s", pr.Name))
if pr.IsDone() {
pods := prPods(ta, pr.Name)
if len(pods) == 0 {
debugAndFailTest(ta, fmt.Sprintf("pod for pipelinerun %s unexpectedly missing", pr.Name))
}
containers := []corev1.Container{}
containers = append(containers, pods[0].Spec.InitContainers...)
containers = append(containers, pods[0].Spec.Containers...)
for _, container := range containers {
if !strings.Contains(container.Name, "analyse-dependencies") {
continue
}
req := podClient.GetLogs(pods[0].Name, &corev1.PodLogOptions{Container: container.Name})
readCloser, err := req.Stream(context.TODO())
if err != nil {
ta.Logf(fmt.Sprintf("error getting pod logs for container %s: %s", container.Name, err.Error()))
continue
}
b, err := io.ReadAll(readCloser)
if err != nil {
ta.Logf(fmt.Sprintf("error reading pod stream %s", err.Error()))
continue
}
cLog := string(b)
if strings.Contains(cLog, "\"publisher\" : \"central\"") {
debugAndFailTest(ta, fmt.Sprintf("pipelinerun %s has container %s with dep analysis still pointing to central %s", pr.Name, container.Name, cLog))
}
if !strings.Contains(cLog, "\"publisher\" : \"rebuilt\"") {
debugAndFailTest(ta, fmt.Sprintf("pipelinerun %s has container %s with dep analysis that does not access rebuilt %s", pr.Name, container.Name, cLog))
}
if !strings.Contains(cLog, "\"java:scm-uri\" : \"https://github.com/stuartwdouglas/hacbs-test-simple-jdk8.git\"") {
debugAndFailTest(ta, fmt.Sprintf("pipelinerun %s has container %s with dep analysis did not include java:scm-uri %s", pr.Name, container.Name, cLog))
}
if !strings.Contains(cLog, "\"java:scm-commit\" : \"") {
debugAndFailTest(ta, fmt.Sprintf("pipelinerun %s has container %s with dep analysis did not include java:scm-commit %s", pr.Name, container.Name, cLog))
}
break
}
ta.Logf(fmt.Sprintf("pr %s is done and has correct analyse-dependencies output, exiting", pr.Name))
exitForLoop = true
break
}
}
if exitForLoop {
break
}
}
})
ta.t.Run("Correct JDK identified for JDK11 build", func(t *testing.T) {
//test that we don't attempt to use JDK8 on a JDK11+ project
err = wait.PollUntilContextTimeout(context.TODO(), ta.interval, 2*ta.timeout, true, func(ctx context.Context) (done bool, err error) {
dbList, err := jvmClient.JvmbuildserviceV1alpha1().DependencyBuilds(ta.ns).List(context.TODO(), metav1.ListOptions{})
if err != nil {
ta.Logf(fmt.Sprintf("error list dependencybuilds: %s", err.Error()))
return false, err
}
ta.Logf(fmt.Sprintf("number of dependencybuilds: %d", len(dbList.Items)))
for _, db := range dbList.Items {
if !strings.Contains(db.Spec.ScmInfo.SCMURL, "shaded-jdk11") ||
db.Status.State == "" ||
db.Status.State == v1alpha1.DependencyBuildStateNew ||
db.Status.State == v1alpha1.DependencyBuildStateAnalyzeBuild {
continue
}
jdk7 := false
jdk8 := false
jdk11 := false
jdk17 := false
for _, i := range db.Status.PotentialBuildRecipes {
jdk7 = jdk7 || i.JavaVersion == "7"
jdk8 = jdk8 || i.JavaVersion == "8"
jdk11 = jdk11 || i.JavaVersion == "11"
jdk17 = jdk17 || i.JavaVersion == "17"
}
for _, i := range db.Status.BuildAttempts {
jdk7 = jdk7 || i.Recipe.JavaVersion == "7"
jdk8 = jdk8 || i.Recipe.JavaVersion == "8"
jdk11 = jdk11 || i.Recipe.JavaVersion == "11"
jdk17 = jdk17 || i.Recipe.JavaVersion == "17"
}
if jdk7 {
return false, fmt.Errorf("build should not have been attempted with jdk7")
}
if jdk8 {
return false, fmt.Errorf("build should not have been attempted with jdk8")
}
if jdk17 {
return false, fmt.Errorf("build should not have been attempted with jdk17")
}
if !jdk11 {
return false, fmt.Errorf("build should have been attempted with jdk11")
}
return true, nil
}
return false, nil
})
if err != nil {
debugAndFailTest(ta, "timed out waiting for contaminated build to appear")
}
})
ta.t.Run("Logs and source included in image", func(t *testing.T) {
rebuiltList, err := jvmClient.JvmbuildserviceV1alpha1().RebuiltArtifacts(ta.ns).List(context.TODO(), metav1.ListOptions{})
if err != nil {
panic(err)
}
for _, artifact := range rebuiltList.Items {
sourceFound := false
logsFound := false
sbomFound := false
imageName := artifact.Spec.Image
if !strings.Contains(imageName, "quay.io") {
//skip this on the minikube tests
//we can't access the internal image registry
continue
}
println(imageName)
ref, err := name.ParseReference(imageName)
if err != nil {
panic(err)
}
rmt, err := remote.Get(ref)
if err != nil {
panic(err)
}
img, err := rmt.Image()
if err != nil {
panic(err)
}
export := path + "/foo.tar"
if err := crane.Save(img, "foo", export); err != nil {
panic(err)
}
f, err := os.Open(export) //#nosec G304
if err != nil {
panic(err)
}
defer func() {
if err := f.Close(); err != nil {
panic(err)
}
}()
tr := tar.NewReader(f)
for {
cur, err := tr.Next()
if err == io.EOF {
break
} else if err != nil {
panic(err)
}
if cur.Typeflag != tar.TypeReg {
continue
}
println(cur.Name)
if strings.HasSuffix(cur.Name, ".tar.gz") {
zip, err := gzip.NewReader(tr)
if err != nil {
panic(err)
}
innerTar := tar.NewReader(zip)
for {
cur, err := innerTar.Next()
if err == io.EOF {
break
} else if err != nil {
panic(err)
}
if cur.Typeflag != tar.TypeReg {
continue
}
println(cur.Name)
if cur.Name == "logs/maven.log" || cur.Name == "logs/gradle.log" {
logsFound = true
} else if cur.Name == "source/.git/HEAD" {
sourceFound = true
} else if cur.Name == "logs/build-sbom.json" {
sbomFound = true
bom := &cdx.BOM{}
decoder := cdx.NewBOMDecoder(innerTar, cdx.BOMFileFormatJSON)
if err = decoder.Decode(bom); err != nil {
panic(err)
}
if bom.Dependencies != nil && len(*bom.Dependencies) < 30 {
_ = cdx.NewBOMEncoder(os.Stdout, cdx.BOMFileFormatXML).
SetPretty(true).
Encode(bom)
panic("Not enough dependencies in build SBom")
}
}
}
}
}
if !sourceFound {
panic("Source was not found in image " + imageName)
}
if !logsFound {
panic("Logs were not found in image " + imageName)
}
if !sbomFound {
panic("Build SBOM were not found in image " + imageName)
}
}
})
}
func watchEvents(eventClient v1.EventInterface, ta *testArgs) {
ctx := context.TODO()
watch, err := eventClient.Watch(ctx, metav1.ListOptions{})
if err != nil {
panic(err)
}
for {
res := <-watch.ResultChan()
if res.Object == nil {
continue
}
event, ok := res.Object.(*v12.Event)
if !ok {
continue
}
if event.Type == corev1.EventTypeNormal {
continue
}
ta.Logf(fmt.Sprintf("non-normal event reason %s about obj %s:%s message %s", event.Reason, event.Regarding.Kind, event.Regarding.Name, event.Note))
}
}