Skip to content

Commit

Permalink
added validate.go for error handling; testing WithPath and other func…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
deemount committed Mar 21, 2024
1 parent 5811a30 commit 2fa1a1f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 7 additions & 3 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ var (
DefaultPathJSON = "files/json" // DefaultPathJSON is the default path to the json files

// Errors
ErrPathNotFound = errors.New("path not found") // ErrPathNotFound is the error for the path not found
ErrPathNotFound = errors.New("path not found") // ErrPathNotFound is the error for the path not found
ErrEmptyFilePathBPMN = errors.New("empty file path for bpmn") // ErrEmptyFilePathBPMN is the error for the empty file path for bpmn
)

type (
Expand Down Expand Up @@ -57,7 +58,7 @@ type (
// and returns the builder repository.
// The method sets the default values and applies the options
// to the builder.
func New(opts ...Option) BuilderRepository {
func New(opts ...Option) (BuilderRepository, error) {
// Set the default values
bldr := &Builder{
Counter: DefaultCounter,
Expand All @@ -72,7 +73,10 @@ func New(opts ...Option) BuilderRepository {
for _, opt := range opts {
opt(bldr)
}
return bldr
if err := bldr.validate(); err != nil {
return nil, err
}
return bldr, nil
}

// SetDefinitions ...
Expand Down
10 changes: 10 additions & 0 deletions validate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package gobpmn_builder

// validate validates the builder fields
// and returns an error if the validation fails.
func (bldr *Builder) validate() error {
if bldr.FilePathBPMN == "" {
return ErrEmptyFilePathBPMN
}
return nil
}

0 comments on commit 2fa1a1f

Please sign in to comment.