Fix flaky TestRequestTrialLicense test (#18259)

Этот коммит содержится в:
Claudio Costa
2021-08-25 14:56:41 +02:00
коммит произвёл GitHub
родитель eaa37b52ee
Коммит 4dc54004ec
2 изменённых файлов: 36 добавлений и 6 удалений

Просмотреть файл

@@ -6,17 +6,19 @@ package api4
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/mattermost/mattermost-server/v6/app"
"github.com/mattermost/mattermost-server/v6/einterfaces/mocks"
"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v6/utils"
mocks2 "github.com/mattermost/mattermost-server/v6/utils/mocks"
"github.com/mattermost/mattermost-server/v6/utils/testutils"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/v6/model"
)
func TestGetOldClientLicense(t *testing.T) {
@@ -219,8 +221,35 @@ func TestRequestTrialLicense(t *testing.T) {
})
t.Run("trial license user count less than current users", func(t *testing.T) {
t.Skip("MM-36695")
resp, err := th.SystemAdminClient.RequestTrialLicense(1)
nUsers := 1
license := model.NewTestLicense()
license.Features.Users = model.NewInt(nUsers)
licenseStr := license.ToJson()
testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
res.WriteHeader(http.StatusOK)
response := map[string]string{
"license": licenseStr,
}
err := json.NewEncoder(res).Encode(response)
require.NoError(t, err)
}))
defer testServer.Close()
mockLicenseValidator := mocks2.LicenseValidatorIface{}
defer testutils.ResetLicenseValidator()
mockLicenseValidator.On("ValidateLicense", mock.Anything).Return(true, licenseStr)
utils.LicenseValidator = &mockLicenseValidator
licenseManagerMock := &mocks.LicenseInterface{}
licenseManagerMock.On("CanStartTrial").Return(true, nil).Once()
th.App.Srv().LicenseManager = licenseManagerMock
defer func(requestTrialURL string) {
app.RequestTrialURL = requestTrialURL
}(app.RequestTrialURL)
app.RequestTrialURL = testServer.URL
resp, err := th.SystemAdminClient.RequestTrialLicense(nUsers)
CheckErrorID(t, err, "api.license.add_license.unique_users.app_error")
CheckBadRequestStatus(t, resp)
})