Applying API default tests to rest of configuration modules
Signed-off-by: Jason Costello <jason@jsnc.tl>
This commit is contained in:
parent
046027a556
commit
b363fd9b3f
@ -38,14 +38,14 @@ func TestCAInjectorConfigurationDefaults(t *testing.T) {
|
||||
if err := os.WriteFile(TestFileLocation, defaultData, 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log("cainjector api defaults updated")
|
||||
t.Log("cainjector config api defaults updated")
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
config *v1alpha1.CAInjectorConfiguration
|
||||
}{
|
||||
{
|
||||
"cainjection",
|
||||
"v1alpha1",
|
||||
&v1alpha1.CAInjectorConfiguration{},
|
||||
},
|
||||
}
|
||||
|
||||
56
internal/apis/config/controller/v1alpha1/defaults_test.go
Normal file
56
internal/apis/config/controller/v1alpha1/defaults_test.go
Normal file
@ -0,0 +1,56 @@
|
||||
package v1alpha1
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/cert-manager/cert-manager/pkg/apis/config/controller/v1alpha1"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const TestFileLocation = "testdata/defaults.json"
|
||||
|
||||
func TestControllerConfigurationDefaults(t *testing.T) {
|
||||
if os.Getenv("UPDATE_DEFAULTS") == "true" {
|
||||
config := &v1alpha1.ControllerConfiguration{}
|
||||
SetObjectDefaults_ControllerConfiguration(config)
|
||||
defaultData, err := json.Marshal(config)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := os.WriteFile(TestFileLocation, defaultData, 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log("controller api defaults updated")
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
config *v1alpha1.ControllerConfiguration
|
||||
}{
|
||||
{
|
||||
"v1alpha1",
|
||||
&v1alpha1.ControllerConfiguration{},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
SetObjectDefaults_ControllerConfiguration(tt.config)
|
||||
|
||||
var expected *v1alpha1.ControllerConfiguration
|
||||
expectedData, err := os.ReadFile(TestFileLocation)
|
||||
err = json.Unmarshal(expectedData, &expected)
|
||||
|
||||
// need re-initialised post-unmarshal to avoid nil slice
|
||||
SetDefaults_ACMEHTTP01Config(&expected.ACMEHTTP01Config)
|
||||
SetDefaults_ACMEDNS01Config(&expected.ACMEDNS01Config)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("testfile not found")
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(tt.config, expected) {
|
||||
prettyExpected, _ := json.MarshalIndent(expected, "", "\t")
|
||||
prettyGot, _ := json.MarshalIndent(tt.config, "", "\t")
|
||||
t.Errorf("expected defaults\n %v \n but got \n %v", string(prettyExpected), string(prettyGot))
|
||||
}
|
||||
}
|
||||
}
|
||||
1
internal/apis/config/controller/v1alpha1/testdata/defaults.json
vendored
Normal file
1
internal/apis/config/controller/v1alpha1/testdata/defaults.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"kubernetesAPIQPS":20,"kubernetesAPIBurst":50,"clusterResourceNamespace":"kube-system","leaderElectionConfig":{"enabled":true,"namespace":"kube-system","leaseDuration":60000000000,"renewDeadline":40000000000,"retryPeriod":15000000000,"healthzTimeout":20000000000},"controllers":["*"],"issuerAmbientCredentials":false,"clusterIssuerAmbientCredentials":true,"enableCertificateOwnerRef":false,"copiedAnnotationPrefixes":["*","-kubectl.kubernetes.io/","-fluxcd.io/","-argocd.argoproj.io/"],"numberOfConcurrentWorkers":5,"maxConcurrentChallenges":60,"metricsListenAddress":"0.0.0.0:9402","metricsTLSConfig":{"filesystem":{},"dynamic":{"LeafDuration":0}},"healthzListenAddress":"0.0.0.0:9403","enablePprof":false,"pprofAddress":"localhost:6060","logging":{"format":"text","flushFrequency":"5s","verbosity":0,"options":{"json":{"infoBufferSize":"0"}}},"ingressShimConfig":{"defaultIssuerKind":"Issuer","defaultIssuerGroup":"cert-manager.io","defaultAutoCertificateAnnotations":["kubernetes.io/tls-acme"]},"acmeHTTP01Config":{"solverImage":"quay.io/jetstack/cert-manager-acmesolver:canary","solverResourceRequestCPU":"10m","solverResourceRequestMemory":"64Mi","solverResourceLimitsCPU":"100m","solverResourceLimitsMemory":"64Mi","solverRunAsNonRoot":true},"acmeDNS01Config":{"recursiveNameserversOnly":false,"checkRetryPeriod":10000000000}}
|
||||
54
internal/apis/config/webhook/v1alpha1/defaults_test.go
Normal file
54
internal/apis/config/webhook/v1alpha1/defaults_test.go
Normal file
@ -0,0 +1,54 @@
|
||||
package v1alpha1
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/cert-manager/cert-manager/pkg/apis/config/webhook/v1alpha1"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const TestFileLocation = "testdata/defaults.json"
|
||||
|
||||
func TestWebhookConfigurationDefaults(t *testing.T) {
|
||||
if os.Getenv("UPDATE_DEFAULTS") == "true" {
|
||||
config := &v1alpha1.WebhookConfiguration{}
|
||||
SetObjectDefaults_WebhookConfiguration(config)
|
||||
defaultData, err := json.Marshal(config)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := os.WriteFile(TestFileLocation, defaultData, 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log("webhook config api defaults updated")
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
config *v1alpha1.WebhookConfiguration
|
||||
}{
|
||||
{
|
||||
"v1alpha1",
|
||||
&v1alpha1.WebhookConfiguration{},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
SetObjectDefaults_WebhookConfiguration(tt.config)
|
||||
|
||||
var expected *v1alpha1.WebhookConfiguration
|
||||
expectedData, err := os.ReadFile(TestFileLocation)
|
||||
err = json.Unmarshal(expectedData, &expected)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("testfile not found")
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(tt.config, expected) {
|
||||
prettyExpected, _ := json.MarshalIndent(expected, "", "\t")
|
||||
prettyGot, _ := json.MarshalIndent(tt.config, "", "\t")
|
||||
t.Errorf("expected defaults\n %v \n but got \n %v", string(prettyExpected), string(prettyGot))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
1
internal/apis/config/webhook/v1alpha1/testdata/defaults.json
vendored
Normal file
1
internal/apis/config/webhook/v1alpha1/testdata/defaults.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"securePort":6443,"healthzPort":6080,"tlsConfig":{"filesystem":{},"dynamic":{"LeafDuration":0}},"enablePprof":false,"pprofAddress":"localhost:6060","logging":{"format":"text","flushFrequency":"5s","verbosity":0,"options":{"json":{"infoBufferSize":"0"}}}}
|
||||
@ -87,9 +87,11 @@ unit-test-controller: | $(NEEDS_GOTESTSUM)
|
||||
unit-test-webhook: | $(NEEDS_GOTESTSUM)
|
||||
cd cmd/webhook && $(GOTESTSUM) ./...
|
||||
|
||||
.PHONY: update-apidefaults-cainjector
|
||||
update-apidefaults-cainjector: | $(NEEDS_GOTESTSUM)
|
||||
cd internal/apis/config/cainjector/v1alpha1/ && UPDATE_DEFAULTS=true $(GOTESTSUM) . && echo "cainjector api defaults updated"
|
||||
.PHONY: update-config-api-defaults
|
||||
update-config-api-defaults: | $(NEEDS_GOTESTSUM)
|
||||
cd internal/apis/config/cainjector/v1alpha1/ && UPDATE_DEFAULTS=true $(GOTESTSUM) . && echo "cainjector config api defaults updated"
|
||||
cd internal/apis/config/controller/v1alpha1/ && UPDATE_DEFAULTS=true $(GOTESTSUM) . && echo "controller config api defaults updated"
|
||||
cd internal/apis/config/webhook/v1alpha1/ && UPDATE_DEFAULTS=true $(GOTESTSUM) . && echo "webhook config api defaults updated"
|
||||
|
||||
.PHONY: setup-integration-tests
|
||||
setup-integration-tests: templated-crds
|
||||
|
||||
Loading…
Reference in New Issue
Block a user