From 125e86e605c27a5543b9561cba68d8a72958dcb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Garc=C3=ADa=20Crespo?= Date: Sat, 11 May 2024 08:47:51 +0000 Subject: [PATCH] Add protovalidate validation test --- .../ccp/internal/api/admin/validation_test.go | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 hack/ccp/internal/api/admin/validation_test.go diff --git a/hack/ccp/internal/api/admin/validation_test.go b/hack/ccp/internal/api/admin/validation_test.go new file mode 100644 index 000000000..75ac0d9a1 --- /dev/null +++ b/hack/ccp/internal/api/admin/validation_test.go @@ -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]`) +}