Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for NewConfig matching AddFlags defaults #19247

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Comment on lines +1056 to +1066
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you going to resolve the TODO in this PR or in a followup PR?

Also I am a little confused why cfg and newConfg match even after you change some fields' value for newConfig? Why we do not see workflow failure? Did I miss anything?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this PR shows the differences between the defaults and AddFlags, I plan to fix it in next PR.

return a.String() == b.String()
})); diff != "" {
t.Errorf("Diff: %s", diff)
}
}
Loading