Skip to content

Commit

Permalink
Merge pull request #19247 from serathius/match-defaults
Browse files Browse the repository at this point in the history
Add tests for NewConfig matching AddFlags defaults
  • Loading branch information
serathius authored Jan 22, 2025
2 parents 4e77d69 + 6ddc4a2 commit 8c1547b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions server/embed/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package embed
import (
"crypto/tls"
"errors"
"flag"
"fmt"
"net"
"net/url"
Expand All @@ -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"
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 8c1547b

Please sign in to comment.