|
1 | 1 | package appprotect
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "io" |
| 5 | + "log/slog" |
4 | 6 | "testing"
|
5 | 7 | "time"
|
6 | 8 |
|
| 9 | + nic_glog "github.com/nginxinc/kubernetes-ingress/internal/logger/glog" |
| 10 | + "github.com/nginxinc/kubernetes-ingress/internal/logger/levels" |
| 11 | + |
7 | 12 | "github.com/google/go-cmp/cmp"
|
8 | 13 | "github.com/google/go-cmp/cmp/cmpopts"
|
9 | 14 | "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
@@ -178,8 +183,8 @@ func TestCreateAppProtectPolicyEx(t *testing.T) {
|
178 | 183 |
|
179 | 184 | for _, test := range tests {
|
180 | 185 | test.expectedPolicyEx.Obj = test.policy
|
181 |
| - |
182 |
| - policyEx, err := createAppProtectPolicyEx(test.policy) |
| 186 | + l := slog.New(nic_glog.New(io.Discard, &nic_glog.Options{Level: levels.LevelInfo})) |
| 187 | + policyEx, err := createAppProtectPolicyEx(test.policy, l) |
183 | 188 | if (err != nil) != test.wantErr {
|
184 | 189 | t.Errorf("createAppProtectPolicyEx() returned %v, for the case of %s", err, test.msg)
|
185 | 190 | }
|
@@ -511,7 +516,8 @@ func TestAddOrUpdatePolicy(t *testing.T) {
|
511 | 516 | },
|
512 | 517 | },
|
513 | 518 | }
|
514 |
| - apc := newConfigurationImpl() |
| 519 | + l := slog.New(nic_glog.New(io.Discard, &nic_glog.Options{Level: levels.LevelInfo})) |
| 520 | + apc := newConfigurationImpl(l) |
515 | 521 | apc.UserSigs["testing/TestUsersig"] = &UserSigEx{Tag: "test", RevTime: parseTime("2019-01-01T18:32:02Z"), IsValid: true}
|
516 | 522 | tests := []struct {
|
517 | 523 | policy *unstructured.Unstructured
|
@@ -643,7 +649,8 @@ func TestAddOrUpdateLogConf(t *testing.T) {
|
643 | 649 | },
|
644 | 650 | },
|
645 | 651 | }
|
646 |
| - apc := NewConfiguration() |
| 652 | + l := slog.New(nic_glog.New(io.Discard, &nic_glog.Options{Level: levels.LevelInfo})) |
| 653 | + apc := NewConfiguration(l) |
647 | 654 | tests := []struct {
|
648 | 655 | logconf *unstructured.Unstructured
|
649 | 656 | expectedChanges []Change
|
@@ -792,7 +799,8 @@ func TestAddOrUpdateUserSig(t *testing.T) {
|
792 | 799 | },
|
793 | 800 | }
|
794 | 801 |
|
795 |
| - appProtectConfiguration := newConfigurationImpl() |
| 802 | + l := slog.New(nic_glog.New(io.Discard, &nic_glog.Options{Level: levels.LevelInfo})) |
| 803 | + appProtectConfiguration := newConfigurationImpl(l) |
796 | 804 | appProtectConfiguration.UserSigs["testing/test1"] = &UserSigEx{
|
797 | 805 | Obj: testUserSig1,
|
798 | 806 | Tag: "test1",
|
@@ -906,7 +914,8 @@ func TestAddOrUpdateUserSig(t *testing.T) {
|
906 | 914 |
|
907 | 915 | func TestDeletePolicy(t *testing.T) {
|
908 | 916 | t.Parallel()
|
909 |
| - appProtectConfiguration := newConfigurationImpl() |
| 917 | + l := slog.New(nic_glog.New(io.Discard, &nic_glog.Options{Level: levels.LevelInfo})) |
| 918 | + appProtectConfiguration := newConfigurationImpl(l) |
910 | 919 | appProtectConfiguration.Policies["testing/test"] = &PolicyEx{}
|
911 | 920 | tests := []struct {
|
912 | 921 | key string
|
@@ -945,7 +954,8 @@ func TestDeletePolicy(t *testing.T) {
|
945 | 954 |
|
946 | 955 | func TestDeleteLogConf(t *testing.T) {
|
947 | 956 | t.Parallel()
|
948 |
| - appProtectConfiguration := newConfigurationImpl() |
| 957 | + l := slog.New(nic_glog.New(io.Discard, &nic_glog.Options{Level: levels.LevelInfo})) |
| 958 | + appProtectConfiguration := newConfigurationImpl(l) |
949 | 959 | appProtectConfiguration.LogConfs["testing/test"] = &LogConfEx{}
|
950 | 960 | tests := []struct {
|
951 | 961 | key string
|
@@ -1018,7 +1028,8 @@ func TestDeleteUserSig(t *testing.T) {
|
1018 | 1028 | },
|
1019 | 1029 | },
|
1020 | 1030 | }
|
1021 |
| - appProtectConfiguration := newConfigurationImpl() |
| 1031 | + l := slog.New(nic_glog.New(io.Discard, &nic_glog.Options{Level: levels.LevelInfo})) |
| 1032 | + appProtectConfiguration := newConfigurationImpl(l) |
1022 | 1033 | appProtectConfiguration.UserSigs["testing/test1"] = &UserSigEx{
|
1023 | 1034 | IsValid: true,
|
1024 | 1035 | Obj: testUserSig1,
|
@@ -1165,7 +1176,8 @@ func TestGetAppProtectResource(t *testing.T) {
|
1165 | 1176 | msg: "Invalid kind, Negative",
|
1166 | 1177 | },
|
1167 | 1178 | }
|
1168 |
| - appProtectConfiguration := newConfigurationImpl() |
| 1179 | + l := slog.New(nic_glog.New(io.Discard, &nic_glog.Options{Level: levels.LevelInfo})) |
| 1180 | + appProtectConfiguration := newConfigurationImpl(l) |
1169 | 1181 | appProtectConfiguration.Policies["testing/test1"] = &PolicyEx{IsValid: true, Obj: &unstructured.Unstructured{}}
|
1170 | 1182 | appProtectConfiguration.Policies["testing/test2"] = &PolicyEx{IsValid: false, Obj: &unstructured.Unstructured{}, ErrorMsg: "validation failed"}
|
1171 | 1183 | appProtectConfiguration.LogConfs["testing/test1"] = &LogConfEx{IsValid: true, Obj: &unstructured.Unstructured{}}
|
|
0 commit comments