Skip to content

Commit

Permalink
test(integration): remove sortSlice function, introduce testifyAssert…
Browse files Browse the repository at this point in the history
….ElementMatch
  • Loading branch information
superiorsd10 committed Nov 18, 2024
1 parent 1076c19 commit a42d0e1
Showing 1 changed file with 3 additions and 22 deletions.
25 changes: 3 additions & 22 deletions integration_tests/commands/resp/smemberswatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"context"
"fmt"
"net"
"sort"
"testing"
"time"

"github.com/dicedb/dice/internal/clientio"
dicedb "github.com/dicedb/dicedb-go"
"gotest.tools/v3/assert"
testifyAssert "github.com/stretchr/testify/assert"
)

type smembersWatchTestCase struct {
Expand Down Expand Up @@ -57,25 +57,6 @@ func TestSMEMBERSWATCH(t *testing.T) {
})
}

func sortSlice(v any) any {
switch v := v.(type) {
case []interface{}:
sorted := make([]interface{}, len(v))
copy(sorted, v)
sort.Slice(sorted, func(i, j int) bool {
return sorted[i].(string) < sorted[j].(string)
})
return sorted
case []string:
sorted := make([]string, len(v))
copy(sorted, v)
sort.Strings(sorted)
return sorted
default:
return v
}
}

func setUpSmembersRespParsers(t *testing.T, subscribers []net.Conn) []*clientio.RESPParser {
respParsers := make([]*clientio.RESPParser, len(subscribers))
for i, subscriber := range subscribers {
Expand Down Expand Up @@ -113,7 +94,7 @@ func verifySmembersWatchResults(t *testing.T, respParsers []*clientio.RESPParser
assert.Equal(t, 3, len(castedValue))
assert.Equal(t, smembersCommand, castedValue[0])
assert.Equal(t, smembersWatchFingerPrint, castedValue[1])
assert.DeepEqual(t, sortSlice(expected), sortSlice(castedValue[2]))
testifyAssert.ElementsMatch(t, expected, castedValue[2])
}
}

Expand Down Expand Up @@ -189,7 +170,7 @@ func verifySmembersWatchResultsSDK(t *testing.T, channels []<-chan *dicedb.Watch
receivedStrings[i] = str
}

assert.DeepEqual(t, sortSlice(expected), sortSlice(receivedStrings))
testifyAssert.ElementsMatch(t, expected, receivedStrings)
case <-time.After(defaultTimeout):
t.Fatal("timeout waiting for watch result")
}
Expand Down

0 comments on commit a42d0e1

Please sign in to comment.