Search⌘ K

PassValidator Kata

Explore how to apply the test-driven development approach to build a password validation function in Go. Learn to write tests covering multiple validation rules, handle errors effectively, and refactor code for clarity and maintainability using practical examples and best practices.

Now, we’re going to implement a less academic exercise to reinforce our knowledge of TDD. The exercise is the Password Validation kata. Theoretically, this function could be invoked to validate the user’s password in a registration form. It will accept a password as the input, and it returns a bool value indicating whether the validation succeeded along with the reasons why the validation failed. A password is valid only if it meets all the following constraints:

  • It must be at least eight characters long.
  • It must contain at least two numbers.
  • It must contain at least one capital letter.
  • It must contain at least one special character.

In addition, the function must be able to manage multiple validation errors at the same time.

Password length

...