clientv3/integration: fix cluster tests
Fixes TestMemberAddForLearner and TestMemberPromoteForLearner.
@@ -202,6 +202,16 @@ func TestMemberAddForLearner(t *testing.T) {
if !resp.Member.IsLearner {
t.Errorf("Added a member as learner, got resp.Member.IsLearner = %v", resp.Member.IsLearner)
}
+
+ numberOfLearners := 0
+ for _, m := range resp.Members {
+ if m.IsLearner {
+ numberOfLearners++
+ }
+ }
+ if numberOfLearners != 1 {
+ t.Errorf("Added 1 learner node to cluster, got %d", numberOfLearners)
+ }
}
func TestMemberPromoteForLearner(t *testing.T) {
@@ -214,35 +224,38 @@ func TestMemberPromoteForLearner(t *testing.T) {
capi := clus.RandClient()
urls := []string{"http://127.0.0.1:1234"}
- isLearner := true
- resp, err := capi.MemberAddAsLearner(context.Background(), urls)
+ memberAddResp, err := capi.MemberAddAsLearner(context.Background(), urls)
if err != nil {
t.Fatalf("failed to add member %v", err)
}
- if !resp.Member.IsLearner {
- t.Errorf("Added a member as learner, got resp.Member.IsLearner = %v", resp.Member.IsLearner)
+ if !memberAddResp.Member.IsLearner {
+ t.Fatalf("Added a member as learner, got resp.Member.IsLearner = %v", memberAddResp.Member.IsLearner)
}
+ learnerID := memberAddResp.Member.ID
- learners, err := clus.GetLearnerMembers()
- if err != nil {
- t.Fatalf("failed to get the learner members in cluster: %v", err)
+ numberOfLearners := 0
+ for _, m := range memberAddResp.Members {
+ if m.IsLearner {
+ numberOfLearners++
+ }
}
- if len(learners) != 1 {
- t.Errorf("Added 1 learner node to cluster, got %d", len(learners))
+ if numberOfLearners != 1 {
+ t.Fatalf("Added 1 learner node to cluster, got %d", numberOfLearners)
}
- _, err = capi.MemberPromote(context.Background(), resp.Member.ID)
+ memberPromoteResp, err := capi.MemberPromote(context.Background(), learnerID)
if err != nil {
- t.Fatalf("failed to promote member error: %v", err)
+ t.Fatalf("failed to promote member: %v", err)
}
- learners, err = clus.GetLearnerMembers()
- if err != nil {
- t.Fatalf("failed to get the number of learners in cluster: %v", err)
+ numberOfLearners = 0
+ for _, m := range memberPromoteResp.Members {
+ if m.IsLearner {
+ numberOfLearners++
}
- if len(learners) != 0 {
- t.Errorf("learner promoted, expect 0 learner, got %d", len(learners))
}
-
+ if numberOfLearners != 0 {
+ t.Errorf("learner promoted, expect 0 learner, got %d", numberOfLearners)
+ }
}
