/
assertions.go
51 lines (45 loc) · 1.92 KB
/
assertions.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
package testwithory
import (
"context"
"log"
"github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
apigatewayv1beta1 "github.com/kyma-project/api-gateway/apis/gateway/v1beta1"
eventingv1alpha2 "github.com/kyma-project/kyma/components/eventing-controller/api/v1alpha2"
)
// getSubscriptionAssert fetches a subscription using the lookupKey and allows making assertions on it.
func getSubscriptionAssert(ctx context.Context, g *gomega.GomegaWithT,
subscription *eventingv1alpha2.Subscription) gomega.AsyncAssertion {
return g.Eventually(func() *eventingv1alpha2.Subscription {
lookupKey := types.NamespacedName{
Namespace: subscription.Namespace,
Name: subscription.Name,
}
if err := emTestEnsemble.k8sClient.Get(ctx, lookupKey, subscription); err != nil {
log.Printf("fetch subscription %s failed: %v", lookupKey.String(), err)
return &eventingv1alpha2.Subscription{}
}
return subscription
}, bigTimeOut, bigPollingInterval)
}
// getAPIRuleForASvcAssert fetches an apiRule for a given service and allows making assertions on it.
func getAPIRuleForASvcAssert(ctx context.Context, g *gomega.GomegaWithT, svc *corev1.Service) gomega.AsyncAssertion {
return g.Eventually(func() apigatewayv1beta1.APIRule {
apiRules, err := getAPIRulesList(ctx, svc)
g.Expect(err).Should(gomega.BeNil())
return filterAPIRulesForASvc(apiRules, svc)
}, smallTimeOut, smallPollingInterval)
}
// getAPIRuleAssert fetches an apiRule and allows making assertions on it.
func getAPIRuleAssert(ctx context.Context, g *gomega.GomegaWithT,
apiRule *apigatewayv1beta1.APIRule) gomega.AsyncAssertion {
return g.Eventually(func() apigatewayv1beta1.APIRule {
fetchedAPIRule, err := getAPIRule(ctx, apiRule)
if err != nil {
log.Printf("fetch APIRule %s/%s failed: %v", apiRule.Namespace, apiRule.Name, err)
return apigatewayv1beta1.APIRule{}
}
return *fetchedAPIRule
}, twoMinTimeOut, bigPollingInterval)
}