From 6ddc4a2861ebe3b630e3230006f593a0ef29b8a9 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Tue, 21 Jan 2025 17:39:47 +0100 Subject: [PATCH] Add tests for NewConfig matching AddFlags defaults Signed-off-by: Marek Siarkowicz --- server/embed/config_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/server/embed/config_test.go b/server/embed/config_test.go index 9a24e5eb903..757769b8722 100644 --- a/server/embed/config_test.go +++ b/server/embed/config_test.go @@ -17,6 +17,7 @@ package embed import ( "crypto/tls" "errors" + "flag" "fmt" "net" "net/url" @@ -25,11 +26,14 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "sigs.k8s.io/yaml" "go.etcd.io/etcd/client/pkg/v3/srv" + "go.etcd.io/etcd/client/pkg/v3/tlsutil" "go.etcd.io/etcd/client/pkg/v3/transport" "go.etcd.io/etcd/client/pkg/v3/types" "go.etcd.io/etcd/pkg/v3/featuregate" @@ -1041,3 +1045,27 @@ func TestSetFeatureGatesFromExperimentalFlags(t *testing.T) { }) } } + +func TestMatchNewConfigAddFlags(t *testing.T) { + cfg := NewConfig() + fs := flag.NewFlagSet("etcd", flag.ContinueOnError) + cfg.AddFlags(fs) + require.NoError(t, fs.Parse(nil)) + + newConfig := NewConfig() + // TODO: Remove the following assigments when both match. + newConfig.SelfSignedCertValidity = 1 + newConfig.TlsMinVersion = string(tlsutil.TLSVersion12) + newConfig.DiscoveryCfg.Secure.InsecureTransport = true + newConfig.AutoCompactionRetention = "0" + newConfig.ExperimentalDistributedTracingAddress = "localhost:4317" + newConfig.ExperimentalDistributedTracingServiceName = "etcd" + newConfig.LogFormat = "json" + newConfig.ExperimentalTxnModeWriteWithSharedBuffer = true + // TODO: Reduce number of unexported fields set in config + if diff := cmp.Diff(newConfig, cfg, cmpopts.IgnoreUnexported(transport.TLSInfo{}, Config{}), cmp.Comparer(func(a, b featuregate.FeatureGate) bool { + return a.String() == b.String() + })); diff != "" { + t.Errorf("Diff: %s", diff) + } +}