48 lines
843 B
Go
48 lines
843 B
Go
package random_test
|
|
|
|
import (
|
|
"testing"
|
|
"url-shortener/internal/lib/random"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestNewRandomString(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
size int
|
|
}{
|
|
{
|
|
name: "size = 1",
|
|
size: 1,
|
|
},
|
|
{
|
|
name: "size = 6",
|
|
size: 6,
|
|
},
|
|
{
|
|
name: "size = 10",
|
|
size: 10,
|
|
},
|
|
{
|
|
name: "size = 20",
|
|
size: 20,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
str1 := random.NewRandomString(tt.size)
|
|
str2 := random.NewRandomString(tt.size)
|
|
|
|
assert.Len(t, str1, tt.size)
|
|
assert.Len(t, str2, tt.size)
|
|
|
|
// Check that two generated strings are different
|
|
// This is not an absolute guarantee that the function works correctly,
|
|
// but this is a good heuristic for a simple random generator.
|
|
assert.NotEqual(t, str1, str2)
|
|
})
|
|
}
|
|
}
|