(t *testing.T)
| 7 | ) |
| 8 | |
| 9 | func Test_isPasswordValid(t *testing.T) { |
| 10 | testPasswords := map[string]struct { |
| 11 | password string |
| 12 | confirmation string |
| 13 | expectedValidity bool |
| 14 | expectedMessage string |
| 15 | }{ |
| 16 | "empty": { |
| 17 | password: "", |
| 18 | confirmation: "", |
| 19 | expectedValidity: true, |
| 20 | expectedMessage: "", |
| 21 | }, |
| 22 | "confirmation doesn't match": { |
| 23 | password: "abc", |
| 24 | confirmation: "aBc", |
| 25 | expectedValidity: false, |
| 26 | expectedMessage: "Password confirmation doesn't match", |
| 27 | }, |
| 28 | "too short": { |
| 29 | password: "123456789a123456789b123", |
| 30 | confirmation: "123456789a123456789b123", |
| 31 | expectedValidity: false, |
| 32 | expectedMessage: "Password must contain between 24 and 64 characters", |
| 33 | }, |
| 34 | "too long": { |
| 35 | password: "123456789a123456789b123456789c123456789d123456789e123456789f12345", |
| 36 | confirmation: "123456789a123456789b123456789c123456789d123456789e123456789f12345", |
| 37 | expectedValidity: false, |
| 38 | expectedMessage: "Password must contain between 24 and 64 characters", |
| 39 | }, |
| 40 | "valid, short password": { |
| 41 | password: "123456789a123456789b1234", |
| 42 | confirmation: "123456789a123456789b1234", |
| 43 | expectedValidity: true, |
| 44 | expectedMessage: "", |
| 45 | }, |
| 46 | "valid, log password ": { |
| 47 | password: "123456789a123456789b123456789c123456789d123456789e123456789f1234", |
| 48 | confirmation: "123456789a123456789b123456789c123456789d123456789e123456789f1234", |
| 49 | expectedValidity: true, |
| 50 | expectedMessage: "", |
| 51 | }, |
| 52 | } |
| 53 | |
| 54 | for name, testCase := range testPasswords { |
| 55 | t.Run(name, func(t *testing.T) { |
| 56 | message, isValid := isPasswordValid(testCase.password, testCase.confirmation) |
| 57 | |
| 58 | assert.Equal(t, testCase.expectedValidity, isValid) |
| 59 | assert.Equal(t, testCase.expectedMessage, message) |
| 60 | }) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | func Test_isUsernameValid(t *testing.T) { |
| 65 | testPasswords := map[string]struct { |
nothing calls this directly
no test coverage detected