Skip to content

Commit 5c2bcfe

Browse files
committed
quickfix: update tests
* random typo and better random key generation
1 parent 7f995da commit 5c2bcfe

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

postgres/postgres_test.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package postgres
22

33
import (
44
"context"
5-
"math/rand"
65
"os"
76
"strconv"
87
"testing"
@@ -25,7 +24,7 @@ func TestNoCreateUser(t *testing.T) {
2524
ctx := context.Background()
2625
conn := testStore.Conn()
2726

28-
username := "testuser" + strconv.Itoa(rand.Intn(1_000_000))
27+
username := "testuser" + strconv.Itoa(int(time.Now().UnixNano()))
2928
password := "testpassword"
3029

3130
_, err := conn.Exec(ctx, "CREATE USER "+username+" WITH PASSWORD '"+password+"'")
@@ -47,7 +46,7 @@ func TestNoCreateUser(t *testing.T) {
4746
require.NoError(t, err)
4847

4948
t.Run("should panic if limited user tries to create table", func(t *testing.T) {
50-
tableThatDoesNotExist := "public.table_does_not_exists_" + strconv.Itoa(rand.Intn(1_000_000))
49+
tableThatDoesNotExist := "public.table_does_not_exists_" + strconv.Itoa(int(time.Now().UnixNano()))
5150

5251
defer func() {
5352
r := recover()
@@ -77,19 +76,19 @@ func TestNoCreateUser(t *testing.T) {
7776
conn.Exec(ctx, "DROP USER "+username)
7877
}()
7978

80-
t.Run("shoud set", func(t *testing.T) {
79+
t.Run("should set", func(t *testing.T) {
8180
var (
82-
key = "john" + strconv.Itoa(rand.Intn(1_000_000))
83-
val = []byte("doe" + strconv.Itoa(rand.Intn(1_000_000)))
81+
key = "john" + strconv.Itoa(int(time.Now().UnixNano()))
82+
val = []byte("doe" + strconv.Itoa(int(time.Now().UnixNano())))
8483
)
8584

8685
err := limitedStore.Set(key, val, 0)
8786
require.NoError(t, err)
8887
})
8988
t.Run("should set override", func(t *testing.T) {
9089
var (
91-
key = "john" + strconv.Itoa(rand.Intn(1_000_000))
92-
val = []byte("doe" + strconv.Itoa(rand.Intn(1_000_000)))
90+
key = "john" + strconv.Itoa(int(time.Now().UnixNano()))
91+
val = []byte("doe" + strconv.Itoa(int(time.Now().UnixNano())))
9392
)
9493
err := limitedStore.Set(key, val, 0)
9594
require.NoError(t, err)
@@ -98,8 +97,8 @@ func TestNoCreateUser(t *testing.T) {
9897
})
9998
t.Run("should get", func(t *testing.T) {
10099
var (
101-
key = "john" + strconv.Itoa(rand.Intn(1_000_000))
102-
val = []byte("doe" + strconv.Itoa(rand.Intn(1_000_000)))
100+
key = "john" + strconv.Itoa(int(time.Now().UnixNano()))
101+
val = []byte("doe" + strconv.Itoa(int(time.Now().UnixNano())))
103102
)
104103
err := limitedStore.Set(key, val, 0)
105104
require.NoError(t, err)
@@ -109,17 +108,17 @@ func TestNoCreateUser(t *testing.T) {
109108
})
110109
t.Run("should set expiration", func(t *testing.T) {
111110
var (
112-
key = "john" + strconv.Itoa(rand.Intn(1_000_000))
113-
val = []byte("doe" + strconv.Itoa(rand.Intn(1_000_000)))
111+
key = "john" + strconv.Itoa(int(time.Now().UnixNano()))
112+
val = []byte("doe" + strconv.Itoa(int(time.Now().UnixNano())))
114113
exp = 100 * time.Millisecond
115114
)
116115
err := limitedStore.Set(key, val, exp)
117116
require.NoError(t, err)
118117
})
119118
t.Run("should get expired", func(t *testing.T) {
120119
var (
121-
key = "john" + strconv.Itoa(rand.Intn(1_000_000))
122-
val = []byte("doe" + strconv.Itoa(rand.Intn(1_000_000)))
120+
key = "john" + strconv.Itoa(int(time.Now().UnixNano()))
121+
val = []byte("doe" + strconv.Itoa(int(time.Now().UnixNano())))
123122
exp = 100 * time.Millisecond
124123
)
125124
err := limitedStore.Set(key, val, exp)
@@ -136,8 +135,8 @@ func TestNoCreateUser(t *testing.T) {
136135
})
137136
t.Run("should delete", func(t *testing.T) {
138137
var (
139-
key = "john" + strconv.Itoa(rand.Intn(1_000_000))
140-
val = []byte("doe" + strconv.Itoa(rand.Intn(1_000_000)))
138+
key = "john" + strconv.Itoa(int(time.Now().UnixNano()))
139+
val = []byte("doe" + strconv.Itoa(int(time.Now().UnixNano())))
141140
)
142141
err := limitedStore.Set(key, val, 0)
143142
require.NoError(t, err)

0 commit comments

Comments
 (0)