huge refactoring

This commit is contained in:
Julien Neuhart
2019-07-23 13:57:18 +02:00
parent f6b357691c
commit 7bfbda4490
105 changed files with 4051 additions and 2667 deletions

View File

@@ -0,0 +1,3 @@
// Package xrand helps generating
// random strings.
package xrand

View 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)
}

View 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())
}