Skip to content

Commit

Permalink
Sort members by rs member id
Browse files Browse the repository at this point in the history
  • Loading branch information
mircea-cosbuc committed Aug 21, 2024
1 parent 00a9472 commit d0b365d
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions test/e2e/mongodbtests/mongodbtests.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"sort"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -429,16 +430,13 @@ func AutomationConfigHasVoteTagPriorityConfigured(ctx context.Context, mdb *mdbv

return func(t *testing.T) {
currentAc := getAutomationConfig(ctx, t, mdb)
rsMemebers := currentAc.ReplicaSets

for _, m := range rsMemebers[0].Members {
var priorityPtr *string
var priority string
if m.Priority != nil {
priority = fmt.Sprintf("%f", *m.Priority)
priorityPtr = &priority
}
acMemberOptions = append(acMemberOptions, automationconfig.MemberOptions{Votes: m.Votes, Priority: priorityPtr, Tags: m.Tags})
rsMembers := currentAc.ReplicaSets
sort.Slice(rsMembers[0].Members, func(i, j int) bool {
return rsMembers[0].Members[i].Id < rsMembers[0].Members[j].Id
})

for _, m := range rsMembers[0].Members {
acMemberOptions = append(acMemberOptions, automationconfig.MemberOptions{Votes: m.Votes, Priority: floatPtrTostringPtr(m.Priority), Tags: m.Tags})
}
assert.ElementsMatch(t, memberOptions, acMemberOptions)
}
Expand Down Expand Up @@ -825,3 +823,11 @@ func AddUserToMongoDBCommunity(ctx context.Context, mdb *mdbv1.MongoDBCommunity,
}
}
}

func floatPtrTostringPtr(floatPtr *float32) *string {
if floatPtr != nil {
stringValue := fmt.Sprintf("%.1f", *floatPtr)
return &stringValue
}
return nil
}

0 comments on commit d0b365d

Please sign in to comment.