8000 Merge branch 'ap-multi-log-dst' of https://github.com/nginxinc/kubern… · nginx/kubernetes-ingress@8765318 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8765318

Browse files
committed
Merge branch 'ap-multi-log-dst' of https://github.com/nginxinc/kubernetes-ingress into ap-multi-log-dst
2 parents e590e86 + 2a6633e commit 8765318

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

internal/k8s/appprotect/app_protect_resources_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package appprotect
22

33
import (
4+
"reflect"
45
"strings"
56
"testing"
67

@@ -434,3 +435,44 @@ func TestGenNsName(t *testing.T) {
434435
t.Errorf("GetNsName() returned %q but expected %q", result, expected)
435436
}
436437
}
438+
439+
func TestParseResourceReferenceAnnotationList(t *testing.T) {
440+
namespace := "test_ns"
441+
tests := []struct {
442+
annotation string
443+
expected []string
444+
msg string
445+
}{
446+
{
447+
annotation: "test",
448+
expected: []string{namespace + "/test"},
449+
msg: "single resource no namespace",
450+
},
451+
{
452+
annotation: "different_ns/test",
453+
expected: []string{"different_ns/test"},
454+
msg: "single resource with namespace",
455+
},
456+
{
457+
annotation: "test,test1",
458+
expected: []string{namespace + "/test", namespace + "/test1"},
459+
msg: "multiple resource no namespace",
460+
},
461+
{
462+
annotation: "different_ns/test,different_ns/test1",
463+
expected: []string{"different_ns/test", "different_ns/test1"},
464+
msg: "multiple resource with namespaces",
465+
},
466+
{
467+
annotation: "different_ns/test,test1",
468+
expected: []string{"different_ns/test", namespace + "/test1"},
469+
msg: "multiple resource with mixed namespaces",
470+
},
471+
}
472+
for _, test := range tests {
473+
result := ParseResourceReferenceAnnotationList(namespace, test.annotation)
474+
if !reflect.DeepEqual(result, test.expected) {
475+
t.Errorf("Error in test case %s: got: %v, expected: %v", test.msg, result, test.expected)
476+
}
477+
}
478+
}

internal/k8s/reference_checkers_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,48 @@ func TestAppProtectResourceIsReferencedByIngresses(t *testing.T) {
939939
expected: false,
940940
msg: "wrong namespace with implicit namespace",
941941
},
942+
{
943+
ing: &networking.Ingress{
944+
ObjectMeta: v1.ObjectMeta{
945+
Namespace: "default",
946+
Annotations: map[string]string{
947+
"test-annotation": "some-namespace/test-resource,some-namespace/different-resource",
948+
},
949+
},
950+
},
951+
resourceNamespace: "some-namespace",
952+
resourceName: "test-resource",
953+
expected: true,
954+
msg: "resource is referenced with namespace within multiple resources",
955+
},
956+
{
957+
ing: &networking.Ingress{
958+
ObjectMeta: v1.ObjectMeta{
959+
Namespace: "default",
960+
Annotations: map[string]string{
961+
"test-annotation": "test-resource,some-namespace/different-resource",
962+
},
963+
},
964+
},
965+
resourceNamespace: "default",
966+
resourceName: "test-resource",
967+
expected: true,
968+
msg: "resource is referenced with implicit namespace within multiple resources",
969+
},
970+
{
971+
ing: &networking.Ingress{
972+
ObjectMeta: v1.ObjectMeta{
973+
Namespace: "default",
974+
Annotations: map[string]string{
975+
"test-annotation": "test-resource,some-namespace/different-resource",
976+
},
977+
},
978+
},
979+
resourceNamespace: "some-namespace",
980+
resourceName: "test-resource",
981+
expected: false,
982+
msg: "wrong namespace within multiple resources",
983+
},
942984
}
943985

944986
for _, test := range tests {

0 commit comments

Comments
 (0)
0