Repository: etcd-io/etcd
File: server/etcdmain/config_test.go (Go)

Code before:
	if cfg.ec.ClusterState != wcfg.ec.ClusterState {
		t.Errorf("clusterState = %v, want %v", cfg.ec.ClusterState, wcfg.ec.ClusterState)
	}
	if cfg.ec.InitialCluster != wcfg.ec.InitialCluster {
		t.Errorf("initialCluster = %v, want %v", cfg.ec.InitialCluster, wcfg.ec.InitialCluster)
	}
	if cfg.ec.InitialClusterToken != wcfg.ec.InitialClusterToken {
		t.Errorf("initialClusterToken = %v, want %v", cfg.ec.InitialClusterToken, wcfg.ec.InitialClusterToken)
	}
	if !reflect.DeepEqual(cfg.ec.AdvertisePeerUrls, wcfg.ec.AdvertisePeerUrls) {
		t.Errorf("initial-advertise-peer-urls = %v, want %v", cfg.ec.AdvertisePeerUrls, wcfg.ec.AdvertisePeerUrls)
	}
	if !reflect.DeepEqual(cfg.ec.AdvertiseClientUrls, wcfg.ec.AdvertiseClientUrls) {
		t.Errorf("advertise-client-urls = %v, want %v", cfg.ec.AdvertiseClientUrls, wcfg.ec.AdvertiseClientUrls)
	}
}

func TestConfigFileDeprecatedOptions(t *testing.T) {
	type configStruct struct {
		SnapshotCount                           uint64        `json:"snapshot-count,omitempty"`
		MaxSnapFiles                            uint          `json:"max-snapshots,omitempty"`
		V2Deprecation                           string        `json:"v2-deprecation,omitempty"`
		ExperimentalCompactHashCheckEnabled     bool          `json:"experimental-compact-hash-check-enabled,omitempty"`
		ExperimentalCompactHashCheckTime        time.Duration `json:"experimental-compact-hash-check-time,omitempty"`
		ExperimentalWarningUnaryRequestDuration time.Duration `json:"experimental-warning-unary-request-duration,omitempty"`
	}

	testCases := []struct {
		name           string
		configFileYAML configStruct
		expectedFlags  map[string]struct{}
	}{
		{
			name:           "no deprecated options",
			configFileYAML: configStruct{},
			expectedFlags:  map[string]struct{}{},
		},
		{
			name: "deprecated experimental options",
			configFileYAML: configStruct{
				ExperimentalCompactHashCheckEnabled:     true,
				ExperimentalCompactHashCheckTime:        2 * time.Minute,
				ExperimentalWarningUnaryRequestDuration: time.Second,
			},
			expectedFlags: map[string]struct{}{
				"experimental-compact-hash-check-enabled": {},
				"experimental-compact-hash-check-time":    {},
			},
		},
		{
			name: "deprecated snapshot options",

Review comment (suggestion):
I think that you can reuse [embed.Config](https://github.com/etcd-io/etcd/blob/9db8dcb44b9ad7d0cf94438169cef7a778e2eb15/server/embed/config.go#L162) directly instead of defining another struct.

Code after:
	if cfg.ec.ClusterState != wcfg.ec.ClusterState {
		t.Errorf("clusterState = %v, want %v", cfg.ec.ClusterState, wcfg.ec.ClusterState)
	}
	if cfg.ec.InitialCluster != wcfg.ec.InitialCluster {
		t.Errorf("initialCluster = %v, want %v", cfg.ec.InitialCluster, wcfg.ec.InitialCluster)
	}
	if cfg.ec.InitialClusterToken != wcfg.ec.InitialClusterToken {
		t.Errorf("initialClusterToken = %v, want %v", cfg.ec.InitialClusterToken, wcfg.ec.InitialClusterToken)
	}
	if !reflect.DeepEqual(cfg.ec.AdvertisePeerUrls, wcfg.ec.AdvertisePeerUrls) {
		t.Errorf("initial-advertise-peer-urls = %v, want %v", cfg.ec.AdvertisePeerUrls, wcfg.ec.AdvertisePeerUrls)
	}
	if !reflect.DeepEqual(cfg.ec.AdvertiseClientUrls, wcfg.ec.AdvertiseClientUrls) {
		t.Errorf("advertise-client-urls = %v, want %v", cfg.ec.AdvertiseClientUrls, wcfg.ec.AdvertiseClientUrls)
	}
}

func TestConfigFileDeprecatedOptions(t *testing.T) {
	// Define a minimal config struct with only the fields we need
	type configFileYAML struct {
		SnapshotCount                           uint64        `json:"snapshot-count,omitempty"`
		MaxSnapFiles                            uint          `json:"max-snapshots,omitempty"`
		ExperimentalCompactHashCheckEnabled     bool          `json:"experimental-compact-hash-check-enabled,omitempty"`
		ExperimentalCompactHashCheckTime        time.Duration `json:"experimental-compact-hash-check-time,omitempty"`
		ExperimentalWarningUnaryRequestDuration time.Duration `json:"experimental-warning-unary-request-duration,omitempty"`
	}

	testCases := []struct {
		name           string
		configFileYAML configFileYAML
		expectedFlags  map[string]struct{}
	}{
		{
			name:           "no deprecated options",
			configFileYAML: configFileYAML{},
			expectedFlags:  map[string]struct{}{},
		},
		{
			name: "deprecated experimental options",
			configFileYAML: configFileYAML{
				ExperimentalCompactHashCheckEnabled:     true,
				ExperimentalCompactHashCheckTime:        2 * time.Minute,
				ExperimentalWarningUnaryRequestDuration: time.Second,
			},
			expectedFlags: map[string]struct{}{
				"experimental-compact-hash-check-enabled": {},
				"experimental-compact-hash-check-time":    {},
			},
		},
		{
			name: "deprecated snapshot options",