Files
virtuallan/pkg/utils/hash_test.go
lucheng a6bfacb0c2 Fix client ip by get client ip base on username hash
Count username hash, get client ip base on it, it will make ip
fixed base on client login username.
2024-08-09 12:30:26 +08:00

56 lines
808 B
Go

package utils
import "testing"
func TestIdxFromString(t *testing.T) {
type args struct {
step int
str string
}
tests := []struct {
name string
args args
want int
}{
{
name: "step 100 user1",
want: 32,
args: args{
step: 100,
str: "shawn",
},
},
{
name: "step 100 user2",
want: 59,
args: args{
step: 100,
str: "guest",
},
},
{
name: "step 30 user1",
want: 2,
args: args{
step: 30,
str: "shawn",
},
},
{
name: "step 30 user2",
want: 9,
args: args{
step: 30,
str: "guest",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IdxFromString(tt.args.step, tt.args.str); got != tt.want {
t.Errorf("IdxFromString() = %v, want %v", got, tt.want)
}
})
}
}