Files
hatchet/pkg/random/random_test.go
Luca Steeb 1490d88954 feat: webhook workers (#542)
Adds serverless support via the concept of webhook workers. Allows any webhook to be registered as a serverless endpoint for executing a step.
2024-06-25 17:06:43 -04:00

51 lines
1.0 KiB
Go

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