Skip to content

Commit

Permalink
Add custom recommender configuration to fake DPAI for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jennchenn committed Dec 9, 2024
1 parent 5b04388 commit 767066e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 41 deletions.
9 changes: 5 additions & 4 deletions pkg/clusteragent/autoscaling/workload/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ func TestLeaderCreateDeleteLocal(t *testing.T) {

// Check internal store content
expectedDPAInternal := model.FakePodAutoscalerInternal{
Namespace: "default",
Name: "dpa-0",
Generation: 1,
Spec: &dpaSpec,
Namespace: "default",
Name: "dpa-0",
Generation: 1,
Spec: &dpaSpec,
CustomRecommenderConfiguration: &model.RecommenderConfiguration{},
}
dpaInternal, found := f.store.Get("default/dpa-0")
assert.True(t, found)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,49 @@ import (

// FakePodAutoscalerInternal is a fake PodAutoscalerInternal object.
type FakePodAutoscalerInternal struct {
Namespace string
Name string
Generation int64
Spec *datadoghq.DatadogPodAutoscalerSpec
SettingsTimestamp time.Time
CreationTimestamp time.Time
ScalingValues ScalingValues
HorizontalLastActions []datadoghq.DatadogPodAutoscalerHorizontalAction
HorizontalLastLimitReason string
HorizontalLastActionError error
HorizontalEventsRetention time.Duration
VerticalLastAction *datadoghq.DatadogPodAutoscalerVerticalAction
VerticalLastActionError error
CurrentReplicas *int32
ScaledReplicas *int32
Error error
Deleted bool
TargetGVK schema.GroupVersionKind
Namespace string
Name string
Generation int64
Spec *datadoghq.DatadogPodAutoscalerSpec
SettingsTimestamp time.Time
CreationTimestamp time.Time
ScalingValues ScalingValues
HorizontalLastActions []datadoghq.DatadogPodAutoscalerHorizontalAction
HorizontalLastLimitReason string
HorizontalLastActionError error
HorizontalEventsRetention time.Duration
VerticalLastAction *datadoghq.DatadogPodAutoscalerVerticalAction
VerticalLastActionError error
CurrentReplicas *int32
ScaledReplicas *int32
Error error
Deleted bool
TargetGVK schema.GroupVersionKind
CustomRecommenderConfiguration *RecommenderConfiguration
}

// Build creates a PodAutoscalerInternal object from the FakePodAutoscalerInternal.
func (f FakePodAutoscalerInternal) Build() PodAutoscalerInternal {
return PodAutoscalerInternal{
namespace: f.Namespace,
name: f.Name,
generation: f.Generation,
spec: f.Spec,
settingsTimestamp: f.SettingsTimestamp,
creationTimestamp: f.CreationTimestamp,
scalingValues: f.ScalingValues,
horizontalLastActions: f.HorizontalLastActions,
horizontalLastLimitReason: f.HorizontalLastLimitReason,
horizontalLastActionError: f.HorizontalLastActionError,
horizontalEventsRetention: f.HorizontalEventsRetention,
verticalLastAction: f.VerticalLastAction,
verticalLastActionError: f.VerticalLastActionError,
currentReplicas: f.CurrentReplicas,
scaledReplicas: f.ScaledReplicas,
error: f.Error,
deleted: f.Deleted,
targetGVK: f.TargetGVK,
namespace: f.Namespace,
name: f.Name,
generation: f.Generation,
spec: f.Spec,
settingsTimestamp: f.SettingsTimestamp,
creationTimestamp: f.CreationTimestamp,
scalingValues: f.ScalingValues,
horizontalLastActions: f.HorizontalLastActions,
horizontalLastLimitReason: f.HorizontalLastLimitReason,
horizontalLastActionError: f.HorizontalLastActionError,
horizontalEventsRetention: f.HorizontalEventsRetention,
verticalLastAction: f.VerticalLastAction,
verticalLastActionError: f.VerticalLastActionError,
currentReplicas: f.CurrentReplicas,
scaledReplicas: f.ScaledReplicas,
error: f.Error,
deleted: f.Deleted,
targetGVK: f.TargetGVK,
customRecommenderConfiguration: f.CustomRecommenderConfiguration,
}
}

Expand Down Expand Up @@ -110,7 +112,7 @@ func ComparePodAutoscalers(expected any, actual any) string {
if fake, ok := x.(FakePodAutoscalerInternal); ok {
return fake.Build()
}
panic("filer failed - unexpected type")
panic("filter failed - unexpected type")
}),
),
cmp.FilterValues(
Expand Down

0 comments on commit 767066e

Please sign in to comment.