-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathstructure_ingress_spec_v1_test.go
More file actions
91 lines (83 loc) · 1.89 KB
/
structure_ingress_spec_v1_test.go
File metadata and controls
91 lines (83 loc) · 1.89 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
82
83
84
85
86
87
88
89
90
91
// Copyright IBM Corp. 2017, 2025
// SPDX-License-Identifier: MPL-2.0
package kubernetes
import (
"reflect"
"testing"
networking "k8s.io/api/networking/v1"
)
// Test Flatteners
func TestFlattenIngressV1Rule(t *testing.T) {
r := networking.HTTPIngressRuleValue{
Paths: []networking.HTTPIngressPath{
{
Path: "/foo/bar",
Backend: networking.IngressBackend{
Service: &networking.IngressServiceBackend{
Name: "foo",
Port: networking.ServiceBackendPort{
Number: 1234,
},
},
},
},
},
}
in := []networking.IngressRule{
{
Host: "the-app-name.staging.live.domain-replaced.tld",
IngressRuleValue: networking.IngressRuleValue{
HTTP: (*networking.HTTPIngressRuleValue)(nil),
},
},
{
Host: "",
IngressRuleValue: networking.IngressRuleValue{
HTTP: (*networking.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": []interface{}{
map[string]interface{}{
"name": "foo",
"port": []interface{}{
map[string]interface{}{
"number": int32(1234),
},
},
},
},
},
},
},
},
},
},
},
}
flatRules := flattenIngressV1Rule(in)
if len(flatRules) < len(out) {
t.Error("Failed to flatten ingress rules")
}
for i, v := range flatRules {
expected := v.(map[string]interface{})
actual := out[i]
if !reflect.DeepEqual(expected, actual) {
t.Errorf("Unexpected result:\n\texpected:%s\n\tactual:%s\n", expected, actual)
}
}
}