Skip to content

Commit 8bda8be

Browse files
committed
Add ability to indicate a monitor test was skipped
1 parent 14fe567 commit 8bda8be

File tree

3 files changed

+97
-12
lines changed

3 files changed

+97
-12
lines changed

pkg/monitortestframework/errors.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package monitortestframework
2+
3+
import "fmt"
4+
5+
// NotSupportedError represents an error when a monitor test is unsupported for the given environment.
6+
type NotSupportedError struct {
7+
Reason string
8+
}
9+
10+
func (e *NotSupportedError) Error() string {
11+
return fmt.Sprintf("not supported: %s", e.Reason)
12+
}

pkg/monitortestframework/impl.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package monitortestframework
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"os"
78
"strings"
@@ -94,6 +95,17 @@ func (r *monitorTestRegistry) StartCollection(ctx context.Context, adminRESTConf
9495
end := time.Now()
9596
duration := end.Sub(start)
9697
if err != nil {
98+
var nsErr *NotSupportedError
99+
if errors.As(err, &nsErr) {
100+
junitCh <- &junitapi.JUnitTestCase{
101+
Name: testName,
102+
Duration: duration.Seconds(),
103+
SkipMessage: &junitapi.SkipMessage{
104+
Message: nsErr.Reason,
105+
},
106+
}
107+
return
108+
}
97109
errCh <- err
98110
junitCh <- &junitapi.JUnitTestCase{
99111
Name: testName,
@@ -149,6 +161,19 @@ func (r *monitorTestRegistry) CollectData(ctx context.Context, storageDir string
149161
end := time.Now()
150162
duration := end.Sub(start)
151163
if err != nil {
164+
var nsErr *NotSupportedError
165+
if errors.As(err, &nsErr) {
166+
junitCh <- []*junitapi.JUnitTestCase{
167+
{
168+
Name: testName,
169+
Duration: duration.Seconds(),
170+
SkipMessage: &junitapi.SkipMessage{
171+
Message: nsErr.Reason,
172+
},
173+
},
174+
}
175+
return
176+
}
152177
junitCh <- []*junitapi.JUnitTestCase{
153178
{
154179
Name: testName,
@@ -206,6 +231,18 @@ func (r *monitorTestRegistry) ConstructComputedIntervals(ctx context.Context, st
206231
end := time.Now()
207232
duration := end.Sub(start)
208233
if err != nil {
234+
var nsErr *NotSupportedError
235+
if errors.As(err, &nsErr) {
236+
junits = append(junits, &junitapi.JUnitTestCase{
237+
Name: testName,
238+
Duration: duration.Seconds(),
239+
SkipMessage: &junitapi.SkipMessage{
240+
Message: nsErr.Reason,
241+
},
242+
})
243+
continue
244+
}
245+
209246
errs = append(errs, err)
210247
junits = append(junits, &junitapi.JUnitTestCase{
211248
Name: testName,
@@ -240,6 +277,18 @@ func (r *monitorTestRegistry) EvaluateTestsFromConstructedIntervals(ctx context.
240277
end := time.Now()
241278
duration := end.Sub(start)
242279
if err != nil {
280+
var nsErr *NotSupportedError
281+
if errors.As(err, &nsErr) {
282+
junits = append(junits, &junitapi.JUnitTestCase{
283+
Name: testName,
284+
Duration: duration.Seconds(),
285+
SkipMessage: &junitapi.SkipMessage{
286+
Message: nsErr.Reason,
287+
},
288+
})
289+
continue
290+
}
291+
243292
errs = append(errs, err)
244293
junits = append(junits, &junitapi.JUnitTestCase{
245294
Name: testName,
@@ -282,6 +331,18 @@ func (r *monitorTestRegistry) WriteContentToStorage(ctx context.Context, storage
282331
end := time.Now()
283332
duration := end.Sub(start)
284333
if err != nil {
334+
var nsErr *NotSupportedError
335+
if errors.As(err, &nsErr) {
336+
junits = append(junits, &junitapi.JUnitTestCase{
337+
Name: testName,
338+
Duration: duration.Seconds(),
339+
SkipMessage: &junitapi.SkipMessage{
340+
Message: nsErr.Reason,
341+
},
342+
})
343+
continue
344+
}
345+
285346
errs = append(errs, err)
286347
junits = append(junits, &junitapi.JUnitTestCase{
287348
Name: testName,
@@ -315,6 +376,18 @@ func (r *monitorTestRegistry) Cleanup(ctx context.Context) ([]*junitapi.JUnitTes
315376
end := time.Now()
316377
duration := end.Sub(start)
317378
if err != nil {
379+
var nsErr *NotSupportedError
380+
if errors.As(err, &nsErr) {
381+
junits = append(junits, &junitapi.JUnitTestCase{
382+
Name: testName,
383+
Duration: duration.Seconds(),
384+
SkipMessage: &junitapi.SkipMessage{
385+
Message: nsErr.Reason,
386+
},
387+
})
388+
continue
389+
}
390+
318391
errs = append(errs, err)
319392
junits = append(junits, &junitapi.JUnitTestCase{
320393
Name: testName,

pkg/monitortests/imageregistry/disruptionimageregistry/monitortest.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type availability struct {
3434
imageRegistryRoute *routev1.Route
3535

3636
disruptionChecker *disruptionlibrary.Availability
37-
notSupportedReason string
37+
notSupportedReason *monitortestframework.NotSupportedError
3838
suppressJunit bool
3939
}
4040

@@ -61,8 +61,8 @@ func (w *availability) StartCollection(ctx context.Context, adminRESTConfig *res
6161

6262
_, err = w.kubeClient.CoreV1().Namespaces().Get(context.Background(), namespace, metav1.GetOptions{})
6363
if apierrors.IsNotFound(err) {
64-
w.notSupportedReason = "namespace openshift-image-registry not present"
65-
return nil
64+
w.notSupportedReason = &monitortestframework.NotSupportedError{Reason: "namespace openshift-image-registry not present"}
65+
return w.notSupportedReason
6666
}
6767
if err != nil {
6868
return err
@@ -73,8 +73,8 @@ func (w *availability) StartCollection(ctx context.Context, adminRESTConfig *res
7373
return err
7474
}
7575
if deployment.Spec.Replicas != nil && *deployment.Spec.Replicas == 1 {
76-
w.notSupportedReason = "image-registry only has a single replica"
77-
return nil
76+
w.notSupportedReason = &monitortestframework.NotSupportedError{Reason: "image-registry only has a single replica"}
77+
return w.notSupportedReason
7878
}
7979

8080
w.routeClient, err = routeclient.NewForConfig(adminRESTConfig)
@@ -115,8 +115,8 @@ func (w *availability) StartCollection(ctx context.Context, adminRESTConfig *res
115115
}
116116

117117
func (w *availability) CollectData(ctx context.Context, storageDir string, beginning, end time.Time) (monitorapi.Intervals, []*junitapi.JUnitTestCase, error) {
118-
if len(w.notSupportedReason) > 0 {
119-
return nil, nil, nil
118+
if w.notSupportedReason != nil {
119+
return nil, nil, w.notSupportedReason
120120
}
121121
// we failed and indicated it during setup.
122122
if w.disruptionChecker == nil {
@@ -131,8 +131,8 @@ func (*availability) ConstructComputedIntervals(ctx context.Context, startingInt
131131
}
132132

133133
func (w *availability) EvaluateTestsFromConstructedIntervals(ctx context.Context, finalIntervals monitorapi.Intervals) ([]*junitapi.JUnitTestCase, error) {
134-
if len(w.notSupportedReason) > 0 {
135-
return nil, nil
134+
if w.notSupportedReason != nil {
135+
return nil, w.notSupportedReason
136136
}
137137
if w.suppressJunit {
138138
return nil, nil
@@ -145,8 +145,8 @@ func (w *availability) EvaluateTestsFromConstructedIntervals(ctx context.Context
145145
return w.disruptionChecker.EvaluateTestsFromConstructedIntervals(ctx, finalIntervals)
146146
}
147147

148-
func (*availability) WriteContentToStorage(ctx context.Context, storageDir, timeSuffix string, finalIntervals monitorapi.Intervals, finalResourceState monitorapi.ResourcesMap) error {
149-
return nil
148+
func (w *availability) WriteContentToStorage(ctx context.Context, storageDir, timeSuffix string, finalIntervals monitorapi.Intervals, finalResourceState monitorapi.ResourcesMap) error {
149+
return w.notSupportedReason
150150
}
151151

152152
func (w *availability) Cleanup(ctx context.Context) error {
@@ -157,5 +157,5 @@ func (w *availability) Cleanup(ctx context.Context) error {
157157
}
158158
}
159159

160-
return nil
160+
return w.notSupportedReason
161161
}

0 commit comments

Comments
 (0)