Search⌘ K
AI Features

PassValidator: MultipleErrors Requirement

Explore how to manage multiple validation errors in a password validator using Go and test-driven development. Learn to write tests that handle multiple error cases, apply the Red-Green-Refactor approach to fix and improve your code, and use table-driven tests for cleaner, more maintainable test cases.

Before we implement the other features of the Validate function, let’s recap what we have managed until now:

  • We check if the password has at least eight characters.
  • We check if the password has at least two digits.

What if the password is shorter than eight characters and also has less than two digits? In this case, we should return both of the encountered validation errors, not just the first one ( ErrTooShort).

The MultipleErrors requirement

This feature should be able to manage a password like abc1 and return the error ...