Skip to content

Commit

Permalink
address comments, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
skonto committed Jan 14, 2025
1 parent f3c3ee1 commit 610bdc8
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 145 deletions.
35 changes: 21 additions & 14 deletions pkg/apis/serving/v1/configuration_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ package v1

import (
"context"
"fmt"
"testing"

"github.com/google/go-cmp/cmp"
"go.uber.org/zap"
authv1 "k8s.io/api/authentication/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -33,6 +35,8 @@ import (
cconfig "knative.dev/serving/pkg/reconciler/configuration/config"
)

const defaultTimeoutSeconds = 400

func TestConfigurationDefaulting(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -187,29 +191,22 @@ func TestConfigurationDefaulting(t *testing.T) {
ReadinessProbe: defaultProbe,
}},
},
TimeoutSeconds: ptr.Int64(423),
TimeoutSeconds: ptr.Int64(defaultTimeoutSeconds),
ContainerConcurrency: ptr.Int64(config.DefaultContainerConcurrency),
},
},
},
},
ctx: func() context.Context {
logger := logtesting.TestLogger(t)
s := cconfig.NewStore(logger)
s.OnConfigChanged(&corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: config.FeaturesConfigName}})
s.OnConfigChanged(&corev1.ConfigMap{
ctx: defaultConfigurationContextWithStore(logtesting.TestLogger(t), corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: config.FeaturesConfigName}},
corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: config.DefaultsConfigName,
},
Data: map[string]string{
"revision-timeout-seconds": "423",
"revision-response-start-timeout-seconds": "423",
"revision-idle-timeout-seconds": "423",
},
})

return s.ToContext(context.Background())
}(),
"revision-timeout-seconds": fmt.Sprintf("%d", defaultTimeoutSeconds),
"revision-response-start-timeout-seconds": fmt.Sprintf("%d", defaultTimeoutSeconds),
"revision-idle-timeout-seconds": fmt.Sprintf("%d", defaultTimeoutSeconds),
}})(context.Background()),
}}

for _, test := range tests {
Expand Down Expand Up @@ -382,3 +379,13 @@ func TestConfigurationUserInfo(t *testing.T) {
})
}
}

func defaultConfigurationContextWithStore(logger *zap.SugaredLogger, cms ...corev1.ConfigMap) func(ctx context.Context) context.Context {
return func(ctx context.Context) context.Context {
s := cconfig.NewStore(logger)
for _, cm := range cms {
s.OnConfigChanged(&cm)
}
return s.ToContext(ctx)
}
}
Loading

0 comments on commit 610bdc8

Please sign in to comment.