Files
hatchet/pkg/validator/validator_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

82 lines
1.6 KiB
Go

//go:build !e2e && !load && !rampup && !integration
package validator
import (
"testing"
"github.com/stretchr/testify/assert"
)
type nameResource struct {
DisplayName string `validate:"hatchetName"`
}
func TestValidatorInvalidName(t *testing.T) {
v := newValidator()
err := v.Struct(&nameResource{
DisplayName: "&&!!",
})
assert.ErrorContains(t, err, "validation for 'DisplayName' failed on the 'hatchetName' tag", "should throw error on invalid name")
}
func TestValidatorValidName(t *testing.T) {
v := newValidator()
err := v.Struct(&nameResource{
DisplayName: "test-name",
})
assert.NoError(t, err, "no error")
}
type cronResource struct {
Cron string `validate:"cron"`
}
func TestValidatorValidCron(t *testing.T) {
v := newValidator()
err := v.Struct(&cronResource{
Cron: "*/5 * * * *",
})
assert.NoError(t, err, "no error")
}
func TestValidatorInvalidCron(t *testing.T) {
v := newValidator()
err := v.Struct(&cronResource{
Cron: "*/5 * * *",
})
assert.ErrorContains(t, err, "validation for 'Cron' failed on the 'cron' tag", "should throw error on invalid cron")
}
func TestValidatorValidDuration(t *testing.T) {
v := newValidator()
err := v.Struct(&struct {
Duration string `validate:"duration"`
}{
Duration: "5s",
})
assert.NoError(t, err, "no error")
}
func TestValidatorInvalidDuration(t *testing.T) {
v := newValidator()
err := v.Struct(&struct {
Duration string `validate:"duration"`
}{
Duration: "5",
})
assert.ErrorContains(t, err, "validation for 'Duration' failed on the 'duration' tag", "should throw error on invalid duration")
}