From 9ab8d036973189faafee91fd66a152aa4f171718 Mon Sep 17 00:00:00 2001 From: Julien Neuhart Date: Mon, 8 Jul 2019 18:06:43 +0200 Subject: [PATCH] adding tests for random pkg --- build/tests/docker-entrypoint.sh | 4 +++- internal/pkg/random/random_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 internal/pkg/random/random_test.go diff --git a/build/tests/docker-entrypoint.sh b/build/tests/docker-entrypoint.sh index b4b0ea1d..476b166f 100755 --- a/build/tests/docker-entrypoint.sh +++ b/build/tests/docker-entrypoint.sh @@ -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. diff --git a/internal/pkg/random/random_test.go b/internal/pkg/random/random_test.go new file mode 100644 index 00000000..b7a37060 --- /dev/null +++ b/internal/pkg/random/random_test.go @@ -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()) +}