Skip to content

Commit

Permalink
Second phase of fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mvshao committed Aug 26, 2024
1 parent b348fda commit f431a3b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func sFnConfigureAuditLog(ctx context.Context, m *fsm, s *systemState) (stateFn,
m.log.Info("Configure Audit Log state")

wasAuditLogEnabled, err := m.AuditLogging.Enable(ctx, s.shoot)
if err != nil && !wasAuditLogEnabled {
if err != nil {
m.log.Error(err, "Failed to configure Audit Log")
s.instance.UpdateStatePending(
imv1.ConditionTypeRuntimeConfigured,
Expand Down
28 changes: 6 additions & 22 deletions internal/controller/runtime/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package runtime

import (
"context"
v12 "k8s.io/api/core/v1"
"path/filepath"
"testing"
"time"
Expand Down Expand Up @@ -183,6 +182,7 @@ func getBaseShootForTestingSequence() gardener_api.Shoot {
func fixShootsSequenceForProvisioning(shoot *gardener_api.Shoot) []*gardener_api.Shoot {
var missingShoot *gardener_api.Shoot
initialisedShoot := shoot.DeepCopy()
initialisedShoot.Spec.SeedName = ptr.To("test-seed")

dnsShoot := initialisedShoot.DeepCopy()

Expand All @@ -199,16 +199,7 @@ func fixShootsSequenceForProvisioning(shoot *gardener_api.Shoot) []*gardener_api
},
}

pendingShoot.Spec.SeedName = ptr.To("test-seed")

auditLogShoot := pendingShoot.DeepCopy()
auditLogShoot.Spec.Kubernetes.KubeAPIServer.AuditConfig = &gardener_api.AuditConfig{
AuditPolicy: &gardener_api.AuditPolicy{
ConfigMapRef: &v12.ObjectReference{Name: "policy-config-map"},
},
}

processingShoot := auditLogShoot.DeepCopy()
processingShoot := pendingShoot.DeepCopy()
processingShoot.Status.LastOperation.State = gardener_api.LastOperationStateProcessing

readyShoot := processingShoot.DeepCopy()
Expand All @@ -217,7 +208,7 @@ func fixShootsSequenceForProvisioning(shoot *gardener_api.Shoot) []*gardener_api

// processedShoot := processingShoot.DeepCopy() // will add specific data later

return []*gardener_api.Shoot{missingShoot, missingShoot, missingShoot, initialisedShoot, dnsShoot, auditLogShoot, auditLogShoot, processingShoot, readyShoot, readyShoot, readyShoot, readyShoot}
return []*gardener_api.Shoot{missingShoot, missingShoot, missingShoot, initialisedShoot, dnsShoot, pendingShoot, processingShoot, readyShoot, readyShoot, readyShoot, readyShoot, readyShoot}
}

func fixShootsSequenceForUpdate(shoot *gardener_api.Shoot) []*gardener_api.Shoot {
Expand All @@ -227,23 +218,16 @@ func fixShootsSequenceForUpdate(shoot *gardener_api.Shoot) []*gardener_api.Shoot
Domain: ptr.To("test.domain"),
}

pendingShoot.Spec.SeedName = ptr.To("test-seed")

pendingShoot.Status = gardener_api.ShootStatus{
LastOperation: &gardener_api.LastOperation{
Type: gardener_api.LastOperationTypeReconcile,
State: gardener_api.LastOperationStatePending,
},
}

auditLogShoot := pendingShoot.DeepCopy()
auditLogShoot.Spec.Kubernetes.KubeAPIServer.AuditConfig = &gardener_api.AuditConfig{
AuditPolicy: &gardener_api.AuditPolicy{
ConfigMapRef: &v12.ObjectReference{Name: "policy-config-map"},
},
}
pendingShoot.Spec.SeedName = ptr.To("test-seed")

processingShoot := auditLogShoot.DeepCopy()
processingShoot := pendingShoot.DeepCopy()

processingShoot.Status.LastOperation.State = gardener_api.LastOperationStateProcessing

Expand All @@ -253,7 +237,7 @@ func fixShootsSequenceForUpdate(shoot *gardener_api.Shoot) []*gardener_api.Shoot

// processedShoot := processingShoot.DeepCopy() // will add specific data later

return []*gardener_api.Shoot{pendingShoot, pendingShoot, auditLogShoot, processingShoot, readyShoot, readyShoot}
return []*gardener_api.Shoot{pendingShoot, processingShoot, readyShoot, readyShoot, readyShoot}
}

func fixShootsSequenceForDelete(shoot *gardener_api.Shoot) []*gardener_api.Shoot {
Expand Down
8 changes: 4 additions & 4 deletions internal/controller/runtime/test_client_obj_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ func getNextShoot(shoot []*gardener_api.Shoot, t *CustomTracker) (runtime.Object
return nil, fmt.Errorf("no more shoots in sequence")
}

//func getNextObject[T any](sequence []*T, t *CustomTracker) (*T, error) {
// if t.callCnt < len(sequence) {
// obj := sequence[t.callCnt]
// t.callCnt++
//func getNextObject[T any](sequence []*T, counter *int) (*T, error) {
// if *counter < len(sequence) {
// obj := sequence[*counter]
// *counter++
//
// if obj == nil {
// return nil, k8serrors.NewNotFound(schema.GroupResource{}, "")
Expand Down

0 comments on commit f431a3b

Please sign in to comment.