mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-12 02:12:15 +01:00
adding tests for random pkg
This commit is contained in:
@@ -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.
|
||||
|
||||
28
internal/pkg/random/random_test.go
Normal file
28
internal/pkg/random/random_test.go
Normal 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())
|
||||
}
|
||||
Reference in New Issue
Block a user