Skip to content

Commit

Permalink
Add protovalidate validation test
Browse files Browse the repository at this point in the history
  • Loading branch information
sevein committed May 11, 2024
1 parent 42d5e3e commit 125e86e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions hack/ccp/internal/api/admin/validation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package admin_test

import (
"testing"

"github.com/bufbuild/protovalidate-go"
"gotest.tools/v3/assert"

adminv1 "github.com/artefactual/archivematica/hack/ccp/internal/api/gen/archivematica/ccp/admin/v1beta1"
)

func TestValidation(t *testing.T) {
t.Parallel()

v, err := protovalidate.New()
assert.NilError(t, err)

req := &adminv1.CreatePackageRequest{
Name: "asdf",
Path: []string{"/tmp"},
}
err = v.Validate(req)
assert.NilError(t, err)

req = &adminv1.CreatePackageRequest{}
err = v.Validate(req)
assert.Error(t, err, `validation error:
- name: value length must be at least 1 characters [string.min_len]
- path: value must contain at least 1 item(s) [repeated.min_items]`)
}

0 comments on commit 125e86e

Please sign in to comment.