Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: validator tests #28

Merged
merged 1 commit into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions internal/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ var NameRegex = regexp.MustCompile("^[a-zA-Z0-9\\.\\-_]+$")

var CronRegex = regexp.MustCompile(`(@(annually|yearly|monthly|weekly|daily|hourly|reboot))|(@every (\d+(ns|us|µs|ms|s|m|h))+)|((((\d+,)+\d+|(\d+(\/|-)\d+)|\d+|\*) ?){5,7})`)

// New creates a new instance of validator and sets the tag name
// to "form", instead of "validate"
func newValidator() *validator.Validate {
validate := validator.New()

Expand Down
8 changes: 3 additions & 5 deletions internal/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ import (
)

type nameResource struct {
DisplayName string `form:"hatchet-name"`
DisplayName string `validate:"hatchetName"`
}

func TestValidatorInvalidName(t *testing.T) {
t.Skipf("TODO: @abelanger5 fix this test")
v := newValidator()

err := v.Struct(&nameResource{
DisplayName: "&&!!",
})

assert.ErrorContains(t, err, "validation for 'DisplayName' failed on the 'hatchet-name' tag", "should throw error on invalid name")
assert.ErrorContains(t, err, "validation for 'DisplayName' failed on the 'hatchetName' tag", "should throw error on invalid name")
}

func TestValidatorValidName(t *testing.T) {
Expand All @@ -32,7 +31,7 @@ func TestValidatorValidName(t *testing.T) {
}

type cronResource struct {
Cron string `form:"cron"`
Cron string `validate:"cron"`
}

func TestValidatorValidCron(t *testing.T) {
Expand All @@ -46,7 +45,6 @@ func TestValidatorValidCron(t *testing.T) {
}

func TestValidatorInvalidCron(t *testing.T) {
t.Skipf("TODO: @abelanger5 fix this test")
v := newValidator()

err := v.Struct(&cronResource{
Expand Down
Loading