-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathstructure_ingress_spec_test.go
More file actions
81 lines (72 loc) · 1.62 KB
/
structure_ingress_spec_test.go
File metadata and controls
81 lines (72 loc) · 1.62 KB
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
77
78
79
80
81
// Copyright IBM Corp. 2017, 2025
// SPDX-License-Identifier: MPL-2.0
package kubernetes
import (
"reflect"
"testing"
"k8s.io/api/extensions/v1beta1"
"k8s.io/apimachinery/pkg/util/intstr"
)
// Test Flatteners
func TestFlattenIngressRule(t *testing.T) {
r := v1beta1.HTTPIngressRuleValue{
Paths: []v1beta1.HTTPIngressPath{
{
Path: "/foo/bar",
Backend: v1beta1.IngressBackend{
ServiceName: "foo",
ServicePort: intstr.FromInt(1234),
},
},
},
}
in := []v1beta1.IngressRule{
{
Host: "the-app-name.staging.live.domain-replaced.tld",
IngressRuleValue: v1beta1.IngressRuleValue{
HTTP: (*v1beta1.HTTPIngressRuleValue)(nil),
},
},
{
Host: "",
IngressRuleValue: v1beta1.IngressRuleValue{
HTTP: (*v1beta1.HTTPIngressRuleValue)(&r),
},
},
}
out := []interface{}{
map[string]interface{}{
"host": "the-app-name.staging.live.domain-replaced.tld",
"http": []interface{}{},
},
map[string]interface{}{
"host": "",
"http": []interface{}{
map[string]interface{}{
"path": []interface{}{
map[string]interface{}{
"path": "/foo/bar",
"backend": []interface{}{
map[string]interface{}{
"service_name": "foo",
"service_port": "1234",
},
},
},
},
},
},
},
}
flatRules := flattenIngressRule(in)
if len(flatRules) < len(out) {
t.Error("Failed to flatten ingress rules")
}
for i, v := range flatRules {
control := v.(map[string]interface{})
sample := out[i]
if !reflect.DeepEqual(control, sample) {
t.Errorf("Unexpected result:\n\tWant:%s\n\tGot:%s\n", control, sample)
}
}
}