Files
hatchet/pkg/validator/validator_test.go
abelanger5 7c3ddfca32 feat: api server extensions (#614)
* feat: allow extending the api server

* chore: remove internal packages to pkg

* chore: update db_gen.go

* fix: expose auth

* fix: move logger to pkg

* fix: don't generate gitignore for prisma client

* fix: allow extensions to register their own api spec

* feat: expose pool on server config

* fix: nil pointer exception on empty opts

* fix: run.go file
2024-06-19 09:36:13 -04:00

80 lines
1.5 KiB
Go

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