From 24224d5f9f38038c8cf8b3806a4a160f876a3100 Mon Sep 17 00:00:00 2001 From: ripls56 <84716344+ripls56@users.noreply.github.com> Date: Tue, 13 Aug 2024 17:14:35 +0300 Subject: [PATCH] feat(validation): add test for `IsPwdComplex` --- internal/pkg/validation/password_test.go | 72 ++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 internal/pkg/validation/password_test.go diff --git a/internal/pkg/validation/password_test.go b/internal/pkg/validation/password_test.go new file mode 100644 index 0000000..9746110 --- /dev/null +++ b/internal/pkg/validation/password_test.go @@ -0,0 +1,72 @@ +package validation + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestIsPwdComplex(t *testing.T) { + tests := []struct { + name string + password string + expect bool + }{ + { + name: "Empty password", + password: "", + expect: false, + }, + { + name: "Lowercase only, too short", + password: "abcde", + expect: false, + }, + { + name: "Lowercase only, sufficient length", + password: "abcdefghijabcdefghij", + expect: true, + }, + { + name: "Lowercase and digits, too short", + password: "abc123", + expect: false, + }, + { + name: "Lowercase and digits, sufficient length", + password: "abc123abc123", + expect: true, + }, + { + name: "Lowercase, uppercase, and digits, too short", + password: "Abc123", + expect: false, + }, + { + name: "Lowercase, uppercase, and digits, sufficient length", + password: "Abc123Abc123", + expect: true, + }, + { + name: "Lowercase, uppercase, digits, and special chars, sufficient length", + password: "Abc123!@#Abc123!@#", + expect: true, + }, + { + name: "Only special characters, too short", + password: "!@#$%^", + expect: false, + }, + { + name: "Only special characters, sufficient length", + password: "!@#$%^&*()_+!@#$%^&*()_+", + expect: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + actual := IsPwdComplex(tt.password) + assert.Equalf(t, tt.expect, actual, "IsPwdComplex() = %v, expect %v", actual, tt.expect) + }) + } +}