adding tests for random pkg

This commit is contained in:
Julien Neuhart
2019-07-08 18:06:43 +02:00
parent 9c6f23d7cc
commit 9ab8d03697
2 changed files with 31 additions and 1 deletions

View File

@@ -9,7 +9,9 @@ go test github.com/thecodingmachine/gotenberg/internal/pkg/pm2 -run TestChromeSt
go test github.com/thecodingmachine/gotenberg/internal/pkg/pm2 -run TestUnoconvStart
# Running others tests.
go test -race -cover -covermode=atomic github.com/thecodingmachine/gotenberg/internal/pkg
go test -race -cover -covermode=atomic github.com/thecodingmachine/gotenberg/internal/pkg/random
go test -race -cover -covermode=atomic github.com/thecodingmachine/gotenberg/internal/pkg/standarderror
go test -race -cover -covermode=atomic github.com/thecodingmachine/gotenberg/internal/pkg/timeout
go test -race -cover -covermode=atomic github.com/thecodingmachine/gotenberg/internal/app/api
# Finally testing processes shutdown.

View File

@@ -0,0 +1,28 @@
package random
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 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())
}