forked from kyma-project/kyma
/
function_reconcile_health_test.go
46 lines (34 loc) · 1.27 KB
/
function_reconcile_health_test.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
package serverless
import (
"context"
"testing"
"github.com/onsi/gomega"
"go.uber.org/zap"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
)
func TestFunctionReconciler_Reconcile_HealthCheck(t *testing.T) {
g := gomega.NewGomegaWithT(t)
t.Run("should receive health check and notify to health channel", func(t *testing.T) {
healthCh := make(chan bool)
reconciler := NewFunctionReconciler(nil, zap.NewNop().Sugar(), FunctionConfig{}, nil, nil, nil, healthCh)
healthRequest := ctrl.Request{NamespacedName: types.NamespacedName{
Name: HealthEvent,
}}
go func() {
result, err := reconciler.Reconcile(context.Background(), healthRequest)
g.Expect(result).To(gomega.Equal(ctrl.Result{}))
g.Expect(err).To(gomega.BeNil())
}()
g.Expect(<-healthCh).To(gomega.BeTrue())
})
t.Run("should receive health check and return nil after timeout", func(t *testing.T) {
reconciler := NewFunctionReconciler(nil, zap.NewNop().Sugar(), FunctionConfig{}, nil, nil, nil, make(chan bool))
healthRequest := ctrl.Request{NamespacedName: types.NamespacedName{
Name: HealthEvent,
}}
result, err := reconciler.Reconcile(context.Background(), healthRequest)
g.Expect(result).To(gomega.Equal(ctrl.Result{}))
g.Expect(err).To(gomega.BeNil())
})
}