diff --git a/internal/gardener/shoot/extender/audit_log_test.go b/internal/gardener/shoot/extender/audit_log_test.go index 55036a43..7ecc6992 100644 --- a/internal/gardener/shoot/extender/audit_log_test.go +++ b/internal/gardener/shoot/extender/audit_log_test.go @@ -1,12 +1,14 @@ package extender import ( + "encoding/json" gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1" imv1 "github.com/kyma-project/infrastructure-manager/api/v1" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" v12 "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "path/filepath" "testing" ) @@ -14,30 +16,60 @@ func TestAuditLogExtender(t *testing.T) { t.Run("Should configure Audit Logs", func(t *testing.T) { // given auditLogPolicyName := "test-policy" - auditLogTenantConfigPath := "test-tenant" + seedName := "seedName" auditLogConfig := &gardener.AuditConfig{ AuditPolicy: &gardener.AuditPolicy{ ConfigMapRef: &v12.ObjectReference{Name: auditLogPolicyName}, }, } - runtimeShoot := imv1.Runtime{ + runtimeCR := imv1.Runtime{ Spec: imv1.RuntimeSpec{ Shoot: imv1.RuntimeShoot{ Name: "myshoot", + Provider: imv1.Provider{ + Type: "azure", + }, }, }, } + + shoot := gardener.Shoot{ + ObjectMeta: v1.ObjectMeta{ + Name: "test", + Namespace: "dev", + }, + Spec: gardener.ShootSpec{ + SeedName: &seedName, + Region: "westus2", + }, + } + + auditLogTenantConfigPath := filepath.Join("testdata", "config.json") extender := NewAuditLogExtender(auditLogPolicyName, auditLogTenantConfigPath) - shoot := fixAuditLogGardenerShoot("test", "dev", "seedName") // when - err := extender(runtimeShoot, &shoot) + err := extender(runtimeCR, &shoot) + + expected := ` + { + "providerConfig": { + "apiVersion": "service.auditlog.extensions.gardener.cloud/v1alpha1", + "kind": "AuditlogConfig", + "secretReferenceName": "auditlog-credentials", + "serviceURL": "https://auditlog.example.com:3000", + "tenantID": "a9be5aad-f855-4fd1-a8c8-e95683ec786b", + "type": "standard" + }, + "type": "shoot-auditlog-service" + }` // then require.NoError(t, err) require.NotNil(t, shoot.Spec.Kubernetes.KubeAPIServer) require.NotNil(t, shoot.Spec.Kubernetes.KubeAPIServer.AuditConfig) assert.Equal(t, auditLogConfig, shoot.Spec.Kubernetes.KubeAPIServer.AuditConfig) + actual, _ := json.Marshal(shoot.Spec.Extensions[0]) + assert.JSONEq(t, expected, string(actual)) }) t.Run("Should not configure Audit Logs when shoot seed name is empty", func(t *testing.T) { // given diff --git a/internal/gardener/shoot/extender/testdata/config.json b/internal/gardener/shoot/extender/testdata/config.json new file mode 100644 index 00000000..6971f3a4 --- /dev/null +++ b/internal/gardener/shoot/extender/testdata/config.json @@ -0,0 +1,14 @@ +{ + "azure": { + "eu-central-1": { + "tenantID": "79c64792-9c1e-4c1b-9941-ef7560dd3eae", + "serviceURL": "https://auditlog.example.com:3001", + "secretName": "auditlog-secret2" + }, + "westus2": { + "tenantID": "a9be5aad-f855-4fd1-a8c8-e95683ec786b", + "serviceURL": "https://auditlog.example.com:3000", + "secretName": "auditlog-secret" + } + } +}