-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.go
48 lines (37 loc) · 1.15 KB
/
setup.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
package assesments
import (
"context"
"errors"
"fmt"
"testing"
"k8s.io/apimachinery/pkg/runtime"
cosi "sigs.k8s.io/container-object-storage-interface-api/apis/objectstorage/v1alpha1"
"sigs.k8s.io/e2e-framework/pkg/envconf"
"sigs.k8s.io/e2e-framework/pkg/types"
)
type (
TypeCtxKey string
)
var ErrKeyNotFound = errors.New("required resource not found")
const (
BucketTypeCtxKey = TypeCtxKey("cosi.Bucket")
BucketClaimTypeCtxKey = TypeCtxKey("cosi.BucketClaim")
BucketAccessTypeCtxKey = TypeCtxKey("cosi.BucketAccess")
)
func RegisterResourcesForTest(objects ...runtime.Object) types.StepFunc {
return func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
for _, obj := range objects {
switch typedObj := obj.(type) {
case *cosi.Bucket:
ctx = context.WithValue(ctx, BucketTypeCtxKey, typedObj)
case *cosi.BucketClaim:
ctx = context.WithValue(ctx, BucketClaimTypeCtxKey, typedObj)
case *cosi.BucketAccess:
ctx = context.WithValue(ctx, BucketAccessTypeCtxKey, typedObj)
default:
panic(fmt.Sprintf("unsupported type: %T (Kind: %s)", typedObj, obj.GetObjectKind()))
}
}
return ctx
}
}