Skip to content

Commit

Permalink
Fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
nak3 committed Mar 28, 2022
1 parent fca1a70 commit dc4de02
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/reconciler/autoscaling/config/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/google/go-cmp/cmp"
logtesting "knative.dev/pkg/logging/testing"

network "knative.dev/networking/pkg"
. "knative.dev/pkg/configmap/testing"
autoscalerconfig "knative.dev/serving/pkg/autoscaler/config"
"knative.dev/serving/pkg/deployment"
Expand All @@ -34,8 +35,10 @@ func TestStoreLoadWithContext(t *testing.T) {

autoscalerConfig := ConfigMapFromTestFile(t, autoscalerconfig.ConfigName)
depConfig := ConfigMapFromTestFile(t, deployment.ConfigName, deployment.DeprecatedQueueSidecarImageKey)
netConfig := ConfigMapFromTestFile(t, network.ConfigName)
store.OnConfigChanged(autoscalerConfig)
store.OnConfigChanged(depConfig)
store.OnConfigChanged(netConfig)
config := FromContext(store.ToContext(context.Background()))

wantAS, _ := autoscalerconfig.NewConfigFromConfigMap(autoscalerConfig)
Expand All @@ -46,6 +49,10 @@ func TestStoreLoadWithContext(t *testing.T) {
if !cmp.Equal(wantD, config.Deployment) {
t.Error("Deployment ConfigMap mismatch (-want, +got):", cmp.Diff(wantD, config.Deployment))
}
wantNet, _ := network.NewConfigFromConfigMap(netConfig)
if !cmp.Equal(wantNet, config.Network) {
t.Error("Network ConfigMap mismatch (-want, +got):", cmp.Diff(wantNet, config.Network))
}
}

func TestStoreImmutableConfig(t *testing.T) {
Expand All @@ -54,16 +61,22 @@ func TestStoreImmutableConfig(t *testing.T) {
store.OnConfigChanged(ConfigMapFromTestFile(t, autoscalerconfig.ConfigName))
store.OnConfigChanged(ConfigMapFromTestFile(t, deployment.ConfigName,
deployment.DeprecatedQueueSidecarImageKey))
store.OnConfigChanged(ConfigMapFromTestFile(t, network.ConfigName))

config := store.Load()
config.Autoscaler.MaxScaleUpRate = 100.0
config.Deployment.ProgressDeadline = 3 * time.Minute
config.Network.ActivatorCA = "activator-ca"
config.Network.ActivatorSAN = "activator-san"
newConfig := store.Load()

if newConfig.Autoscaler.MaxScaleUpRate == 100.0 {
t.Error("Autoscaler config is not immuable")
}
if newConfig.Deployment.ProgressDeadline == 3*time.Minute {
t.Error("Autoscaler config is not immuable")
t.Error("Deployment config is not immuable")
}
if newConfig.Network.ActivatorCA == "activator-ca" || newConfig.Network.ActivatorSAN == "activator-san" {
t.Error("Network config is not immuable")
}
}

0 comments on commit dc4de02

Please sign in to comment.