Files
mostlymatter/server/channels/app/import_utils_test.go
Claudio Costa 611b2a8e79 [MM-62408] Server Code Coverage with Fully Parallel Tests (#30078)
* TestPool

* Store infra

* Store tests updates

* Bump maximum concurrent postgres connections

* More infra

* channels/jobs

* channels/app

* channels/api4

* Protect i18n from concurrent access

* Replace some use of os.Setenv

* Remove debug

* Lint fixes

* Fix more linting

* Fix test

* Remove use of Setenv in drafts tests

* Fix flaky TestWebHubCloseConnOnDBFail

* Fix merge

* [MM-62408] Add CI job to generate test coverage (#30284)

* Add CI job to generate test coverage

* Remove use of Setenv in drafts tests

* Fix flaky TestWebHubCloseConnOnDBFail

* Fix more Setenv usage

* Fix more potential flakyness

* Remove parallelism from flaky test

* Remove conflicting env var

* Fix

* Disable parallelism

* Test atomic covermode

* Disable parallelism

* Enable parallelism

* Add upload coverage step

* Fix codecov.yml

* Add codecov.yml

* Remove redundant workspace field

* Add Parallel() util methods and refactor

* Fix formatting

* More formatting fixes

* Fix reporting
2025-05-30 13:58:26 +02:00

46 строки
1.3 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGeneratePassword(t *testing.T) {
mainHelper.Parallel(t)
t.Run("Should be the minimum length or 4, whichever is less", func(t *testing.T) {
password1, err := generatePassword(5)
require.NoError(t, err)
assert.Len(t, password1, 5)
password2, err := generatePassword(10)
require.NoError(t, err)
assert.Len(t, password2, 10)
password3, err := generatePassword(1)
require.NoError(t, err)
assert.Len(t, password3, 4)
})
t.Run("Should contain at least one of symbols, upper case, lower case and numbers", func(t *testing.T) {
password, err := generatePassword(4)
require.NoError(t, err)
require.Len(t, password, 4)
assert.Contains(t, []rune(passwordUpperCaseLetters), []rune(password)[0])
assert.Contains(t, []rune(passwordNumbers), []rune(password)[1])
assert.Contains(t, []rune(passwordLowerCaseLetters), []rune(password)[2])
assert.Contains(t, []rune(passwordSpecialChars), []rune(password)[3])
})
t.Run("Should not fail on concurrent calls", func(t *testing.T) {
for i := 0; i < 10; i++ {
go func() {
_, err := generatePassword(10)
require.NoError(t, err)
}()
}
})
}