mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-16 12:22:17 +01:00
huge refactoring
This commit is contained in:
3
internal/pkg/xrand/doc.go
Normal file
3
internal/pkg/xrand/doc.go
Normal file
@@ -0,0 +1,3 @@
|
||||
// Package xrand helps generating
|
||||
// random strings.
|
||||
package xrand
|
||||
10
internal/pkg/xrand/xrand.go
Normal file
10
internal/pkg/xrand/xrand.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package xrand
|
||||
|
||||
import (
|
||||
"github.com/labstack/gommon/random"
|
||||
)
|
||||
|
||||
// Get returns a random string.
|
||||
func Get() string {
|
||||
return random.String(32)
|
||||
}
|
||||
28
internal/pkg/xrand/xrand_test.go
Normal file
28
internal/pkg/xrand/xrand_test.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package xrand
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
var rands []string
|
||||
// use case: for 1 000 concurrent
|
||||
// requests (which is a big Gotenberg instance),
|
||||
// none should have the same identifier.
|
||||
for i := 0; i < 1000; i++ {
|
||||
rands = append(rands, Get())
|
||||
}
|
||||
unique := func() bool {
|
||||
for i, rand := range rands {
|
||||
for j, current := range rands {
|
||||
if i != j && rand == current {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
assert.Equal(t, true, unique())
|
||||
}
|
||||
Reference in New Issue
Block a user