-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathingress_test.go
76 lines (68 loc) · 2.02 KB
/
ingress_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
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
package kube
import (
"context"
"testing"
"github.com/stretchr/testify/require"
networkv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestClientIngress(t *testing.T) {
mockingressname := "mockingress"
mockingressnamespace := "default"
mockingtype := networkv1.PathType("Prefix")
mocking := &networkv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: mockingressname,
},
Spec: networkv1.IngressSpec{
Rules: []networkv1.IngressRule{{
IngressRuleValue: networkv1.IngressRuleValue{
HTTP: &networkv1.HTTPIngressRuleValue{Paths: []networkv1.HTTPIngressPath{{
Path: "/mock",
PathType: &mockingtype,
Backend: networkv1.IngressBackend{
Service: &networkv1.IngressServiceBackend{
Name: "mocksvc",
Port: networkv1.ServiceBackendPort{
Number: 8001,
},
},
},
}}},
},
}},
},
}
// clean
if _, err := mockcli.GetIngress(context.TODO(), mockingressnamespace, mockingressname); err == nil {
err := mockcli.DeleteIngress(context.TODO(), mockingressnamespace, mockingressname)
require.NoError(t, err)
}
t.Run("create:ingress", func(t *testing.T) {
ing := mocking
ing.Namespace = mockingressnamespace
_, err := mockcli.CreateIngress(context.TODO(), ing)
require.NoError(t, err)
})
t.Run("create:ingress:error", func(t *testing.T) {
ing := mocking
ing.Namespace = ""
_, err := mockcli.CreateIngress(context.TODO(), ing)
require.EqualError(t, err, ErrorMissingNamespace.Error())
})
t.Run("get:ingress", func(t *testing.T) {
_, err := mockcli.GetIngress(context.TODO(), mockingressnamespace, mockingressname)
require.NoError(t, err)
})
t.Run("get:ingress:list", func(t *testing.T) {
list, err := mockcli.GetIngresses(context.TODO(), mockingressnamespace)
require.NoError(t, err)
if len(list.Items) == 0 {
t.Fatal(err)
}
})
t.Run("delete:ingress", func(t *testing.T) {
err := mockcli.DeleteIngress(context.TODO(), mockingressnamespace, mockingressname)
require.NoError(t, err)
})
}