Files
hatchet/pkg/random/random_test.go
abelanger5 ffbeafc204 revert: add back testing harness (#1659)
* re-add new testing harness

* add healthcheck port and pick random grpc port to listen on

* feat: parallel load tests and faster tests

* make parallelism = 5

* fix: lint

* add linter to pre

* fix: add back rampup fixes

* reduce matrix on PR, add matrix to pre-release step

* make load tests less likely to block

* make limit strategy group round robin

* uncomment lines
2025-05-01 15:22:30 -04:00

53 lines
1.1 KiB
Go

//go:build !e2e && !load && !rampup && !integration
package random
import (
"fmt"
"regexp"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGenerateRandomString(t *testing.T) {
type args struct {
n int
}
tests := []struct {
name string
args args
want func(string) bool
wantErr assert.ErrorAssertionFunc
}{{
name: "GenerateRandomString",
args: args{
n: 32,
},
want: func(s string) bool {
if match, err := regexp.MatchString(`^[0-9a-zA-Z]+$`, s); err != nil || !match {
return false
}
return len(s) == 32
},
wantErr: assert.NoError,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Generate(tt.args.n)
if !tt.wantErr(t, err, fmt.Sprintf("GenerateRandomString(%v)", tt.args.n)) {
return
}
assert.Equalf(t, true, tt.want(got), "GenerateRandomString(%v)", tt.args.n)
})
}
}
func TestGenerateWebhookSecret(t *testing.T) {
s, err := GenerateWebhookSecret()
if !assert.NoError(t, err) {
t.FailNow()
}
assert.Equalf(t, 32, len(s), "GenerateWebhookSecret length should be 32")
}