Skip to content

Commit

Permalink
Create unit test for case where extender should not update Auditlog e…
Browse files Browse the repository at this point in the history
…xtension when provided input auditLogData is empty
  • Loading branch information
koala7659 committed Dec 11, 2024
1 parent 5ff8fb1 commit 754e3e4
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions pkg/gardener/shoot/extender/extensions/extensions_extender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,44 +86,58 @@ func TestNewExtensionsExtenderForPatch(t *testing.T) {

for _, testCase := range []struct {
name string
auditLogData auditlogs.AuditLogData
inputAuditLogData auditlogs.AuditLogData
expectedAuditLogData auditlogs.AuditLogData
disableNetworkFilter bool
previousExtensions []gardener.Extension
}{
{
name: "Existing extensions should not change order during patching if nothing has changed",
previousExtensions: fixAllExtensionsOnTheShoot(),
auditLogData: oldAuditLogData,
inputAuditLogData: oldAuditLogData,
expectedAuditLogData: oldAuditLogData,
disableNetworkFilter: true,
},
{
name: "Should update Audit Log extension without changing order and data of other extensions",
previousExtensions: fixAllExtensionsOnTheShoot(),
auditLogData: newAuditLogData,
inputAuditLogData: newAuditLogData,
expectedAuditLogData: newAuditLogData,
disableNetworkFilter: true,
},
{
name: "Should update Network filter extension without changing order and data of other extensions",
previousExtensions: fixAllExtensionsOnTheShoot(),
auditLogData: oldAuditLogData,
inputAuditLogData: oldAuditLogData,
expectedAuditLogData: oldAuditLogData,
disableNetworkFilter: false,
},
{
name: "Should add Network filter extension at the end without changing order and data of other extensions",
previousExtensions: fixExtensionsOnTheShootWithoutNetworkFilter(),
auditLogData: oldAuditLogData,
inputAuditLogData: oldAuditLogData,
expectedAuditLogData: oldAuditLogData,
disableNetworkFilter: true,
},
{
name: "Should add Auditlog extension at the end without changing order and data of other extensions",
previousExtensions: fixExtensionsOnTheShootWithoutAuditLogs(),
auditLogData: oldAuditLogData,
inputAuditLogData: oldAuditLogData,
expectedAuditLogData: oldAuditLogData,
disableNetworkFilter: true,
},
{
name: "Should add Auditlog and Network filter extensions at the end without changing order and data of other extensions",
previousExtensions: fixExtensionsOnTheShootWithoutAuditLogsAndNetworkFilter(),
auditLogData: oldAuditLogData,
inputAuditLogData: oldAuditLogData,
expectedAuditLogData: oldAuditLogData,
disableNetworkFilter: true,
},
{
name: "Should not update Auditlog extension when input auditLogData is empty",
previousExtensions: fixAllExtensionsOnTheShoot(),
inputAuditLogData: auditlogs.AuditLogData{},
expectedAuditLogData: oldAuditLogData,
disableNetworkFilter: true,
},
} {
Expand All @@ -136,7 +150,7 @@ func TestNewExtensionsExtenderForPatch(t *testing.T) {
},
}

extender := NewExtensionsExtenderForPatch(testCase.auditLogData, testCase.previousExtensions)
extender := NewExtensionsExtenderForPatch(testCase.inputAuditLogData, testCase.previousExtensions)
orderMap := getExpectedExtensionsOrderMap(testCase.previousExtensions)

err := extender(runtime, shoot)
Expand All @@ -162,7 +176,7 @@ func TestNewExtensionsExtenderForPatch(t *testing.T) {
verifyOIDCExtension(t, ext)

case AuditlogExtensionType:
verifyAuditLogExtension(t, ext, testCase.auditLogData)
verifyAuditLogExtension(t, ext, testCase.expectedAuditLogData)
}
}
})
Expand All @@ -174,7 +188,7 @@ func fixAllExtensionsOnTheShoot() []gardener.Extension {
{
Type: AuditlogExtensionType,
ProviderConfig: &runtime.RawExtension{
Raw: []byte(`{"type":"standard","tenantID":"test-auditlog-tenant","serviceURL":"test-auditlog-service-url","secretReferenceName":"test-auditlog-secret"}`),
Raw: []byte(`{"apiVersion":"service.auditlog.extensions.gardener.cloud/v1alpha1","kind":"AuditlogConfig","type":"standard","tenantID":"test-auditlog-tenant","serviceURL":"test-auditlog-service-url","secretReferenceName":"auditlog-credentials"}`),
},
},
{
Expand Down Expand Up @@ -230,7 +244,7 @@ func fixExtensionsOnTheShootWithoutNetworkFilter() []gardener.Extension {
{
Type: AuditlogExtensionType,
ProviderConfig: &runtime.RawExtension{
Raw: []byte(`{"type":"standard","tenantID":"test-auditlog-tenant","serviceURL":"test-auditlog-service-url","secretReferenceName":"test-auditlog-secret"}`),
Raw: []byte(`{"apiVersion":"service.auditlog.extensions.gardener.cloud/v1alpha1","kind":"AuditlogConfig","type":"standard","tenantID":"test-auditlog-tenant","serviceURL":"test-auditlog-service-url","secretReferenceName":"auditlog-credentials"}`),
},
},
{
Expand Down

0 comments on commit 754e3e4

Please sign in to comment.