Repository: etcd-io/etcd
File: server/etcdserver/server_test.go (Go)

Code before:
		ID:     1,
		Path:   membership.MemberAttributesStorePath(1),
		Val:    `{"Name":"abc","ClientURLs":["http://127.0.0.1:2379"]}`,
	}
	data, err := proto.Marshal(&req)
	if err != nil {
		t.Fatal(err)
	}
	srv.applyEntryNormal(&raftpb.Entry{
		Data: data,
	}, membership.ApplyV2storeOnly)
	w := membership.Attributes{Name: "abc", ClientURLs: []string{"http://127.0.0.1:2379"}}
	if g := cl.Member(1).Attributes; !reflect.DeepEqual(g, w) {
		t.Errorf("attributes = %v, want %v", g, w)
	}
}

// TestV2SetClusterVersion validates support of hybrid v3.5 cluster which still uses v2 request.
// TODO: Remove in v3.7
func TestV2SetClusterVersion(t *testing.T) {
	be, _ := betesting.NewDefaultTmpBackend(t)
	defer betesting.Close(t, be)
	cl := newTestClusterWithBackend(t, []*membership.Member{}, be)
	cl.SetVersion(semver.New("3.4.0"), api.UpdateCapability, membership.ApplyBoth)
	cfg := config.ServerConfig{
		ServerFeatureGate: features.NewDefaultServerFeatureGate("TxnModeWriteWithSharedBuffer", nil),
	}

	srv := &EtcdServer{
		lgMu:         new(sync.RWMutex),
		lg:           zaptest.NewLogger(t),
		v2store:      mockstore.NewRecorder(),
		cluster:      cl,
		consistIndex: cindex.NewConsistentIndex(be),
		w:            wait.New(),
		Cfg:          cfg,
	}
	as, err := v3alarm.NewAlarmStore(srv.lg, schema.NewAlarmBackend(srv.lg, be))
	if err != nil {
		t.Fatal(err)
	}
	srv.alarmStore = as
	srv.uberApply = srv.NewUberApplier()

	req := pb.Request{
		Method: "PUT",
		ID:     1,
		Path:   membership.StoreClusterVersionKey(),
		Val:    "3.5.0",
	}
	data, err := proto.Marshal(&req)

Review comment (suggestion):
```suggestion
		ServerFeatureGate: features.NewDefaultServerFeatureGate("test", nil),
```
since the test has nothing to do with TxnModeWriteWithSharedBuffer

Code after:
		ID:     1,
		Path:   membership.MemberAttributesStorePath(1),
		Val:    `{"Name":"abc","ClientURLs":["http://127.0.0.1:2379"]}`,
	}
	data, err := proto.Marshal(&req)
	if err != nil {
		t.Fatal(err)
	}
	srv.applyEntryNormal(&raftpb.Entry{
		Data: data,
	}, membership.ApplyV2storeOnly)
	w := membership.Attributes{Name: "abc", ClientURLs: []string{"http://127.0.0.1:2379"}}
	if g := cl.Member(1).Attributes; !reflect.DeepEqual(g, w) {
		t.Errorf("attributes = %v, want %v", g, w)
	}
}

// TestV2SetClusterVersion validates support of hybrid v3.5 cluster which still uses v2 request.
// TODO: Remove in v3.7
func TestV2SetClusterVersion(t *testing.T) {
	be, _ := betesting.NewDefaultTmpBackend(t)
	defer betesting.Close(t, be)
	cl := newTestClusterWithBackend(t, []*membership.Member{}, be)
	cl.SetVersion(semver.New("3.4.0"), api.UpdateCapability, membership.ApplyBoth)
	cfg := config.ServerConfig{
		ServerFeatureGate: features.NewDefaultServerFeatureGate("test", nil),
	}

	srv := &EtcdServer{
		lgMu:         new(sync.RWMutex),
		lg:           zaptest.NewLogger(t),
		v2store:      mockstore.NewRecorder(),
		cluster:      cl,
		consistIndex: cindex.NewConsistentIndex(be),
		w:            wait.New(),
		Cfg:          cfg,
	}
	as, err := v3alarm.NewAlarmStore(srv.lg, schema.NewAlarmBackend(srv.lg, be))
	if err != nil {
		t.Fatal(err)
	}
	srv.alarmStore = as
	srv.uberApply = srv.NewUberApplier()

	req := pb.Request{
		Method: "PUT",
		ID:     1,
		Path:   membership.StoreClusterVersionKey(),
		Val:    "3.5.0",
	}
	data, err := proto.Marshal(&req)