Skip to content

Commit

Permalink
feat(validation): add test for IsPwdComplex
Browse files Browse the repository at this point in the history
  • Loading branch information
ripls56 committed Aug 13, 2024
1 parent 2274f09 commit 24224d5
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions internal/pkg/validation/password_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
}

0 comments on commit 24224d5

Please sign in to comment.