From f7da40b65a8efa7cf824b2688b225fd528c862d4 Mon Sep 17 00:00:00 2001 From: Daniel <24758309+leedaniil@users.noreply.github.com> Date: Wed, 24 Nov 2021 13:20:20 +0300 Subject: [PATCH] Fix validator (#7) --- pkg/validation/folders.go | 24 ++++++++++++++++++++++++ src/validator/validators.go | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/pkg/validation/folders.go b/pkg/validation/folders.go index 37e8a48..6bc177f 100644 --- a/pkg/validation/folders.go +++ b/pkg/validation/folders.go @@ -31,6 +31,30 @@ OutLoop: return nil } +func ValidateFilesNotInList(files []fs.DirEntry, fileList []string) error { + compErr := NewErrComposite() + + for _, dir := range files { + var found bool + for _, f := range fileList { + if dir.Name() == f { + found = true + break + } + } + + if !found { + compErr.Append(fmt.Errorf("%w: %s", ErrMissingFile, dir.Name())) + } + } + + if compErr.Len() > 0 { + return compErr + } + + return nil +} + func ValidateAllowedFiles(files []fs.DirEntry, allowedFiles []string) error { compErr := NewErrComposite() for _, f := range files { diff --git a/src/validator/validators.go b/src/validator/validators.go index 0b88773..ec651c9 100644 --- a/src/validator/validators.go +++ b/src/validator/validators.go @@ -274,7 +274,7 @@ func (s *Service) ValidateValidatorsListFile(file *file.AssetFile) error { return err } - err = validation.ValidateHasFiles(dirAssetFolderFiles, listIDs) + err = validation.ValidateFilesNotInList(dirAssetFolderFiles, listIDs) if err != nil { return err }