Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move TCL test unit/tls to Go case #1012

Merged
merged 22 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 9 additions & 23 deletions .github/workflows/kvrocks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ jobs:
if: ${{ startsWith(matrix.os, 'ubuntu') }}
run: |
sudo apt update
sudo apt install -y tcl8.6 ninja-build tcl-tls
sudo apt install -y ninja-build
echo "NPROC=$(nproc)" >> $GITHUB_ENV

- name: Install redis
Expand Down Expand Up @@ -213,36 +213,22 @@ jobs:
run: |
export ${{ matrix.runtime_env_vars }}
export PATH=$PATH:$HOME/local/bin/
./x.py test go build
SANITIZER_OUTPUT=$(grep "Sanitizer:" tests/gocase/workspace -r || true)
if [[ $SANITIZER_OUTPUT ]]; then
echo "$SANITIZER_OUTPUT"
echo "\ndetail reports:\n"
cat $(find tests/gocase/workspace -iname stderr)
echo "sanitizer error was reported, exiting..."
exit 1
fi

- name: Run Redis Tcl Test
run: |
export ${{ matrix.runtime_env_vars }}
GOCASE_RUN_ARGS=""
if [[ -n "${{ matrix.with_openssl }}" ]] && [[ "${{ matrix.os }}" == ubuntu* ]]; then
git clone https://github.com/jsha/minica
cd minica && go build && cd ..
./minica/minica --domains localhost
mkdir -p tests/tcl/tests/tls
cp localhost/cert.pem tests/tcl/tests/tls/server.crt
cp localhost/key.pem tests/tcl/tests/tls/server.key
cp localhost/cert.pem tests/tcl/tests/tls/client.crt
cp localhost/key.pem tests/tcl/tests/tls/client.key
cp minica.pem tests/tcl/tests/tls/ca.crt
./x.py test tcl build --tls --single unit/tls --dont-clean
cp localhost/cert.pem tests/gocase/tls/cert/server.crt
cp localhost/key.pem tests/gocase/tls/cert/server.key
cp minica.pem tests/gocase/tls/cert/ca.crt
GOCASE_RUN_ARGS="-tlsEnable"
fi
SANITIZER_OUTPUT=$(grep "Sanitizer:" tests/tcl/tests/tmp -r || true)
./x.py test go build $GOCASE_RUN_ARGS
SANITIZER_OUTPUT=$(grep "Sanitizer:" tests/gocase/workspace -r || true)
if [[ $SANITIZER_OUTPUT ]]; then
echo "$SANITIZER_OUTPUT"
echo "\ndetail reports:\n"
cat $(find tests/tcl/tests/tmp -iname stderr)
cat $(find tests/gocase/workspace -iname stderr)
echo "sanitizer error was reported, exiting..."
exit 1
fi
Expand Down
4 changes: 2 additions & 2 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ We only used the source code in `lib` directory which is under BSD 2-Clause:
are intended to be used "as is", as part of their intended scenarios,
with no intention to support 3rd party integration use cases.

For tcl tests(*.tcl), src/geohash.*, src/rand.*, src/sha1.*,
src/scripting.* and some functions in src/util.cc are modified from Redis.
For src/types/geohash.*, src/common/rand.*, src/common/sha1.*, src/storage/scripting.* and
some functions in src/common/util.cc are modified from Redis.

We have added the Redis license notice in each file header, can also see bundled license file
https://github.com/apache/incubator-kvrocks/blob/unstable/licenses/LICENSE.redis for details.
Expand Down
8 changes: 8 additions & 0 deletions tests/gocase/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.19

require (
github.com/go-redis/redis/v9 v9.0.0-beta.2
github.com/shirou/gopsutil/v3 v3.22.9
github.com/stretchr/testify v1.8.0
golang.org/x/exp v0.0.0-20220929160808-de9c53c655b9
modernc.org/mathutil v1.5.0
Expand All @@ -13,7 +14,14 @@ require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
24 changes: 23 additions & 1 deletion tests/gocase/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,48 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-redis/redis/v9 v9.0.0-beta.2 h1:ZSr84TsnQyKMAg8gnV+oawuQezeJR11/09THcWCQzr4=
github.com/go-redis/redis/v9 v9.0.0-beta.2/go.mod h1:Bldcd/M/bm9HbnNPi/LUtYBSD8ttcZYBMupwMXhdU0o=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/gomega v1.20.0 h1:8W0cWlwFkflGPLltQvLRB7ZVD5HuP6ng320w2IS245Q=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6OkFY5QxjkYwrChwuRruF69c169dPK26NUlk=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/shirou/gopsutil/v3 v3.22.9 h1:yibtJhIVEMcdw+tCTbOPiF1VcsuDeTE4utJ8Dm4c5eA=
github.com/shirou/gopsutil/v3 v3.22.9/go.mod h1:bBYl1kjgEJpWpxeHmLI+dVHWtyAwfcmSBLDsp2TNT8A=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw=
github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk=
github.com/tklauser/numcpus v0.4.0 h1:E53Dm1HjH1/R2/aoCtXtPgzmElmn51aOkhCFSuZq//o=
github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ=
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
golang.org/x/exp v0.0.0-20220929160808-de9c53c655b9 h1:lNtcVz/3bOstm7Vebox+5m3nLh/BYWnhmc3AhXOW6oI=
golang.org/x/exp v0.0.0-20220929160808-de9c53c655b9/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
Expand Down
7 changes: 2 additions & 5 deletions tests/gocase/integration/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"bufio"
"bytes"
"context"
"flag"
"fmt"
"io"
"math"
Expand All @@ -39,16 +38,14 @@ import (

const defaultByteBufLen = math.MaxUint16

var cliPath = flag.String("cliPath", "redis-cli", "path to redis-cli")

type interactiveCli struct {
c *exec.Cmd
r *bufio.Reader
w *bufio.Writer
}

func createInteractiveCli(t *testing.T, srv *util.KvrocksServer) *interactiveCli {
c := exec.Command(*cliPath)
c := exec.Command(util.CLIPath())
c.Args = append(c.Args, "-h", srv.Host(), "-p", fmt.Sprintf("%d", srv.Port()))
w, err := c.StdinPipe()
require.NoError(t, err)
Expand Down Expand Up @@ -120,7 +117,7 @@ func (res *result) Failed() {
}

func runCli(t *testing.T, srv *util.KvrocksServer, in io.Reader, args ...string) *result {
c := exec.Command(*cliPath)
c := exec.Command(util.CLIPath())
c.Stdin = in
c.Args = append(c.Args, "-h", srv.Host(), "-p", fmt.Sprintf("%d", srv.Port()))
c.Args = append(c.Args, args...)
Expand Down
1 change: 1 addition & 0 deletions tests/gocase/tls/cert/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
138 changes: 138 additions & 0 deletions tests/gocase/tls/tls_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package tls

import (
"context"
"crypto/tls"
"testing"

"github.com/apache/incubator-kvrocks/tests/gocase/util"
"github.com/go-redis/redis/v9"
"github.com/stretchr/testify/require"
)

func TestTLS(t *testing.T) {
if !util.TLSEnable() {
t.Skip("TLS tests run only if tls enabled.")
}

ctx := context.Background()

srv := util.StartTLSServer(t, map[string]string{})
defer srv.Close()

defaultTLSConfig, err := util.DefaultTLSConfig()
require.NoError(t, err)

rdb := srv.NewClientWithOption(&redis.Options{TLSConfig: defaultTLSConfig, Addr: srv.TLSAddr()})
defer func() { require.NoError(t, rdb.Close()) }()

doWithTLSClient := func(tlsConfig *tls.Config, f func(c *redis.Client)) {
c := srv.NewClientWithOption(&redis.Options{TLSConfig: tlsConfig, Addr: srv.TLSAddr()})
defer func() { require.NoError(t, c.Close()) }()
f(c)
}

t.Run("TLS: Not accepting non-TLS connections on a TLS port", func(t *testing.T) {
c := srv.NewClientWithOption(&redis.Options{TLSConfig: defaultTLSConfig})
tisonkun marked this conversation as resolved.
Show resolved Hide resolved
defer func() { require.NoError(t, c.Close()) }()
require.Error(t, c.Ping(ctx).Err())
})

t.Run("TLS: Verify tls-auth-clients behaves as expected", func(t *testing.T) {
tlsConfig := &tls.Config{InsecureSkipVerify: true}
doWithTLSClient(tlsConfig, func(c *redis.Client) { require.Error(t, c.Ping(ctx).Err()) })

require.NoError(t, rdb.ConfigSet(ctx, "tls-auth-clients", "no").Err())
doWithTLSClient(tlsConfig, func(c *redis.Client) { require.Equal(t, "PONG", c.Ping(ctx).Val()) })

require.NoError(t, rdb.ConfigSet(ctx, "tls-auth-clients", "optional").Err())
doWithTLSClient(tlsConfig, func(c *redis.Client) { require.Equal(t, "PONG", c.Ping(ctx).Val()) })

require.NoError(t, rdb.ConfigSet(ctx, "tls-auth-clients", "yes").Err())
doWithTLSClient(tlsConfig, func(c *redis.Client) { require.Error(t, c.Ping(ctx).Err()) })
})

t.Run("TLS: Verify tls-protocols behaves as expected", func(t *testing.T) {
require.NoError(t, rdb.ConfigSet(ctx, "tls-protocols", "TLSv1.2").Err())

tlsConfig, err := util.DefaultTLSConfig()
require.NoError(t, err)

tlsConfig.MaxVersion = tls.VersionTLS11
doWithTLSClient(tlsConfig, func(c *redis.Client) { require.Error(t, c.Ping(ctx).Err()) })

tlsConfig.MaxVersion = tls.VersionTLS12
doWithTLSClient(tlsConfig, func(c *redis.Client) { require.Equal(t, "PONG", c.Ping(ctx).Val()) })
})

t.Run("TLS: Verify tls-ciphers behaves as expected", func(t *testing.T) {
require.NoError(t, rdb.ConfigSet(ctx, "tls-protocols", "TLSv1.2").Err())
require.NoError(t, rdb.ConfigSet(ctx, "tls-ciphers", "DEFAULT:-AES128-SHA256").Err())

tlsConfig, err := util.DefaultTLSConfig()
require.NoError(t, err)

tlsConfig.CipherSuites = []uint16{tls.TLS_RSA_WITH_AES_128_CBC_SHA256}
doWithTLSClient(tlsConfig, func(c *redis.Client) { require.Error(t, c.Ping(ctx).Err()) })

tlsConfig.CipherSuites = []uint16{tls.TLS_RSA_WITH_AES_256_GCM_SHA384}
doWithTLSClient(tlsConfig, func(c *redis.Client) { require.Equal(t, "PONG", c.Ping(ctx).Val()) })

require.NoError(t, rdb.ConfigSet(ctx, "tls-ciphers", "DEFAULT").Err())
tlsConfig.CipherSuites = []uint16{tls.TLS_RSA_WITH_AES_128_CBC_SHA256}
doWithTLSClient(tlsConfig, func(c *redis.Client) { require.Equal(t, "PONG", c.Ping(ctx).Val()) })

require.NoError(t, rdb.ConfigSet(ctx, "tls-protocols", "").Err())
require.NoError(t, rdb.ConfigSet(ctx, "tls-ciphers", "DEFAULT").Err())
})

doWithTCPTLSClient := func(tlsConfig *tls.Config, f func(c *util.TCPClient)) {
c := srv.NewTCPTLSClient(tlsConfig)
defer func() { require.NoError(t, c.Close()) }()
f(c)
}

t.Run("TLS: Verify tls-prefer-server-ciphers behaves as expected", func(t *testing.T) {
require.NoError(t, rdb.ConfigSet(ctx, "tls-protocols", "TLSv1.2").Err())
require.NoError(t, rdb.ConfigSet(ctx, "tls-ciphers", "AES128-SHA256:AES256-GCM-SHA384").Err())

tlsConfig, err := util.DefaultTLSConfig()
require.NoError(t, err)
tlsConfig.CipherSuites = []uint16{tls.TLS_RSA_WITH_AES_256_GCM_SHA384, tls.TLS_RSA_WITH_AES_128_CBC_SHA256}

doWithTCPTLSClient(tlsConfig, func(c *util.TCPClient) {
require.NoError(t, c.WriteArgs("PING"))
c.MustRead(t, "+PONG")
require.Equal(t, c.TLSState().CipherSuite, tls.TLS_RSA_WITH_AES_256_GCM_SHA384)
})

require.NoError(t, rdb.ConfigSet(ctx, "tls-prefer-server-ciphers", "yes").Err())
doWithTCPTLSClient(tlsConfig, func(c *util.TCPClient) {
require.NoError(t, c.WriteArgs("PING"))
c.MustRead(t, "+PONG")
require.Equal(t, c.TLSState().CipherSuite, tls.TLS_RSA_WITH_AES_128_CBC_SHA256)
})

require.NoError(t, rdb.ConfigSet(ctx, "tls-protocols", "").Err())
require.NoError(t, rdb.ConfigSet(ctx, "tls-ciphers", "DEFAULT").Err())
})
}
25 changes: 13 additions & 12 deletions tests/gocase/unit/type/bitmap/bitmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"bytes"
"context"
"fmt"
"math"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -51,7 +52,7 @@ func Set2SetBit(t *testing.T, rdb *redis.Client, ctx context.Context, key string
}
}
func GetBitmap(t *testing.T, rdb *redis.Client, ctx context.Context, keys ...string) []string {
buf := []string{}
buf := make([]string, 0, len(keys))
for _, key := range keys {
cmd := rdb.Get(ctx, key)
require.NoError(t, cmd.Err())
Expand All @@ -61,7 +62,7 @@ func GetBitmap(t *testing.T, rdb *redis.Client, ctx context.Context, keys ...str
}
func SimulateBitOp(op BITOP, values ...[]byte) string {
maxlen := 0
binaryArray := []string{}
binaryArray := make([]string, 0, len(values))
for _, value := range values {
if maxlen < len(value)*8 {
maxlen = len(value) * 8
Expand All @@ -75,7 +76,7 @@ func SimulateBitOp(op BITOP, values ...[]byte) string {
tmp := buf.String() + strings.Repeat("0", maxlen-len(buf.String()))
binaryArray = append(binaryArray, tmp)
}
var binarayResult []byte
var binaryResult []byte
for i := 0; i < maxlen; i++ {
x := binaryArray[0][i]
if op == NOT {
Expand All @@ -102,14 +103,14 @@ func SimulateBitOp(op BITOP, values ...[]byte) string {
x = '1'
}
}
binarayResult = append(binarayResult, x)
binaryResult = append(binaryResult, x)
}

result := []byte{}
for i := 0; i < len(binarayResult); i += 8 {
var result []byte
for i := 0; i < len(binaryResult); i += 8 {
sum := 0
for j := 0; j < 8; j++ {
sum = sum*2 + int(binarayResult[i+j]-'0')
sum = sum*2 + int(binaryResult[i+j]-'0')
}
result = append(result, byte(sum))
}
Expand Down Expand Up @@ -138,11 +139,11 @@ func TestBitmap(t *testing.T) {

t.Run("SETBIT/GETBIT/BITCOUNT/BITPOS boundary check (type bitmap)", func(t *testing.T) {
require.NoError(t, rdb.Del(ctx, "b0").Err())
maxOffset := 4*1024*1024*1024 - 1
util.ErrorRegexp(t, rdb.SetBit(ctx, "b0", int64(maxOffset)+1, 1).Err(), ".*out of range.*")
require.NoError(t, rdb.SetBit(ctx, "b0", int64(maxOffset), 1).Err())
require.EqualValues(t, 1, rdb.GetBit(ctx, "b0", int64(maxOffset)).Val())
require.EqualValues(t, 1, rdb.BitCount(ctx, "b0", &redis.BitCount{Start: 0, End: int64(maxOffset) / 8}).Val())
var maxOffset int64 = math.MaxUint32
util.ErrorRegexp(t, rdb.SetBit(ctx, "b0", maxOffset+1, 1).Err(), ".*out of range.*")
require.NoError(t, rdb.SetBit(ctx, "b0", maxOffset, 1).Err())
require.EqualValues(t, 1, rdb.GetBit(ctx, "b0", maxOffset).Val())
require.EqualValues(t, 1, rdb.BitCount(ctx, "b0", &redis.BitCount{Start: 0, End: maxOffset / 8}).Val())
require.EqualValues(t, maxOffset, rdb.BitPos(ctx, "b0", 1).Val())
})

Expand Down
2 changes: 1 addition & 1 deletion tests/gocase/unit/type/strings/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func TestString(t *testing.T) {

require.NoError(t, rdb.Del(ctx, "mykey").Err())
require.NoError(t, rdb.Set(ctx, "mykey", "", 0).Err())
var maxOffset int64 = math.MaxInt32
var maxOffset int64 = math.MaxUint32
require.NoError(t, rdb.SetBit(ctx, "mykey", maxOffset, 1).Err())
require.EqualValues(t, 1, rdb.GetBit(ctx, "mykey", maxOffset).Val())
require.EqualValues(t, 1, rdb.BitCount(ctx, "mykey", &redis.BitCount{Start: 0, End: maxOffset / 8}).Val())
Expand Down
Loading